Ang*_*ker 1 asp.net-core-mvc asp.net-core
我有几个 WebDeploy 发布配置文件,可将我的 .NET Core Web 项目部署到各个位置(Dev、QA、IIS 上的阶段)。为了让应用程序知道它在哪里运行,我需要设置 ASPNETCORE_ENVIRONMENT 环境变量。
是否可以将 ASPNETCORE_ENVIRONMENT 环境变量设置为发布应用程序的一部分?
PS 这个问题对我来说没有解决任何问题,因为它显示了如何手动实现它。我希望它作为部署发布配置文件的一部分是自动的。
您可以使用以下文本更新您的webconfig文件 部分。
<configuration>
<system.webServer>
<aspNetCore .....>
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)
或者您可以在 IIS 中托管您的应用程序后执行以下步骤。
步骤1: 点击配置编辑器,如下图所示
第2步 :
现在选择system.webserver/asp.netcore并在其他下拉列表中选择如下图所示的applicationHost.config。
第 3 步:
现在选择环境变量并输入值。
我希望它可以帮助你。
Tao*_*hou -1
要发布web.config特定环境,您可以尝试Transform web.config。
对于你的要求,你可以尝试一下Profile。
使用不同的环境变量创建多个 web.{profile}.config ASPNETCORE_ENVIRONMENT。
例如。web.Dev.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<aspNetCore>
<environmentVariables xdt:Transform="InsertIfMissing">
<environmentVariable name="ASPNETCORE_ENVIRONMENT"
value="Dev"
xdt:Locator="Match(name)"
xdt:Transform="InsertIfMissing" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Run Code Online (Sandbox Code Playgroud)
例如。web.Release.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<aspNetCore>
<environmentVariables xdt:Transform="InsertIfMissing">
<environmentVariable name="ASPNETCORE_ENVIRONMENT"
value="Release"
xdt:Locator="Match(name)"
xdt:Transform="InsertIfMissing" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Run Code Online (Sandbox Code Playgroud)使用特定名称创建项目配置文件,例如Dev和Release,您可以使用现有配置文件名称创建 web.{profile}.config 。
发布后会将具体内容复制web.{profile}.config到web.config中
web.config目前,它将存在web.Dev.config于web.Release.config您的 publihshed 文件夹中,如果您愿意web.config,请更改Project.csproj如下内容以排除不需要的文件。
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<Configurations>Debug;Release;Dev</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Content Update="web.Dev.config" CopyToPublishDirectory="Never" />
<Content Update="web.Release.config" CopyToPublishDirectory="Never" />
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
6823 次 |
| 最近记录: |