禁用 asp.net core 3.1 项目的 web.config 生成

muf*_*fel 6 msbuild .net-core asp.net-core

dotnet publish我的ASP.NET 3.1的核心项目命令创建一个web.config在我的文件publish/目录。我不希望生成此文件(或至少将其复制到该文件夹​​中)-它根本不会与 IIS 一起使用。

当我查看详细程度增加的命令输出时,我发现了以下文本:

   Target "_TransformWebConfig" in file "C:\Program Files\dotnet\sdk\3.1.200\Sdks\Microsoft.NET.Sdk.Publish\targets\TransformTargets\Microsoft.NET.Sdk.Publish.TransformFiles.targets" from project "C:\repos\reportweb\reportweb\reportweb.csproj" (target "_AspNetCoreProjectSystemPostPublish" depends on it):
       Using "TransformWebConfig" task from assembly "C:\Program Files\dotnet\sdk\3.1.200\Sdks\Microsoft.NET.Sdk.Publish\targets\..\tools\netcoreapp2.1\Microsoft.NET.Sdk.Publish.Tasks.dll".
       Task "TransformWebConfig"
         Configuring the following project for use with IIS: 'C:\repos\reportweb\reportweb\bin\Release\netcoreapp3.1\linux-x64\publish\'
         Updating web.config at 'C:\repos\reportweb\reportweb\bin\Release\netcoreapp3.1\linux-x64\publish\web.config'
         Configuring project completed successfully
       Done executing task "TransformWebConfig".
   Done building target "_TransformWebConfig" in project "reportweb.csproj".
Run Code Online (Sandbox Code Playgroud)

是否可以将我的项目配置为跳过_TransformWebConfig目标或TransformWebConfig任务 - 或者使用另一种方式跳过生成?我知道我可以让 MSBuild 之后删除文件,但是禁用此功能对我来说似乎不那么麻烦

Kir*_*kin 5

您可以使用IsWebConfigTransformDisabledMSBuild 属性来控制它:

要防止 web.config 文件的转换,请设置 MSBuild 属性$(IsWebConfigTransformDisabled)

dotnet publish /p:IsWebConfigTransformDisabled=true
Run Code Online (Sandbox Code Playgroud)

因为这是一个 MSBuild 属性,您可以在 .csproj 中设置它,而不是将它作为命令行参数传递:

<PropertyGroup>
    <IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)