与发布配置文件名称相关的 ASP.NET web.config 转换

问题描述 投票:0回答:2

我的 ASP.NET MVC 项目有三个发布配置文件。

我需要为所有这些添加转换。为此,我在 web.config 文件上选择了“添加配置转换”并获得了 4 个 Web 配置:

但我不明白如何将它们分配给任何发布配置文件。例如,我找不到用于开发发布配置文件的放置转换的正确配置文件。我怎样才能做到这一点 ? 感谢您的任何建议。

c# asp.net asp.net-mvc
2个回答
9
投票

我创建了一个新的 Web 配置,并将其命名为“Web.development.config”。 这是我用于转换的项目文件代码:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists('Web.$(Configuration).config')">
  <!-- Generate transformed app config in the intermediate directory -->
  <TransformXml Source="Web.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="Web.$(Configuration).config" />
  <!-- Force build process to use the transformed configuration file from now on. -->
  <ItemGroup>
    <AppConfigWithTargetPath Remove="Web.config" />
    <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
      <TargetPath>$(TargetFileName).config</TargetPath>
    </AppConfigWithTargetPath>
  </ItemGroup>
</Target>

因此,通过此解决方案,您可以使用

Web.<your publish profile name>.config


2
投票

当您想要创建发布配置文件时,您会看到一个下拉列表,您可以在其中指定其模式。尝试创建一个新的发布配置文件,您就会看到。

© www.soinside.com 2019 - 2024. All rights reserved.