dotnet / dotnet/core

.net core 3.1 worker service - set EnvironmentName on publish

Open
#4,412 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
PowerShell
Stars
22k
Forks
4.9k
Avg merge
5d 5h
Merged PRs (30d)
29

Description

# Issue Title

Hello !
I'm trying to setup a worker service using the asp.net core 3.1 template provided by VS 2019 Enterprise.

# General

Steps to reproduce : Create a new project and run it : "Hosting Environment: Development", works as expected.

![image](https://user-images.githubusercontent.com/6016692/76968902-f13b6a80-6929-11ea-92ed-76e618158b1d.png)

Create a FileSystem publish profile, and add `Test` to publish the worker to a testing environment for exemple

![image](https://user-images.githubusercontent.com/6016692/76969279-77f04780-692a-11ea-8885-25f74f8ed022.png)

When launching the published version, HostingEnvironment is set to "Production", but i defined "Test" in the FolderProfile.pubxml

![image](https://user-images.githubusercontent.com/6016692/76970655-7b84ce00-692c-11ea-9496-20a04ff7e95e.png)

Is this a bug ? Or you don't publish worker services on another environments this way ?

I've also tried `dotnet publish /p:EnvironmentName=Test`, without success.

I also tried to generate manually a web.config file, containing

``, the worker service seems to ignore the web.config file.

Cannot run my application on custom environment, like Test or Staging !

PS : Works in Debug into VS, setting `DOTNET_ENVIRONMENT = Test` Environment variable

![image](https://user-images.githubusercontent.com/6016692/76970876-c6064a80-692c-11ea-9807-5003db6cb27d.png)

Thanks in advance

Edit : The final goal is to host this worker on a Windows Server 2012 R2 as a windows service (and managing different environments), `using Microsoft.Extensions.Hosting.WindowsServices, Version=3.1.1.0`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.