简体   繁体   English

发布Web应用程序时Web.config的奇怪转换行为

[英]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.config的转换创建了一个新的mvc webapp:

Web.Debug.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 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. 然后,我创建了一个发布配置文件并将其命名为Release,但是我选择了Debug(OBS!重要)构建配置。

(I know. Stupid example. In my real project they were called Test and Test2.) (我知道。这是愚蠢的例子。在我的真实项目中,它们被称为Test和Test2。)

When I run the publish action I get the following in the transformed Web.config: 当我运行发布动作时,在转换后的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: 如果将发布配置文件的名称更改为Release2,则会得到以下正确结果:

  <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. 如果是这样,只需为“失败的”配置文件添加一个配置即可解决该配置,您将获得预期的转换效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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