我有2个发布个人资料。我要制作一个舞台,制作一个。浏览了一下之后,我发现您可以使用命令行发布来设置环境变量:dotnet publish /p:Configuration=Release /p:EnvironmentName=Staging
。但是我的发布配置文件是由Visual Studio生成的,我想知道是否可以在其中进行设置?
答案 0 :(得分:0)
尽管我没有在.Net Core上尝试过这种方法,但我相信它会起作用,因为它是VS Publish(msbuild)的功能。
您需要创建web.config。像这样:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<remove name="WebDAV" />
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<modules>
<remove name="WebDAVModule" />
</modules>
<aspNetCore requestTimeout="00:30:00" processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
然后您需要为此添加 Config Transform (见下文)
对于配置转换,您可以查看以下github文档:https://github.com/vijayrkn/webconfigtransform/blob/master/README.md
然后,您还需要转换您的发布个人资料。
web.$(publish-profile-name).config
将成为您的web.config名称。您需要分别更改转换后的web.configs的环境变量。