app.config ファイルから接続文字列を読み取る VSTO Excel 2007 アドインがあり、ユーザーが接続先のデータベースを決定できるようにします。これは、デバッグ時には正常に機能しますが、展開されたバージョン (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="data source=myServer;initial catalog=myDB;persist security info=True;user id=myUser;password=myPassword;multipleactiveresultsets=True;App=EntityFramework"" 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;
Releaseフォルダーと.projファイルがあるセットアッププロジェクトのフォルダーにExcelAddin.dll.configファイルを追加しようとしました。app.config ファイルの 'Copy to Output Directory' プロパティを 'Copy always' に設定し、Build Action プロパティを 'Content' に設定しました。
app.config ファイルに何か摩耗がありますか、それとも、インストーラーを実行した後、それが検出されない (接続文字列が csSection に読み込まれない) のはなぜですか?