I'm trying to setup a worker service using the asp.net core 3.1 template provided by VS 2019 Enterprise. So far:
1 / Created a new project and ran it: "Hosting Environment: Development", works as expected.
Development
2 / Created a FileSystem publish profile, and added <EnvironmentName>Test</EnvironmentName>
to publish the worker to a testing environment for exemple
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishProtocol>FileSystem</PublishProtocol>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PublishDir>bin\Release\netcoreapp3.1\publish\</PublishDir>
<EnvironmentName>Test</EnvironmentName>
</PropertyGroup>
</Project>
When launching the published version, HostingEnvironment is set to "Production", but i defined "Test" in the FolderProfile.pubxml
Production
I've tried dotnet publish /p:EnvironmentName=Test
, without success.
I also tried to generate manually a web.config file, containing
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Test" />
The worker service seems to ignore the web.config file.
It works on VS while debugging, having DOTNET_ENVIRONMENT = Test
Test
What's the correct way to publish worker services on different environments ?
Microsoft.Extensions.Hosting.WindowsServices, Version=3.1.1.0
. This approach (having several publication profiles and modifying them for several environments) works for classic ASP.NET Core app's which are hosted on IIS, which uses ASPNETCORE_ENVIRONMENT. The worker service template uses DOTNET_ENVIRONMENT, i'm not sure how to modify and manage that. – Karuskrokro