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?

4

2 回答 2

0

您是否尝试过使用SlowCheetah(一个 VS 扩展),它使您能够以与 web.config 相同的方式转换 app.config。还支持为安装项目转换 app.config 的方案。

于 2012-04-28T02:55:44.860 回答
-1

我在这里找到了我正在寻找的工作。滚动到底部并查看 kakoskin 的答案。结合Dan Abramov 的解决方案,我能够得到我正在寻找的结果。这是我使用的 MSBuild 代码:

  <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" />

<ItemGroup>部分将从相应的 obj\ 文件夹中删除 app.config 文件并将其替换为转换后的配置文件,这不是必需的,但我还是把它留在了那里。

希望这对其他人也有帮助!

于 2011-11-01T17:04:25.527 回答