xml-transform
xml transforms in non-web projects using msbuild
Adding XML transforms to non-Web projects (Console, Winforms, WPF etc.)
- Add Debug/Release versions of confit as XDT transforms
- Add
MSBuild.Microsoft.VisualStudio.Web.targets
nugetPackageReference
Import
targets (conditionally or it won’t load the first time)- Add
TransformXml
toAfterBuild
<Project>
...
<ItemGroup>
<None Include="App.config" />
<None Include="App.Debug.config">
<DependentUpon>App.config</DependentUpon>
<SubType>Designer</SubType>
</None>
<None Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
<SubType>Designer</SubType>
</None>
</ItemGroup>
...
<ItemGroup>
<PackageReference Include="MSBuild.Microsoft.VisualStudio.Web.targets">
<Version>14.0.0.3</Version>
</PackageReference>
</ItemGroup>
...
<Import Condition="Exists('$(VSToolsPath)\Web\Microsoft.Web.Publishing.targets')" Project="$(VSToolsPath)\Web\Microsoft.Web.Publishing.targets" />
...
<Target Name="AfterBuild">
<TransformXml Source="@(AppConfigWithTargetPath)" Transform="App.$(Configuration).config" Destination="@(AppConfigWithTargetPath->'$(OutDir)%(TargetPath)')" />
</Target>
</Project>