VSTO Debug版很好,安装版本没有读取app.config

Iga*_*hne 6 vsto visual-studio-2010 excel-addins

我有一个VSTO Excel 2007加载项,应该从app.config文件读取连接字符串,然后让用户决定连接到哪个数据库.这在调试时工作正常,但是当我运行已部署的版本(使用Windows Installer完成)时,根本不读取连接字符串.我已将所有项目的主要输出添加到安装项目中.app.config文件位于ExcelAddIn项目中,但不在Excel标题下.管理连接字符串的类在另一个项目中.

这是我的app.config文件:

    <?xml version="1.0"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
  </configSections>
  <connectionStrings>
    <clear/>
    <add name="MyEntities" connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/SymModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=myServer;initial catalog=myDB;persist security info=True;user id=myUser;password=myPassword;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0"/>
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
Run Code Online (Sandbox Code Playgroud)

我使用以下内容来获取连接字符串:

System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        ConnectionStringsSection csSection = config.ConnectionStrings;
Run Code Online (Sandbox Code Playgroud)

我试图将ExcelAddin.dll.config文件添加到安装文件夹和.proj文件所在的安装项目文件夹中.我已将app.config文件的'Copy to Output Directory'属性设置为'Copy always',将Build Action属性设置为'Content'.

我的app.config文件有什么问题,或者为什么在我运行安装程序后它没有被拾取(连接字符串没有加载到csSection中)?

小智 6

加入file:///[TARGETDIR]ExcelAddIn.vsto|vstolocal(例如:file:///[TARGETDIR]ExcelAddIn.vsto|vstolocal)在根据"安装程序"注册表项.