I'm currently writing an msbuild script to publish a solution, which is all fine but i want to use a different app.config depending on what configuration is selected.
i've seen people talk about transforms, but this natively only works for web.config (yes you can do it for app.config with a little hacking but doesn't seem to work for the publish task on msbuild)
Creating msbuild script to build, publish with specified app.config, and update from different locations i've also seen this post but it doesn't actually answer this specific question (After reading the links).
currently my build script looks like:
<PropertyGroup>
<ProjectFile>.\BarcodeScannerApp\BarcodeScannerApp.csproj</ProjectFile>
<SolutionFile>.\BarcodeScannerApp.sln</SolutionFile>
<PublishLoc>http://publishlocation.com</PublishLoc>
<Configuration>release</Configuration>
<GenerateManifests>false</GenerateManifests>
<BootstrapperEnabled>true</BootstrapperEnabled>
<ApplicationVersion>1.0.0.*</ApplicationVersion>
<UpdateEnabled>true</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateUrl>http://backoffice-dev/</UpdateUrl>
</PropertyGroup>
<Target Name="PublishApp">
<MSBuild Projects="$(SolutionFile)"
Targets="Publish"
Properties="PublishUrl=$(PublishLoc);
Configuration=$(Configuration);
GenerateManifests=$(GenerateManifests);
BootstrapperEnabled=$(BootstrapperEnabled);
ApplicationVersion=$(ApplicationVersion);
UpdateEnabled=$(UpdateEnabled);
UpdateMode=$(UpdateMode);
UpdateUrl=$(UpdateUrl)"
/>
</Target>
currently when this script is run, it generates a file BarcodeScannerApp.exe.config which is a copy of the app.config i have in the solution. i want to use a different config file depending on what different configuration i set up (Debug / Release).
As first you need to define properties which references an app.config
path for all config files like:
<DebugConfig>...</DebugConfig>
<ReleaseConfig>...</ReleaseConfig>
<TargetConfigPath>...</TargetConfigPath>
And then using WHEN
select an appropriate one and rewrite into the target directory
<When Condition="'$(Configuration)'=='DEBUG'">
...
</When>
<When Condition="'$(Configuration)'=='RELEASE'">
...
</When>
You can rewrite files before executing PublishApp
targetby introducing new target and create target dependency.