VSTO调试版本良好,已安装版本未读取app.config [英] VSTO Debug version fine, Installed version doesn't read app.config

查看:94
本文介绍了VSTO调试版本良好,已安装版本未读取app.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a VSTO Excel 2007 add-in that should read connectionstrings from the app.config file, and then let the user decide which database to connect to. This works fine when I debug it, but when I run the deployed version (done with Windows Installer) the connectionstrings aren't read at all. I have added the primary outputs from all the projects to the setup project. The app.config file is in the ExcelAddIn project, but not under the Excel heading. The class that manages the connectionstrings is in another project.

这是我的app.config文件:

Here is my app.config file:

    <?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>

我使用以下命令获取连接字符串:

I use the following to get to the connectionstrings:

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

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

I have tried to add the ExcelAddin.dll.config file to the setup project's folder in which the Release folder and .proj file are. I have set the app.config file's 'Copy to Output Directory' property to 'Copy always' and the Build Action property to 'Content'.

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

Is there something worng with my app.config file, or why is it not picked up (the connectionstrings are not loaded into csSection) after I've run the installer?

推荐答案

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

Add file:/// to [TARGETDIR]ExcelAddIn.vsto|vstolocal (ex: file:///[TARGETDIR]ExcelAddIn.vsto|vstolocal) at the registry entries under "installer".

这篇关于VSTO调试版本良好,已安装版本未读取app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆