简体   繁体   中英

Strange transform behaviour for web.config when publishing a webapp

I have created a new mvc webapp with the following transforms for web.config:

Web.Debug.config

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="Debug" value="true" xdt:Transform="Insert"/>
  </appSettings>
</configuration>

Web.Release.config

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="Release" value="true" xdt:Transform="Insert"/>
  </appSettings>  
</configuration>

Then I created a publish profile and called it Release, but I select the Debug(OBS! important) build configuration.

(I know. Stupid example. In my real project they were called Test and Test2.)

When I run the publish action I get the following in the transformed Web.config:

  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="Debug" value="true"/>
    <add key="Release" value="true"/>
  </appSettings>

Both the transformations were performed! Strange! If I change the name of the publish profile to Release2 I get following correct result:

  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="Debug" value="true"/>
  </appSettings> 

What do you think? Bug?

Met same issue and finally was able to identify the reason and resolve it.

This issue happens because of publish profiles configuration settings mess. When you set up profile with configuration manager you should make sure Current Solution Configuration matches Configuration that is going to be used: Easiest way for configuration to track config Transformations

Otherwise, remember, that before selected Profile configuration, selected Configuration Transformation would be applied.

So, make sure you don't have twice assigned Configuration for different profiles. If so, just add one more configuration for 'failed' profile to resolve it and you get what you expected on transformation applied.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM