我正在尝试配置ASP.NET Core项目发布配置文件以部署到暂存环境.在服务器上设置了预配置的ASPNETCORE_ENVIRONMENT变量,但是无论我尝试使用什么Visual Studio都会不断将ASPNETCORE_ENVIRONMENT变量定义添加到发布web.config文件中.消除它的唯一方法是从launchSettings.json中删除.
I'm trying to configure ASP.NET Core project publication profile for deployment to staging environment. There's preconfigured ASPNETCORE_ENVIRONMENT variable set on server, but whatever I try Visual Studio keeps adding ASPNETCORE_ENVIRONMENT variable definition to publishing web.config file. The only way to eliminate it is to delete from launchSettings.json.
这会导致几个问题:
我找不到控制此行为的任何设置.有吗?
I could not find any setting that controls this behaviour. Is there any?
这是我的.pubxml
This is my .pubxml
<Project ToolsVersion="4.0" xmlns="schemas.microsoft/developer/msbuild/2003"> <PropertyGroup> <WebPublishMethod>MSDeploy</WebPublishMethod> <LastUsedBuildConfiguration>Release.Main</LastUsedBuildConfiguration> <LastUsedPlatform>Any CPU</LastUsedPlatform> <SiteUrlToLaunchAfterPublish /> <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish> <ExcludeApp_Data>False</ExcludeApp_Data> <TargetFramework>netcoreapp2.2</TargetFramework> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <ProjectGuid>433bb565-5e85-4f1a-9dd4-a7f437fdb534</ProjectGuid> <SelfContained>false</SelfContained> <_IsPortable>true</_IsPortable> <MSDeployServiceURL>192.168.0.22</MSDeployServiceURL> <DeployIisAppPath>auth/main</DeployIisAppPath> <RemoteSitePhysicalPath /> <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer> <MSDeployPublishMethod>RemoteAgent</MSDeployPublishMethod> <EnableMSDeployBackup>True</EnableMSDeployBackup> <_SavePWD>False</_SavePWD> </PropertyGroup> </Project>launchSettings.json
launchSettings.json
{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iis": { "applicationUrl": "localhost/DocShellWeb.Sts", "sslPort": 0 } }, "profiles": { "DocShellWeb.Sts": { "commandName": "IIS", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }部署的web.config
Deployed 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="..." arguments="..." stdoutLogEnabled="false" hostingModel="InProcess" stdoutLogFile=".\logs\stdout"> <environmentVariables> <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> </environmentVariables> </aspNetCore> </system.webServer> </location> </configuration> <!--ProjectGuid: 706412a5-be0d-452d-a9b0-ce00d799f990--> 推荐答案仅在调试期间以及通过 dotnet run运行应用程序时,Visual Studio才会使用 launchSettings.json 文件.代码>.发布时根本不使用它,甚至不考虑使用它.如果要在发布时指定特定的环境,则需要将添加< EnvironmentName> Staging</EnvironmentName> 添加到 pubxml 文件:
The launchSettings.json file is only used by Visual Studio during debugging and when running the app via dotnet run. It is not used at all or even considered when publishing. If you want to specify a particular environment when you publish, then you need to add add <EnvironmentName>Staging</EnvironmentName> to the pubxml file:
<Project ToolsVersion="4.0" xmlns="schemas.microsoft/developer/msbuild/2003"> <PropertyGroup> ... <EnvironmentName>Staging</EnvironmentName> </PropertyGroup> </Project>这将为在发布的web.config中为 ASPNETCORE_ENVIRONMENT 设置为 Staging 的环境变量声明添加环境效果.
This will have the effect of adding an environment variable declaration for ASPNETCORE_ENVIRONMENT set to Staging in your published web.config.
但是,这要假定一些条件:
However, that assumes a few things:
更多推荐
Visual Studio在发布过程中使用launchSettings.json配置文件中定义的哪个?
发布评论