7

I have created a console application (blah.exe) with specific app.config's for dev and prod. These are named dev_app.config and prod_app.config. I have hooked up an AfterBuild target in my csproj file* which copies the correct config file to the bin directory as blah.exe.config.

I have also created a setup project for this console app but I have run into a slight issue. It seems that the setup project uses the actual app.config from the project directory as opposed to the final blah.exe.config (located in bin directory).

|--Bin
|  |--Debug
|     |--Blah.exe.config <--- I want the setup project to use this file
|--app.config <--- Setup project uses this file at the moment
|--dev_app.config
|--prod_app.config

How can I force the setup project to use the final config file generated in the bin folder and not the actual app.config file?

Additional Information:

My current solution involves adding another AfterBuild command which overwrites the actual app.config file. I don't like approach since it forces me to have an additional file that I don't need. Also, having this file has caused me some grief already since I made changes to the app.config file which got overwritten when building. The question is about how to get the setup project use the final config file in the bin folder and NOT how to manage the config or ways to create a config file.

* Adapted from Deploy an app.config based on build configuration

Community
  • 1
  • 1
Ahmad
  • 22,657
  • 9
  • 52
  • 84
  • Are you using DEBUG version for dev, and release for production? If so, you could take a look at using #if DEBUG http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx and maybe load the different config files based on that using http://msdn.microsoft.com/en-us/library/ms223161.aspx – Adriaan Stander Feb 18 '11 at 05:31
  • @astander, yes `dev_app.config` for Debug and `prod_app.config` for Release. – Ahmad Feb 18 '11 at 05:33
  • Not sure why you are doing it this way. Create the base .config file to be suitable for deployment. Only create a special one for the Debug configuration. Deploy the Release build. – Hans Passant Feb 18 '11 at 05:34
  • @astander - please clarify, where would I implement your suggestion. In my console app? If so, that does not make sense to me since the correct file is copied to my bin folder. – Ahmad Feb 18 '11 at 05:38
  • @hans - that does makes sense to a degree, but what if I need to deploy a Debug release of my project (which I will need to for an initial POC) - the Setup project will use the prod ready version of the config file. – Ahmad Feb 18 '11 at 05:41
  • Easily covered by my recommendation. Just don't do the special thing. – Hans Passant Feb 18 '11 at 05:47
  • 1
    Assuming you're concerned with appSettings values, another option would be to use the "file" attribute to override the settings for debug scenarios. . Then create your own custom.config file in your debug folder to override values as needed. – randbrown Feb 18 '11 at 21:26

1 Answers1

3

I have been using that exact same scenario but I use the BeforeBuild instead of AfterBuild, and it has always been fine. I have been doing this on both web and windows projects. Below is the code I am using.

  <Target Name="BeforeBuild">
    <ItemGroup>
      <ConfigSourceFiles Include="Web.$(Configuration).config" />
      <ConfigDestinationFiles Include="Web.config" />
    </ItemGroup>
    <Copy SourceFiles="@(ConfigSourceFiles)" DestinationFiles="@(ConfigDestinationFiles)" />
  </Target>

Hope this helps.

Ron Nicholson
  • 86
  • 1
  • 5