0
  • dotnet version 2.1.4

Following SO answers such as this, and this I have had no success with the deployed Web.config having the following section generated:

<environmentVariables>
  <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="development" />
</environmentVariables>

Here is my publish command:

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

Here is my publish profile:

<?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>

The publish and deploy is successful and this is the generate Web.config currently:

<?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-->

If I publish from Visual Studio, using the same publish profile the Web.config does have the <environmentVariable> entry:

<?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-->

I have tried variations such as an explicit file path of the publish profile:

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

And also using the startup project instead of the solution file:

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

Here is my 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>
Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
  • Strange. I just tried reproducing this, but with file deploy and I don't see any problems. The env is always set in the web.config. What's up with the build configuration = `development` though? – jpgrassi Apr 11 '19 at 21:21
  • development is the name of my build configuration... – Brian Ogden Apr 11 '19 at 21:24
  • @jpgrassi I switched to Debug build configuration, did not help. What version of dotnet do you have? – Brian Ogden Apr 11 '19 at 21:54
  • Same as yours `2.1.4`. I noted you also run on .NETFX 4.7.2. Tested with that as well, and it works. I haven't tested with WebDeploy but I don't think that's the issue. If you keep the `EnvironmentName` on the `pubxml` file, it ignores the `/p:Configuration=Release`. Also, do you have a `global.json` in your app? Because you might be running with different version of the sdk. How does your `csproj` looks like? – jpgrassi Apr 12 '19 at 07:39
  • I just noticed, you do `dotnet publish Tsl.Submittal.sln`. if you do that it will publish multiple projects, and I'm not sure it will actually use the publish profile correctly. Just as a test, can you publish against a `csproj` instead? – jpgrassi Apr 12 '19 at 07:50
  • @jpgrassi ok I tried dotnet publish src/Tsl.Submittal/Tsl.Submittal.csproj no difference. I do not have a global.json in the solution, I have added the csproj to my question – Brian Ogden Apr 12 '19 at 17:05
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/191751/discussion-between-jpgrassi-and-brian-ogden). – jpgrassi Apr 12 '19 at 17:10

0 Answers0