How to prevent msbuild config transforms in particular environments? : <p>I have a azure webjob project that uses config transforms to create dev/test/release configuration. We are using TFS for CI/CD deployment to Azure. I want to have MSBuild apply the transforms for dev so we can debug locally. However, when we are building in TFS in the CI/CD pipeline I need to disable the config transforms during the build step. </p>

<p>TFS has an "apply XML transformations" checkbox in the release step, which is where we want the transforms applied since we have the environment variable set during release. Unfortunately, this is not working because the transforms are already applied during build so the release artifact only has the finished output file, not the separate transform files. </p>

<p>I have tried editing the .csproj file to disable the transforms. I assume the transforms are being performed by the following section of the project file:</p>

<pre><code>&lt;UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" /&gt;
  &lt;Target Name="AfterCompile" Condition="Exists('App.$(Configuration).config')"&gt;
    &lt;!--Generate transformed app config in the intermediate directory--&gt;
    &lt;TransformXml Source="App.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="App.$(Configuration).config" /&gt;
    &lt;!--Force build process to use the transformed configuration file from now on.--&gt;
    &lt;ItemGroup&gt;
      &lt;AppConfigWithTargetPath Remove="App.config" /&gt;
      &lt;AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config"&gt;
        &lt;TargetPath&gt;$(TargetFileName).config&lt;/TargetPath&gt;
      &lt;/AppConfigWithTargetPath&gt;
    &lt;/ItemGroup&gt;
  &lt;/Target&gt;
  &lt;!--Override After Publish to support ClickOnce AfterPublish. Target replaces the untransformed config file copied to the deployment directory with the transformed one.--&gt;
  &lt;Target Name="AfterPublish"&gt;
    &lt;PropertyGroup&gt;
      &lt;DeployedConfig&gt;$(_DeploymentApplicationDir)$(TargetName)$(TargetExt).config$(_DeploymentFileMappingExtension)&lt;/DeployedConfig&gt;
    &lt;/PropertyGroup&gt;
    &lt;!--Publish copies the untransformed App.config to deployment directory so overwrite it--&gt;
    &lt;Copy Condition="Exists('$(DeployedConfig)')" SourceFiles="$(IntermediateOutputPath)$(TargetFileName).config" DestinationFiles="$(DeployedConfig)" /&gt;
  &lt;/Target&gt;
</code></pre>

<p>I tried adding conditions like "$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" to these sections, and it did not help (the transforms still got applied in all three environments). I even commented this section out completely, and I still got the transforms. This leaves me with three questions:</p>

<ol>
<li>How can the config transforms be disabled? </li>
<li>How can I conditionally
disable them so they are still applied when debugging in VS? </li>
<li>Is this
the correct approach, or is there a better way to get the correct
transform applied when using CI/CD in TFS 2017?</li>
</ol>
