![](/img/trans.png)
[英]How to include dynamically generated files in Visual Studio's publish profile
[英]How do I set the environment in a Visual Studio generated publish profile
我有2個發布個人資料。 我要制作一個舞台,制作一個。 瀏覽了一下之后,我發現您可以使用命令行發布來設置環境變量: dotnet publish /p:Configuration=Release /p:EnvironmentName=Staging
。 但是我的發布配置文件是由Visual Studio生成的,我想知道是否可以在其中設置它?
盡管我沒有在.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的環境變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.