【问题标题】:VSTO Debug version fine, Installed version doesn't read app.configVSTO 调试版本正常,安装版本不读取 app.config
【发布时间】:2015-04-09 01:12:50
【问题描述】:

我有一个 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>

我使用以下方法获取连接字符串:

System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        ConnectionStringsSection csSection = config.ConnectionStrings;

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

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

【问题讨论】:

    标签: visual-studio-2010 vsto excel-addins


    【解决方案1】:

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

    【讨论】:

    • 这个答案为我节省了几个小时的工作时间。谢谢!当您使用 MSI 制作 VSTO 安装程序时,请检查您的 Manifest 注册表项值是否以 file:/// 开头,如上述答案中所述。否则加载项将使用 Excel.exe.config(如果您编写 Excel 加载项)而不是您的配置。
    • 甜蜜!这对我们有用。我们遇到了一个奇怪的问题,当为当前用户安装时会找到配置文件,但在为所有用户安装时不会找到。修改清单 URL 解决了它。
    【解决方案2】:

    您需要将 app.Config 文件添加到您的安装项目中,而不是从实际项目中添加,请从 ExcelAddIn 项目的 Release\Debug 文件夹中进行。

    当您构建 ExcelAddIn 项目时,它会将 App.config 文件留在 Release\Debug 文件夹中,在那里选择文件表单并将其包含到安装项目的依赖项文件夹中。

    【讨论】:

    • 我不确定我是否理解正确。我构建了 ExcelAddin 项目。然后我单击安装项目并从 ExcelAddin 的 Release 文件夹中添加 ExcelAddin.dll.config。然后我构建安装项目,清理解决方案,并安装 msi。不幸的是,这并不能解决问题。我尝试了与上面相同的方法,但在 ExcelAddin 文件夹中找到了 app.config 文件(不在 bin/Release 的更下方)。然后我在资源管理器中复制 ExcelAddin.dll.config 文件并将其粘贴到安装项目的文件夹(.proj 所在的位置)。与 app.config 类似。没有快乐。
    • 您是否将 ExcelAddin 项目的主要输出提供给您的安装项目?
    • 是的,我有,也是所有其他项目的主要输出。
    【解决方案3】:

    似乎它正在与 ClickOnce 一起使用。所以我仍然不知道安装项目和使用 Windows Installer 的问题是什么,但至少我可以部署它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 2020-08-21
      • 1970-01-01
      • 2021-08-13
      • 2017-07-30
      • 1970-01-01
      相关资源
      最近更新 更多