visual-studio-2010 - VSTO 调试版本正常,安装版本不读取 app.config

标签 visual-studio-2010 vsto excel-addins

我有一个 VSTO Excel 2007 加载项,它应该从 app.config 文件中读取连接字符串,然后让用户决定要连接到哪个数据库。这在我调试时工作正常,但是当我运行部署版本(使用 Windows 安装程序完成)时,根本不会读取连接字符串。我已将所有项目的主要输出添加到设置项目中。
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>

我使用以下方法获取连接字符串:
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        ConnectionStringsSection csSection = config.ConnectionStrings;

我试图将 ExcelAddin.dll.config 文件添加到安装项目的文件夹中,其中 Release 文件夹和 .proj 文件所在。我已将 app.config 文件的“复制到输出目录”属性设置为“始终复制”,并将构建操作属性设置为“内容”。

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

最佳答案

添加 file:///[TARGETDIR]ExcelAddIn.vsto|vstolocal (例如: file:///[TARGETDIR]ExcelAddIn.vsto|vstolocal )在“安装程序”下的注册表项中。

关于visual-studio-2010 - VSTO 调试版本正常,安装版本不读取 app.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18586875/

相关文章:

c# - Visual Studio 2010 中 Parallel.Invoke 中无法捕获的异常

.net - ClickOnce 应用程序的远程调试类库

c - 如何在 Visual Studio 2010 中找到地址对应的段

c# - VSTO 字 2016 : Squiggly underline without affecting undo

visual-studio-2010 - F# 错误 FS0193 (VS 2010) : The type 'WebRequest' is not compatible with the type 'HttpWebRequest'

.net - 以编程方式访问 VSTO 中的功能区控件

c# - Excel 自动化,如何检测用户是否在 Excel 工作表中运行宏或单击 'Run Macro' CommandBarControl?

javascript - 有没有办法强制旧版本的 Excel Api(api 版本<=1.1)使列宽适合内容?

Excel 公式检查单元格内容

Wix 工具集 : cannot add Excel Add-in project reference