Skip to content

Instantly share code, notes, and snippets.

@phillijw
Created February 16, 2017 16:15
Show Gist options
  • Save phillijw/10987f496953ae7293a62a5c92d4c896 to your computer and use it in GitHub Desktop.
Save phillijw/10987f496953ae7293a62a5c92d4c896 to your computer and use it in GitHub Desktop.
<PropertyGroup>
<EnvConfig>$(EnvConfig)</EnvConfig>
<EnvConfig Condition=" '$(EnvConfig)' == '' ">Local</EnvConfig>
</PropertyGroup>
...
<Content Include="Web.Production.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
<Content Include="Web.Test.config">
<DependentUpon>Web.config</DependentUpon>
</Content>
...
<Target Name="AfterBuild" Condition="Exists('Web.$(Configuration).config')">
<!--Generate transformed config in the output directory-->
<TransformXml Source="Web.config" Destination="$(OutputPath)Web.config" Transform="Web.$(Configuration).config" />
<TransformXml Condition="Exists('Web.$(EnvConfig).config')" Source="$(OutputPath)Web.config" Destination="$(OutputPath)Web.config" Transform="Web.$(EnvConfig).config" />
</Target>
...
Then use msbuild to pass in the necessary params:
"C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe" ../MEDIC.Web.csproj /t:rebuild /p:Configuration=Release /p:EnvConfig="Production"
This will do a build and produce a Web.config file that has been transformed with the Web.Release.config and then the Web.Production.config similar to how Octopus does it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment