我的 ASP.NET MVC 项目有三个发布配置文件。
我需要为所有这些添加转换。为此,我在 web.config 文件上选择了“添加配置转换”并获得了 4 个 Web 配置:
但我不明白如何将它们分配给任何发布配置文件。例如,我找不到用于开发发布配置文件的放置转换的正确配置文件。我怎样才能做到这一点 ? 感谢您的任何建议。
我创建了一个新的 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