在Asp.NET Core中设置web.config转换 [英] Set web.config transform in Asp.NET Core
问题描述
我刚遇到asp.net核心中的web.config转换问题.
I've just came across with problem of web.config transformation in asp.net core.
有两个文件:基本web.config和web.prod-zone-a.config.我的目标是在发布项目时在web.prod-zone-a.config内部使用转换. 我在.csproj中具有以下"prod-zone-a"配置设置:
There are two files: base web.config and web.prod-zone-a.config. My aim is to use transformation inside web.prod-zone-a.config when publishing my project. I have the following "prod-zone-a" configuration settings in .csproj:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'prod-zone-a|AnyCPU' ">
<IntermediateOutputPath>obj\Debug\netcoreapp1.1</IntermediateOutputPath>
<DebugSymbols>true</DebugSymbols>
<Optimize>false</Optimize>
<DefineConstants>TRACE;DEBUG;NETCOREAPP1_1</DefineConstants>
<Configuration>prod-zone-a</Configuration>
</PropertyGroup>
web.prod-zone-a.config看起来像:
web.prod-zone-a.config looks like:
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore>
<environmentVariables xdt:Transform="Replace">
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="prod-zone-a" />
</environmentVariables>
</aspNetCore>
</system.webServer>
我试图通过两个命令来运行发布:
I tried to run publish by two commands:
dotnet msbuild /t:Publish /p:OutputPath=c:\delivery /p:Configuration=prod-zone-a
和
dotnet publish --configuration prod-zone-a --output c:\delivery
但是没有转换适用于输出的web.config-仅是默认值. 我会错过配置或命令执行过程中的某些内容吗?
But no transformation applies to web.config on output - just the default value. Do I miss something in configuration or command executing?
推荐答案
There is a well-documented tool on github for xdt-transformations.
Also it doesn't depend on command, both of dotnet publish
and dotnet msbuild
works fine
这篇关于在Asp.NET Core中设置web.config转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!