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

时间:2017-02-14 23:49:57

标签: c# asp.net asp.net-mvc

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

enter image description here

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

enter image description here

但是我无法理解如何将它们中的任何一个分配给任何发布配置文件。例如,我找不到用于开发发布配置文件的put转换的正确配置文件。我怎样才能做到这一点 ? 谢谢你的任何建议。

2 个答案:

答案 0 :(得分:3)

我创建了一个新的网络配置,我将其命名为#34; 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

答案 1 :(得分:2)

如果要创建发布配置文件,您会看到一个下拉列表,您可以在其中指定它将采用的模式。尝试创建一个新的发布配置文件,您将看到。

enter image description here

相关问题