我在Visual Studio 2013 ASP.NET Web API 2项目中具有以下设置。
有关每个的详细信息,请参见下文。
<!-- 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. -->
每当我通过发布发布配置文件发布应用程序时,我的
<appSettings/>
元素都会被成功删除。但是,当同时运行“开发发布”配置文件时,也会删除<appSettings/>
元素。我想了解的是:
为什么在运行“开发发布”配置文件而不是设置ReportInputPath值时删除了
<appSettings/>
元素?解决方案/项目配置,发布配置文件和web.config转换之间的关系是什么?
最佳答案
运行Develop publish配置文件时为何删除<appSettings/>
元素的答案是,因为两个转换按以下顺序运行。
发生的是,第一个转换删除了
<appSettings/>
元素。第二个转换尝试在该元素中设置键值,但找不到它,因此它默默地失败了。我可以通过搜索控制台输出来确认这一点。运行Develop转换时,有一条警告,指出找不到所需的元素。
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)
赛义德·易卜拉欣·哈希米(Sayed Ibrahim Hashimi)发表的Profile specific web.config transforms and transform preview文章对确定此问题非常有帮助。
就构建配置,发布配置文件和web.config转换之间的关系而言,我目前的理解是。
这里的关键是可以运行两个web.config转换。
关于visual-studio - 解决方案配置,发布配置文件和web.config转换之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31737080/