Reputation: 2374
I want to publish a specific appsettings json in my publish folder.
In my .csproj file, I have this
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</None>
<None Update="appsettings.Staging.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Settings.job">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
I have two publishing profiles (local/Azure).
In my local folder, everything works fine
But the when I publish on Azure I am not able to get the correct file:
What am I doing wrong?
MORE INFO:
Azure env settings:
File property in the project:
Upvotes: 1
Views: 2410
Reputation: 2522
ASP.NET Core configures app behavior based on the runtime environment using an environment variable.
To determine the runtime environment, ASP.NET Core reads from the following environment variables:
DOTNET_ENVIRONMENT
ASPNETCORE_ENVIRONMENT
when ConfigureWebHostDefaults is called.The default ASP.NET Core web app templates call
ConfigureWebHostDefaults. The ASPNETCORE_ENVIRONMENT
value
overrides DOTNET_ENVIRONMENT
.
EnvironmentName can be set to any value, but the following values are provided by the framework:
ASPNETCORE_ENVIRONMENT
to Development on the local machine.DOTNET_ENVIRONMENT
and ASPNETCORE_ENVIRONMENT
have not been set.The environment for local machine development can be set in the Properties\launchSettings.json file of the project. Environment values set in launchSettings.json override values set in the system environment.
The launchSettings.json file can contain multiple profiles
Apps deployed to azure are Production by default.
Production is the default value if DOTNET_ENVIRONMENT
and ASPNETCORE_ENVIRONMENT
have not been set.
When you publish your app you can override the environment on the host OS using an environment variable. When .NET Core starts your published app it will read that variables and load the appropriate appsettings.{environment}.json file. If the value is not set, or no file exists for that environment, then the settings in appsettings.json will apply.
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.1
How to use publish profile to change a value is appsettings.json
Upvotes: 1