在诸如this和this之类的SO答案之后,我对部署的Web.config生成以下部分却没有成功:
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="development" />
</environmentVariables>
这是我的发布命令:
dotnet publish Tsl.Submittal.sln -v m /p:PublishProfile="Properties\PublishProfiles\SubmittalService - development.pubxml" /p:Configuration=Debug /p:AllowUntrustedCertificate=True /p:Password=***** /p:EnvironmentName=development
这是我的发布个人资料:
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>http://MyServer:80/WebSvcs/SubmittalService</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<ProjectGuid>9f9bb353-9ef3-4991-ad64-e4e9961ffa7f</ProjectGuid>
<MSDeployServiceURL>https://MyServer:8172/msdeploy.axd</MSDeployServiceURL>
<DeployIisAppPath>Default Website/WebSvcs/SubmittalService</DeployIisAppPath>
<RemoteSitePhysicalPath />
<SkipExtraFilesOnServer>False</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<EnableMSDeployBackup>True</EnableMSDeployBackup>
<UserName>deployUser</UserName>
<_SavePWD>True</_SavePWD>
<TargetFramework>net472</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
<EnvironmentName>development</EnvironmentName>
</PropertyGroup>
</Project>
发布和部署成功,这是当前生成的Web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Tsl.Submittal.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: 9f9bb353-9ef3-4991-ad64-e4e9961ffa7f-->
如果我是从Visual Studio发布的,则使用相同的发布配置文件,Web.config确实具有<environmentVariable>
条目:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Tsl.Submittal.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 9f9bb353-9ef3-4991-ad64-e4e9961ffa7f-->
我尝试了各种变化,例如发布配置文件的显式文件路径:
dotnet publish Tsl.Submittal.sln -v m /p:PublishProfile="src/Tsl.Submittal/Properties/PublishProfiles/SubmittalService - staging.pubxml" /p:Configuration=Release /p:AllowUntrustedCertificate=True /p:Password=**** /p:EnvironmentName=staging
并使用启动项目代替解决方案文件:
dotnet publish src/Tsl.Submittal/Tsl.Submittal.csproj -v m /p:PublishProfile="src/Tsl.Submittal/Properties/PublishProfiles/SubmittalService - staging.pubxml" /p:Configuration=Release /p:AllowUntrustedCertificate=True /p:Password=**** /p:EnvironmentName=staging
这是我的csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<Configurations>Debug;Release;development;staging;production</Configurations>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Any CPU'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Any CPU'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='development|Any CPU'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='staging|Any CPU'">
<PlatformTarget>x64</PlatformTarget>
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
<PackageReference Include="MSBuild.Microsoft.VisualStudio.Web.targets" Version="14.0.0.3" />
<PackageReference Include="ServiceStack.Core" Version="5.4.1" />
<PackageReference Include="ServiceStack.Admin.Core" Version="5.4.1" />
<PackageReference Include="ServiceStack.Api.OpenApi.Core" Version="5.4.1" />
<PackageReference Include="Tsl.Framework.Helpers" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tsl.Submittal.Data\Tsl.Submittal.Data.csproj" />
<ProjectReference Include="..\Tsl.Submittal.Interfaces\Tsl.Submittal.Interfaces.csproj" />
<ProjectReference Include="..\Tsl.Submittal.Model\Tsl.Submittal.Model.csproj" />
<ProjectReference Include="..\Tsl.Submittal.Service.Facade\Tsl.Submittal.Service.Facade.csproj" />
<ProjectReference Include="..\Tsl.Submittal.Service\Tsl.Submittal.Service.csproj" />
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1staging_1json__JSONSchema="" /></VisualStudio></ProjectExtensions>
</Project>