This doesn't seem to work in a core console app:
dotnet publish myproject.csproj /p:EnvironmentName=MyEnvironment
Is there an alternative for publishing a console app that alters the environment name variable programmatically?
This doesn't seem to work in a core console app:
dotnet publish myproject.csproj /p:EnvironmentName=MyEnvironment
Is there an alternative for publishing a console app that alters the environment name variable programmatically?
Config in ASP.NET Core is entirely externalized. As such there's nothing you can do as part of the build (or therefore publish) that will set the environment. The same code can be published multiple different places, all using different values for environment. In other words, the environment is a function of the destination, not the act of publishing.
As part of a CI/D pipeline, you can easily set environment variables, but importantly, the dotnet publish
command is not a CI/D pipeline. This would mean setting up something in Pipelines in Azure DevOps, for example. Or, if you don't want to go quite that far (though, you really should), you'll want to create a PowerShell script perhaps that will handle publishing and setting environment variables appropriately.