6

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.

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;

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'.

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?

Igavshne
  • 699
  • 7
  • 33

3 Answers3

7

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

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Madhur
  • 98
  • 1
  • 9
  • This answer saved me hours of work. Thank you! When you make VSTO installers using MSI, check that your `Manifest` registry key value begins with `file:///` as described in the above answer. Else the Add-In will use Excel.exe.config (if you write an Excel Add-In) instead of your config. – lennartk Aug 19 '15 at 09:51
  • Sweet! This worked for us. We had a weird issue, where the config file would be found when installed for current user but not when installed for all users. Modifying manifest URL resolved it. – Søren Boisen Mar 11 '19 at 15:29
0

You need to add app.Config File to your Setup Project but not from the actual project do it from the Release\Debug folder of the ExcelAddIn project.

When you build you ExcelAddIn project it will leave App.config File to the Release\Debug Folder, piCk the file form there and include it into the dependicies folder of the Setup Project.

I kiet
  • 176
  • 2
  • 12
  • I'm not sure whether I understand you correctly. I build the ExcelAddin project. Then I click on the Setup project and Add the ExcelAddin.dll.config from the ExcelAddin's Release folder. Then I build the Setup project, clean the solution, and install the msi. Unfortunately this does not solve the problem. I tried the same as above, but with the app.config file found in the ExcelAddin folder (not further down in the bin/Release). Then I copied the ExcelAddin.dll.config file in Explorer and pasted it into the Setup project's folder (where the .proj is). Similarly with the app.config. No joy. – Igavshne Sep 05 '13 at 06:43
  • Have you given the the primary output of ExcelAddin project to your Setup Project? – I kiet Sep 05 '13 at 08:02
  • Yes I have, and also the primary output of all the other projects. – Igavshne Sep 05 '13 at 11:17
0

It seems that it is working with ClickOnce. So I still don't know what the problem was with the setup project and using Windows Installer, but at least I can deploy it.

Igavshne
  • 699
  • 7
  • 33