解决方案配置,发布配置文件和web.config转换之间的关系 [英] Relationship between solution configuration, publish profile, and web.config transforms

查看:213
本文介绍了解决方案配置,发布配置文件和web.config转换之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2013 ASP.NET Web API 2项目中具有以下设置.

I have the following setup in a Visual Studio 2013 ASP.NET Web API 2 project.

  • Web.Develop.config Web转换以设置应用程序设置键值
  • Web.Release.config Web转换以删除应用程序设置键
  • Develop.pubxml映射到Web.Develop.config转换
  • Release.pubxml映射到Web.Release.config转换

每个的详细信息都在下面.

Details for each are found below.

<!-- Web.Develop.config (Web Config Transform) -->
<appSettings>
  <add key="ReportInputPath" 
       value="DevelopPath" 
       xdt:Transform="SetAttributes" 
       xdt:Locator="Match(key)" />
  </appSettings>

<!-- Web.Release.config (Web Config Transform) -->
<appSettings xdt:Transform="Remove" />

<!-- **Develop.pubxml (Publish Profile) -->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>x64</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>True</ExcludeApp_Data>
    <publishUrl>Path</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles
    <ExcludeFilesFromDeployment>packages.config</ExcludeFilesFromDeployment>
  </PropertyGroup>
</Project>

<!-- Release.pubxml (Publish Profile) -->
<!-- Contents are identical to Develop.pubxml. 
     This is used to target the Web.Release.Config transform. -->

每当我通过Release publish概要文件发布应用程序时,我的<appSettings/>元素都会被成功删除.但是,同时运行开发发布"配置文件时,也会删除<appSettings/>元素.

Whenever I publish the application via the Release publish profile my <appSettings/> element is successfully removed. However, <appSettings/> element is removed when the Develop publish profile is run as well.

我想了解的是:

为什么运行开发发布配置文件而不设置ReportInputPath值时会删除<appSettings/>元素?

Why is the <appSettings/> element being removed when I run the Develop publish profile instead of setting the ReportInputPath value?

解决方案/项目配置,发布配置文件和web.config转换之间的关系是什么?

And what are the relationships between the between solution/project configurations, publish profiles, and web.config transforms?

推荐答案

运行Develop publish配置文件时为何删除<appSettings/>元素的答案是因为两个转换按以下顺序运行.

The answer to why the <appSettings/> element is being removed when the Develop publish profile is run is because two transformations are run in the following order.

  1. Web.Release.config.之所以运行该命令,是因为Develop.pubxml文件中的配置目标是Release构建配置.
  2. Web.Develop.config.之所以运行该命令,是因为发布配置文件(开发)的名称与转换文件的名称匹配.

发生的是,第一个转换删除了<appSettings/>元素.第二个转换尝试在该元素中设置键值,但找不到它,因此它默默地失败了.

What is happening is the the first transformation removes the <appSettings/> element. The second transformation attempts to set the key value in that element, but cannot find it, so it silently fails.

我能够通过搜索控制台输出来确认这一点.运行Develop转换时,有一条警告,指出找不到所需的元素.

I was able to confirm this by searching through the console output. When the Develop transformation was run there was a warning that the desired element could not be found.

Example (shortened for clarity)
> TransformXml: Applying Transform File: C:\...\MyProject\Web.Develop.config
> C:\...\MyProject\Web.Develop.config(6,4): Warning : No element in the source document matches '/configuration/appSettings'
> TransformXml: Not executing SetAttributes (transform line 9, 10)

特定于配置文件的web.config转换和转换预览赛义德·易卜拉欣·哈希米(Sayed Ibrahim Hashimi)撰写的文章对确定这一问题非常有帮助.

The Profile specific web.config transforms and transform preview article by Sayed Ibrahim Hashimi was very helpful in identifying this was the issue.

就构建配置,发布配置文件和web.config转换之间的关系而言,我目前的理解是

As far as the relationship between the build configuration, publish profiles, and web.config transform go my current understanding is this.

  1. 发布配置文件具有(除其他外)配置目标
  2. 发布配置文件首先运行转换,该转换将映射到其指定的配置目标名称(如果存在)
  3. 发布配置文件,然后运行转换(如果存在的话)映射到其发布配置文件名称

关键是可以运行两个 web.config转换.

The key here being that two web.config transformations may be run.

这篇关于解决方案配置,发布配置文件和web.config转换之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆