c# - 使用 Visual Studio 2019 运行应用程序时,如何防止在 Asp.Net Core API 3.1 中自动生成 web.config?
问题描述
我正在开发 Asp.Net Core 3.1 API,它按预期工作。
当我运行它时,它会自动将原始 web.config 转换为新的。
原始 Web.config 文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\EngageAPI.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
</system.webServer>
</location>
</configuration>
新的 web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="COMPLUS_ForceENC" value="1" />
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
所以我有两个问题。
- 为什么会自动生成?
- 我怎样才能停止这种自动生成?
更新:
为问题添加更多说明:
为什么会导致这个问题?我正在从 azure dev ops 进行部署。我做什么我将 web.config 从我的项目复制到我正在创建的包中。并注意到当您从 VS 运行代码时,此 web.config 被修改为新的 web.config(具有 %LAUNCHER_PATH% %LAUNCHER_ARGS%)。所以基本上我们不需要复制这个web.config。而不是这个,我们需要复制在发布文件夹中生成的那个。
CsProj 文件
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Dapper" Version="2.0.35" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.7" />
<PackageReference Include="Microsoft.Azure.Storage.Common" Version="11.1.7" />
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.1.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
</ItemGroup>
</Project>
解决方案
似乎您在调试时使用的是 IIS 而不是 IIS express。
尝试将此添加到您的 .csproj 文件中:
<ANCMPreConfiguredForIIS>true</ANCMPreConfiguredForIIS>
还要确保您的 VS 版本 >= VS 16.6.3
这是 websdk 团队现已修复的问题: https ://github.com/dotnet/websdk/issues/564#issuecomment-644199581
推荐阅读
- javascript - highcharts散点图中的绘图线(垂直线)
- eclipse - Javafx Stage 在显示元素前几秒钟是空白的
- powershell - 如何通过 powershell 代码提供键盘输入?
- opencv - 如何确定图像中的物体是平面还是非平面?
- node.js - 在 Node 服务器的 Mailgun 模板中使用变量
- firebase - 并发文档创建/删除时,firestore 事务是否会再次运行?
- angular-cli - Keycloak 应用程序中的 Service Worker 操作
- puppeteer - Target.sendMessageToTarget 已弃用——我现在如何使用 devtools 协议的扁平化风格?
- javascript - 循环形式的 AJAX 请求
- reactjs - Framer Motion:与父子动画冲突