我的dotnet core 3.1 webapp tasks.json
中有以下内容:
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000",
"LOCAL": "true"
},
当我运行dotnet publish
时,Debug 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=".\App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
</system.webServer>
</location>
</configuration>
因为我想在IIS下托管,这就是我希望它包含的内容,所以现在我需要手动编辑它:
<?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=".\App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariable name="ASPNETCORE_URLS" value="http://localhost/app" />
<environmentVariable name="LOCAL" value="true" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
当我运行dotnet publish
时,如何配置我的解决方案或.vscode .json
文件以进行此更改?
2条答案
按热度按时间ibps3vxo1#
1)您可以使用以下命令在发布时添加环境变量:
2)在发布配置文件中添加环境变量
3)修改项目文件(.csProj)文件
引用链接:
Publish to IIS, setting Environment Variable
how to set ASPNETCORE_ENVIRONMENT to be considered for publishing an asp.net core application?
lf5gs5x22#
如果要执行的操作不只是设置
EnvironmentName
:在使用
"Microsoft.NET.Sdk.Web"
目标的项目上,将应用配置转换。在项目文件夹中添加一个
web.{CONFIGURATION}.config
:然后,在运行
dotnet publish -c {CONFIGURATION}
之后,发布输出包含以下自动生成的web.config
(为简洁起见,删除了一些部分):请访问https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-6.0#build-configuration