ASPNETCORE_ENVIRONMENT не устанавливается в динамически сгенерированном Web.config - PullRequest
0 голосов
/ 11 апреля 2019
  • dotnet версия 2.1.4

После ответов SO, таких как this и this У меня не было успеха с развернутым 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...