Multiple level web.config transform












0















Is there any way to apply a web.config transform on more than one level? E.g:



web.config
- web.release.config
- web.prod1.config
- web.prod2.config


When targeting prod1, I would like to do a 3 way merge web.config < web.release.config < web.prod1.config. Is this possible?










share|improve this question

























  • There is nothing out of the box that will do this. Your best bet, if you really want this, is to write your own VS extension or a t4 template or a post build command, etc. There are some options available but they all require code.

    – Igor
    Dec 4 '18 at 21:44


















0















Is there any way to apply a web.config transform on more than one level? E.g:



web.config
- web.release.config
- web.prod1.config
- web.prod2.config


When targeting prod1, I would like to do a 3 way merge web.config < web.release.config < web.prod1.config. Is this possible?










share|improve this question

























  • There is nothing out of the box that will do this. Your best bet, if you really want this, is to write your own VS extension or a t4 template or a post build command, etc. There are some options available but they all require code.

    – Igor
    Dec 4 '18 at 21:44
















0












0








0








Is there any way to apply a web.config transform on more than one level? E.g:



web.config
- web.release.config
- web.prod1.config
- web.prod2.config


When targeting prod1, I would like to do a 3 way merge web.config < web.release.config < web.prod1.config. Is this possible?










share|improve this question
















Is there any way to apply a web.config transform on more than one level? E.g:



web.config
- web.release.config
- web.prod1.config
- web.prod2.config


When targeting prod1, I would like to do a 3 way merge web.config < web.release.config < web.prod1.config. Is this possible?







c# asp.net web-config






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 12 '18 at 14:13









peinearydevelopment

4,17242346




4,17242346










asked Nov 13 '18 at 15:57









filurfilur

7731131




7731131













  • There is nothing out of the box that will do this. Your best bet, if you really want this, is to write your own VS extension or a t4 template or a post build command, etc. There are some options available but they all require code.

    – Igor
    Dec 4 '18 at 21:44





















  • There is nothing out of the box that will do this. Your best bet, if you really want this, is to write your own VS extension or a t4 template or a post build command, etc. There are some options available but they all require code.

    – Igor
    Dec 4 '18 at 21:44



















There is nothing out of the box that will do this. Your best bet, if you really want this, is to write your own VS extension or a t4 template or a post build command, etc. There are some options available but they all require code.

– Igor
Dec 4 '18 at 21:44







There is nothing out of the box that will do this. Your best bet, if you really want this, is to write your own VS extension or a t4 template or a post build command, etc. There are some options available but they all require code.

– Igor
Dec 4 '18 at 21:44














2 Answers
2






active

oldest

votes


















4





+125









There is a way to accomplish this. As you don't specify too much, I'm not sure this will satisfy your requirements though. The following is how it could be accomplished from scratch, but you could just pull the bits that you need directly into the csproj you already have.



Create a .csproj file:



Transform.csproj



<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="Web.config" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.Prod.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</None>
</ItemGroup>
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)WebMicrosoft.Web.Publishing.Tasks.dll"/>
<Target Name="TransformRelease">
<TransformXml Source="Web.config"
Transform="Web.Release.config"
Destination="Web.New.config"/>
</Target>
<Target Name="TransformProd">
<TransformXml Source="Web.New.config"
Transform="Web.Prod.config"
Destination="Web.New.config"/>
</Target>
</Project>


Then you can execute your two transforms through invoking an msbuild command from the command line. I used the following powershell commands.



.msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformRelease
.msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformProd


This will transform your web.config using the transforms in the web.release.config and create a new file with the result of that transform web.new.config. Then the second command will transform the web.new.config using the transforms in web.prod.config and update the web.new.config with that transformed value.



Web.config



<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="web" value="web" />
<add key="release" value="web" />
<add key="prod" value="web" />
<add key="release:prod" value="web" />
</appSettings>
</configuration>


Web.Release.config



<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="release" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="release:prod" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
</configuration>


Web.Prod.config



<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
<add key="release:prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
</appSettings>
</configuration>


Running the above commands produced Web.New.config



<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="web" value="web" />
<add key="release" value="release" />
<add key="prod" value="prod" />
<add key="release:prod" value="prod" />
</appSettings>
</configuration>


UPDATE



While the above works, I wouldn't want to use it in that manner. After tinkering around with the .csproj a bit, I came up with this which will do the transformation for you in the BeforeBuild task.



  <Target Name="TransformRelease">
<TransformXml Source="Web.config" Transform="Web.Release.config" Destination="Web.New.config" />
</Target>
<Target Name="TransformProd" Condition="'$(Configuration)' == 'Release'">
<TransformXml Source="Web.New.config" Transform="Web.Prod.config" Destination="Web.New.config" />
</Target>
<Target Name="BeforeBuild">
<MSBuild Projects="WebApplication1.csproj" Targets="TransformRelease;TransformProd"/>
</Target>


With these defined in your .csproj file, when you build the project as is, it will apply the Release transform alone. When you build the project in the Release configuration, it will apply both the Release and Prod transformations. Obviously you will need to tweak it for your needs given prod1, prod2, etc.






share|improve this answer

































    0














    Is not possible out of the box with simple commands, but you can do custom transformation and string replacement using build tasks



    A while ago I asked a similar questions and I got a really nice answer using build tasks transformation. Instead of copying it here, take a look in the solution and adapt to your needs.:



    Service Fabric Default Publish Profile other than Local.xml






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284827%2fmultiple-level-web-config-transform%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      4





      +125









      There is a way to accomplish this. As you don't specify too much, I'm not sure this will satisfy your requirements though. The following is how it could be accomplished from scratch, but you could just pull the bits that you need directly into the csproj you already have.



      Create a .csproj file:



      Transform.csproj



      <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup>
      <None Include="Web.config" />
      <None Include="Web.Debug.config">
      <DependentUpon>Web.config</DependentUpon>
      </None>
      <None Include="Web.Prod.config">
      <DependentUpon>Web.config</DependentUpon>
      </None>
      <None Include="Web.Release.config">
      <DependentUpon>Web.config</DependentUpon>
      </None>
      </ItemGroup>
      <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)WebMicrosoft.Web.Publishing.Tasks.dll"/>
      <Target Name="TransformRelease">
      <TransformXml Source="Web.config"
      Transform="Web.Release.config"
      Destination="Web.New.config"/>
      </Target>
      <Target Name="TransformProd">
      <TransformXml Source="Web.New.config"
      Transform="Web.Prod.config"
      Destination="Web.New.config"/>
      </Target>
      </Project>


      Then you can execute your two transforms through invoking an msbuild command from the command line. I used the following powershell commands.



      .msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformRelease
      .msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformProd


      This will transform your web.config using the transforms in the web.release.config and create a new file with the result of that transform web.new.config. Then the second command will transform the web.new.config using the transforms in web.prod.config and update the web.new.config with that transformed value.



      Web.config



      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
      <appSettings>
      <add key="web" value="web" />
      <add key="release" value="web" />
      <add key="prod" value="web" />
      <add key="release:prod" value="web" />
      </appSettings>
      </configuration>


      Web.Release.config



      <?xml version="1.0" encoding="utf-8"?>
      <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <appSettings>
      <add key="release" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
      <add key="release:prod" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
      </appSettings>
      </configuration>


      Web.Prod.config



      <?xml version="1.0" encoding="utf-8"?>
      <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <appSettings>
      <add key="prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
      <add key="release:prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
      </appSettings>
      </configuration>


      Running the above commands produced Web.New.config



      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
      <appSettings>
      <add key="web" value="web" />
      <add key="release" value="release" />
      <add key="prod" value="prod" />
      <add key="release:prod" value="prod" />
      </appSettings>
      </configuration>


      UPDATE



      While the above works, I wouldn't want to use it in that manner. After tinkering around with the .csproj a bit, I came up with this which will do the transformation for you in the BeforeBuild task.



        <Target Name="TransformRelease">
      <TransformXml Source="Web.config" Transform="Web.Release.config" Destination="Web.New.config" />
      </Target>
      <Target Name="TransformProd" Condition="'$(Configuration)' == 'Release'">
      <TransformXml Source="Web.New.config" Transform="Web.Prod.config" Destination="Web.New.config" />
      </Target>
      <Target Name="BeforeBuild">
      <MSBuild Projects="WebApplication1.csproj" Targets="TransformRelease;TransformProd"/>
      </Target>


      With these defined in your .csproj file, when you build the project as is, it will apply the Release transform alone. When you build the project in the Release configuration, it will apply both the Release and Prod transformations. Obviously you will need to tweak it for your needs given prod1, prod2, etc.






      share|improve this answer






























        4





        +125









        There is a way to accomplish this. As you don't specify too much, I'm not sure this will satisfy your requirements though. The following is how it could be accomplished from scratch, but you could just pull the bits that you need directly into the csproj you already have.



        Create a .csproj file:



        Transform.csproj



        <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <ItemGroup>
        <None Include="Web.config" />
        <None Include="Web.Debug.config">
        <DependentUpon>Web.config</DependentUpon>
        </None>
        <None Include="Web.Prod.config">
        <DependentUpon>Web.config</DependentUpon>
        </None>
        <None Include="Web.Release.config">
        <DependentUpon>Web.config</DependentUpon>
        </None>
        </ItemGroup>
        <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)WebMicrosoft.Web.Publishing.Tasks.dll"/>
        <Target Name="TransformRelease">
        <TransformXml Source="Web.config"
        Transform="Web.Release.config"
        Destination="Web.New.config"/>
        </Target>
        <Target Name="TransformProd">
        <TransformXml Source="Web.New.config"
        Transform="Web.Prod.config"
        Destination="Web.New.config"/>
        </Target>
        </Project>


        Then you can execute your two transforms through invoking an msbuild command from the command line. I used the following powershell commands.



        .msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformRelease
        .msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformProd


        This will transform your web.config using the transforms in the web.release.config and create a new file with the result of that transform web.new.config. Then the second command will transform the web.new.config using the transforms in web.prod.config and update the web.new.config with that transformed value.



        Web.config



        <?xml version="1.0" encoding="utf-8"?>
        <configuration>
        <appSettings>
        <add key="web" value="web" />
        <add key="release" value="web" />
        <add key="prod" value="web" />
        <add key="release:prod" value="web" />
        </appSettings>
        </configuration>


        Web.Release.config



        <?xml version="1.0" encoding="utf-8"?>
        <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
        <appSettings>
        <add key="release" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
        <add key="release:prod" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
        </appSettings>
        </configuration>


        Web.Prod.config



        <?xml version="1.0" encoding="utf-8"?>
        <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
        <appSettings>
        <add key="prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
        <add key="release:prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
        </appSettings>
        </configuration>


        Running the above commands produced Web.New.config



        <?xml version="1.0" encoding="utf-8"?>
        <configuration>
        <appSettings>
        <add key="web" value="web" />
        <add key="release" value="release" />
        <add key="prod" value="prod" />
        <add key="release:prod" value="prod" />
        </appSettings>
        </configuration>


        UPDATE



        While the above works, I wouldn't want to use it in that manner. After tinkering around with the .csproj a bit, I came up with this which will do the transformation for you in the BeforeBuild task.



          <Target Name="TransformRelease">
        <TransformXml Source="Web.config" Transform="Web.Release.config" Destination="Web.New.config" />
        </Target>
        <Target Name="TransformProd" Condition="'$(Configuration)' == 'Release'">
        <TransformXml Source="Web.New.config" Transform="Web.Prod.config" Destination="Web.New.config" />
        </Target>
        <Target Name="BeforeBuild">
        <MSBuild Projects="WebApplication1.csproj" Targets="TransformRelease;TransformProd"/>
        </Target>


        With these defined in your .csproj file, when you build the project as is, it will apply the Release transform alone. When you build the project in the Release configuration, it will apply both the Release and Prod transformations. Obviously you will need to tweak it for your needs given prod1, prod2, etc.






        share|improve this answer




























          4





          +125







          4





          +125



          4




          +125





          There is a way to accomplish this. As you don't specify too much, I'm not sure this will satisfy your requirements though. The following is how it could be accomplished from scratch, but you could just pull the bits that you need directly into the csproj you already have.



          Create a .csproj file:



          Transform.csproj



          <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
          <ItemGroup>
          <None Include="Web.config" />
          <None Include="Web.Debug.config">
          <DependentUpon>Web.config</DependentUpon>
          </None>
          <None Include="Web.Prod.config">
          <DependentUpon>Web.config</DependentUpon>
          </None>
          <None Include="Web.Release.config">
          <DependentUpon>Web.config</DependentUpon>
          </None>
          </ItemGroup>
          <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)WebMicrosoft.Web.Publishing.Tasks.dll"/>
          <Target Name="TransformRelease">
          <TransformXml Source="Web.config"
          Transform="Web.Release.config"
          Destination="Web.New.config"/>
          </Target>
          <Target Name="TransformProd">
          <TransformXml Source="Web.New.config"
          Transform="Web.Prod.config"
          Destination="Web.New.config"/>
          </Target>
          </Project>


          Then you can execute your two transforms through invoking an msbuild command from the command line. I used the following powershell commands.



          .msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformRelease
          .msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformProd


          This will transform your web.config using the transforms in the web.release.config and create a new file with the result of that transform web.new.config. Then the second command will transform the web.new.config using the transforms in web.prod.config and update the web.new.config with that transformed value.



          Web.config



          <?xml version="1.0" encoding="utf-8"?>
          <configuration>
          <appSettings>
          <add key="web" value="web" />
          <add key="release" value="web" />
          <add key="prod" value="web" />
          <add key="release:prod" value="web" />
          </appSettings>
          </configuration>


          Web.Release.config



          <?xml version="1.0" encoding="utf-8"?>
          <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
          <appSettings>
          <add key="release" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
          <add key="release:prod" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
          </appSettings>
          </configuration>


          Web.Prod.config



          <?xml version="1.0" encoding="utf-8"?>
          <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
          <appSettings>
          <add key="prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
          <add key="release:prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
          </appSettings>
          </configuration>


          Running the above commands produced Web.New.config



          <?xml version="1.0" encoding="utf-8"?>
          <configuration>
          <appSettings>
          <add key="web" value="web" />
          <add key="release" value="release" />
          <add key="prod" value="prod" />
          <add key="release:prod" value="prod" />
          </appSettings>
          </configuration>


          UPDATE



          While the above works, I wouldn't want to use it in that manner. After tinkering around with the .csproj a bit, I came up with this which will do the transformation for you in the BeforeBuild task.



            <Target Name="TransformRelease">
          <TransformXml Source="Web.config" Transform="Web.Release.config" Destination="Web.New.config" />
          </Target>
          <Target Name="TransformProd" Condition="'$(Configuration)' == 'Release'">
          <TransformXml Source="Web.New.config" Transform="Web.Prod.config" Destination="Web.New.config" />
          </Target>
          <Target Name="BeforeBuild">
          <MSBuild Projects="WebApplication1.csproj" Targets="TransformRelease;TransformProd"/>
          </Target>


          With these defined in your .csproj file, when you build the project as is, it will apply the Release transform alone. When you build the project in the Release configuration, it will apply both the Release and Prod transformations. Obviously you will need to tweak it for your needs given prod1, prod2, etc.






          share|improve this answer















          There is a way to accomplish this. As you don't specify too much, I'm not sure this will satisfy your requirements though. The following is how it could be accomplished from scratch, but you could just pull the bits that you need directly into the csproj you already have.



          Create a .csproj file:



          Transform.csproj



          <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
          <ItemGroup>
          <None Include="Web.config" />
          <None Include="Web.Debug.config">
          <DependentUpon>Web.config</DependentUpon>
          </None>
          <None Include="Web.Prod.config">
          <DependentUpon>Web.config</DependentUpon>
          </None>
          <None Include="Web.Release.config">
          <DependentUpon>Web.config</DependentUpon>
          </None>
          </ItemGroup>
          <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)WebMicrosoft.Web.Publishing.Tasks.dll"/>
          <Target Name="TransformRelease">
          <TransformXml Source="Web.config"
          Transform="Web.Release.config"
          Destination="Web.New.config"/>
          </Target>
          <Target Name="TransformProd">
          <TransformXml Source="Web.New.config"
          Transform="Web.Prod.config"
          Destination="Web.New.config"/>
          </Target>
          </Project>


          Then you can execute your two transforms through invoking an msbuild command from the command line. I used the following powershell commands.



          .msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformRelease
          .msbuild.exe "PATH_TO_YOUR_CSPROJTransform.csproj" /t:TransformProd


          This will transform your web.config using the transforms in the web.release.config and create a new file with the result of that transform web.new.config. Then the second command will transform the web.new.config using the transforms in web.prod.config and update the web.new.config with that transformed value.



          Web.config



          <?xml version="1.0" encoding="utf-8"?>
          <configuration>
          <appSettings>
          <add key="web" value="web" />
          <add key="release" value="web" />
          <add key="prod" value="web" />
          <add key="release:prod" value="web" />
          </appSettings>
          </configuration>


          Web.Release.config



          <?xml version="1.0" encoding="utf-8"?>
          <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
          <appSettings>
          <add key="release" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
          <add key="release:prod" value="release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
          </appSettings>
          </configuration>


          Web.Prod.config



          <?xml version="1.0" encoding="utf-8"?>
          <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
          <appSettings>
          <add key="prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
          <add key="release:prod" value="prod" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />
          </appSettings>
          </configuration>


          Running the above commands produced Web.New.config



          <?xml version="1.0" encoding="utf-8"?>
          <configuration>
          <appSettings>
          <add key="web" value="web" />
          <add key="release" value="release" />
          <add key="prod" value="prod" />
          <add key="release:prod" value="prod" />
          </appSettings>
          </configuration>


          UPDATE



          While the above works, I wouldn't want to use it in that manner. After tinkering around with the .csproj a bit, I came up with this which will do the transformation for you in the BeforeBuild task.



            <Target Name="TransformRelease">
          <TransformXml Source="Web.config" Transform="Web.Release.config" Destination="Web.New.config" />
          </Target>
          <Target Name="TransformProd" Condition="'$(Configuration)' == 'Release'">
          <TransformXml Source="Web.New.config" Transform="Web.Prod.config" Destination="Web.New.config" />
          </Target>
          <Target Name="BeforeBuild">
          <MSBuild Projects="WebApplication1.csproj" Targets="TransformRelease;TransformProd"/>
          </Target>


          With these defined in your .csproj file, when you build the project as is, it will apply the Release transform alone. When you build the project in the Release configuration, it will apply both the Release and Prod transformations. Obviously you will need to tweak it for your needs given prod1, prod2, etc.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Dec 5 '18 at 15:32

























          answered Dec 5 '18 at 14:49









          peinearydevelopmentpeinearydevelopment

          4,17242346




          4,17242346

























              0














              Is not possible out of the box with simple commands, but you can do custom transformation and string replacement using build tasks



              A while ago I asked a similar questions and I got a really nice answer using build tasks transformation. Instead of copying it here, take a look in the solution and adapt to your needs.:



              Service Fabric Default Publish Profile other than Local.xml






              share|improve this answer




























                0














                Is not possible out of the box with simple commands, but you can do custom transformation and string replacement using build tasks



                A while ago I asked a similar questions and I got a really nice answer using build tasks transformation. Instead of copying it here, take a look in the solution and adapt to your needs.:



                Service Fabric Default Publish Profile other than Local.xml






                share|improve this answer


























                  0












                  0








                  0







                  Is not possible out of the box with simple commands, but you can do custom transformation and string replacement using build tasks



                  A while ago I asked a similar questions and I got a really nice answer using build tasks transformation. Instead of copying it here, take a look in the solution and adapt to your needs.:



                  Service Fabric Default Publish Profile other than Local.xml






                  share|improve this answer













                  Is not possible out of the box with simple commands, but you can do custom transformation and string replacement using build tasks



                  A while ago I asked a similar questions and I got a really nice answer using build tasks transformation. Instead of copying it here, take a look in the solution and adapt to your needs.:



                  Service Fabric Default Publish Profile other than Local.xml







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 4 '18 at 21:45









                  Diego MendesDiego Mendes

                  4,38711826




                  4,38711826






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53284827%2fmultiple-level-web-config-transform%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine