When I issue the following command in the command line:
dotnet publish -o \"./../output\" -c Release
The dotnetcli publishes the pr
Discovered a three-step build in Visual Studio approach for publishing environment-specific appsetting files (Windows, PowerShell).
This approach will publish
Step 1. Update csproj:
Step 2. Set an environment variable in PowerShell:
# Read
[Environment]::GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "User")
# Output: empty string if not set or 'Staging' in my case
# Set environment variable "User" or "Machine" level
[Environment]::SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Staging", "User")
Step 3. Then close and reopen Visual Studio solution to enable Visual Studio to see the environment variable and reload project structure accordingly.
Final step. Run publishing.
Note: publishing profile environment variables do not affect publishing configuration. This approach uses PowerShell to set an environment variable and enables environment-specific publishing. Please see link for more details on environment variables.