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

标签 asp.net-core .net-core msbuild

dotnet publish我的 ASP.NET Core 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".

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

最佳答案

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

To prevent transformations of the web.config file, set the MSBuild property $(IsWebConfigTransformDisabled):

dotnet publish /p:IsWebConfigTransformDisabled=true

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

关于asp.net-core - 禁用 asp.net core 3.1 项目的 web.config 生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61613653/

相关文章:

asp.net-mvc - 如何将现有的 asp.net MVC 应用程序与 IdentityServer 集成?

c# - MySQL 连接错误 : Value Preferred is not of the correct type mysql

delphi - 如何让 MSBuild 完成相当于 dcc32 -b 的 Delphi 项目的完整构建?

c++ - MSBuild入参配置

powershell - 具有发布配置文件和配置合并的MSBuild

javascript - 有没有办法用一些 DEV 或 RELEASE 配置数据替换一些 javascript 变量(在构建时?)?

c# - 无法加载文件或程序集 'System.Private.ServiceModel,版本 = 4.1.2.4

asp.net-core - 使用 GenerateChangePhoneNumberTokenAsync() 来确认电子邮件而不是电话号码是否可以接受?

.net - project.json 相当于 InternalsVisibleTo

c# - 更新依赖注入(inject)的单例