disable web.config generation for asp.net core 3.1 project

馋奶兔 提交于 2020-06-12 08:37:52

问题


The dotnet publish command for my ASP.NET Core 3.1 project creates a web.config file in my publish/ directory. I don't want this file to be generated (or copied to that folder, at least) - it is never to be used with IIS at all.

When I took a look at the command output with verbosity increased, I found the following text:

   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".

Is it somehow possible to configure my project to skip the _TransformWebConfig Target or TransformWebConfig Task - or to use another way to skip the generation? I know I could make MSBuild delete the file afterwards, but having this disabled seems less hacky to me.


回答1:


You can control this with the IsWebConfigTransformDisabled MSBuild property:

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

dotnet publish /p:IsWebConfigTransformDisabled=true

Because this is an MSBuild property, you can set it in the .csproj, instead of passing it as a command-line argument:

<PropertyGroup>
    <IsWebConfigTransformDisabled>true</IsWebConfigTransformDisabled>
</PropertyGroup>


来源:https://stackoverflow.com/questions/61613653/disable-web-config-generation-for-asp-net-core-3-1-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!