Transform appSettings from external file after merge

霸气de小男生 提交于 2019-12-05 19:50:40
Rock Jing

Interesting. I have the same issue like yours. So now here is a workaround for your reference. Please open project file - XXX.csproj for example, ISWB.Test.Unit.csproj

add below section like this

<!-- Rock Add here, 2015.03.19 enable the external config transformation -->
  <Target Name="BeforeCompile" Condition="Exists('ISWB.$(Configuration).config')">
    <!--Generate transformed app config in the intermediate directory-->
    <TransformXml Source="ISWB.config" Destination="$(IntermediateOutputPath)ISWB.config" Transform="ISWB.$(Configuration).config" />
    <!--Force build process to use the transformed configuration file from now on.-->
    <ItemGroup>
      <AppConfigWithTargetPath Remove="ISWB.config" />
      <AppConfigWithTargetPath Include="$(IntermediateOutputPath)ISWB.config">
        <TargetPath>ISWB.config</TargetPath>
      </AppConfigWithTargetPath>
    </ItemGroup>
  </Target>

  <Target Name="AfterCompile" Condition="Exists('app.$(Configuration).config')">
    <!--Generate transformed app config in the intermediate directory-->
    <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>
  </Target>

Please notice the added section, you have to add it into cs project file in a TEXT editor manually. Please replace ISWB with yours. And then save it.

it should work well. Enjoy it!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!