2

I created an app.config transform for my WinForms project using Dan Abramov's solution here. Works great and the config file is transformed and present in the correct obj folder.

When I look at the outputs for the Primary Output of my application, it gets the app.config from the project directory instead of the corresponding obj folder like everything else...a big oversight, in my opinion, by MSFT. Obviously, they didn't have transforms in mind for all config file types.

So now, how do I get the Primary Output of my main project to output the config file from the obj folder based on the build configuration?

Community
  • 1
  • 1
jonnyb
  • 352
  • 1
  • 2
  • 17
  • Why not use the files directly instead of a project output? This way you can control the source. – Cosmin Oct 26 '11 at 06:52
  • 1
    @Cosmin I could, but I am trying to automate my build process and that would require me to select a file based on the build configuration. I am using the config transform to change WCF URLs, which change based on my build. – jonnyb Oct 26 '11 at 13:32

2 Answers2

0

Have you tried using SlowCheetah (a VS extension) which enables you to transform app.config in the same way that web.config works. Also your scenario for transforming app.config for a setup project is supported.

Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
  • Thanks for the response. I'll have to check this out with the next project I do. I did get an app.config to transform as stated previously, but it was definitely a pain. Why the VS team didn't think/care that anyone would want to transform an app.config is beyond me. Thanks again for the response! – jonnyb Jun 20 '12 at 14:28
-1

I found the work around I was looking for here. Scroll to the bottom and see kakoskin's answer. In conjunction with Dan Abramov's solution, I was able to get the results I was looking for. Here's the MSBuild code I used:

  <Target Name="AfterBuild" Condition="exists('app.$(Configuration).config')">
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
  <AppConfigWithTargetPath Remove="app.config" />
  <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
    <TargetPath>$(TargetFileName).config</TargetPath>
  </AppConfigWithTargetPath>
</ItemGroup>
<TransformXml Source="App.config" Transform="app.$(Configuration).config" Destination="App.Transformed.config" />

The <ItemGroup> section will remove the app.config file from the corresponding obj\ folder and replace it with the transformed config file, which is not needed but I left it in there anyways.

Hope this helps others out as well!

Community
  • 1
  • 1
jonnyb
  • 352
  • 1
  • 2
  • 17
  • This didn't work for me. I still get the un-transformed config in the MSI generated by the Setup Project – fuzzbone Dec 19 '11 at 19:39
  • @fuzzbone: did you put the code in the project file for the Setup Project or the project file of the project that contains the config file you are looking to transform? – jonnyb Dec 20 '11 at 15:18
  • I put the code in the csproj - the project file that contains the config file I tried to transform. No luck. I've given up on Setup Projects and am learning WIX... – fuzzbone Jan 11 '12 at 23:02