So when I run the publish command there was only the right appsettings file. This did not work because on IIS it is looking for appsettings.json and that is required.
So I included both and they are there in the published file set.
I then tested and edited the appsettings.json in the IIS folder with the wrong database and recycling the app pool I found the appsettings.json is always read. So how do I get different build's to have the different settings?
This is my understanding of how it works (I may be wrong)
When you Publish your site from VS, there is a setting for configuration, it uses this value to determine what gets written to the appsettings.json file.
So, if you have an appsettings.Staging.json file and you want these values to be used, te configuration setting for the publish should be set to 'staging' then when you publish, any settings that are in appsettings.staging will overwrite/replace any equivalent settings in the appsettings.json which will be used by the app when running
I didn't have to make any manual changes to my csprj for this to work, just added a staging configuration to the 'Solution configurations' settings in VS
I am going through visual studio code and the CLI command but I looked in Visual studio and this did not appear to be the case for me.
You may need to test that for yourself by making a wrong database name in the connection string in that other settings file and doing that. If you see it all still run it is because it is just using the appsetting.json which is what I have been seeing.
I don't use visual studio code, I use visual studio and it works how I described above I tested withe different publish configurations and it worked as expected. I will have a look with VSC over the weekend to see if you need to do anything different, but in VS it is the publishing which combines the different settings files into the published appsettings.json that will be used when the site is run.
Once you have done that, IIS should load your appsettings.Staging.json file
The default JsonConfigurationProvider loads configuration in the
following order:
appsettings.json
appsettings.{Environment}.json : For example, the
appsettings.Production.json and appsettings.Development.json files.
The environment version of the file is loaded based on the
IHostingEnvironment.EnvironmentName. For more information, see Use
multiple environments in ASP.NET Core. appsettings.{Environment}.json
values override keys in appsettings.json. For example, by default:
In development, appsettings.Development.json configuration overwrites
values found in appsettings.json. In production,
appsettings.Production.json configuration overwrites values found in
appsettings.json. For example, when deploying the app to Azure.
Help needed - Environment setup
Hi All, I am trying to work out the setup to build to run on a staging server vs local development and a production server.
The Staging server will have a different database (SQL Server) connection to a Production server.
I have a an appsettings.json and.. appsettings.Staging.json appsettings.Production.json With a different connection string in other two files.
I learned in the csproj file you can add the following code...
So when I run the publish command there was only the right appsettings file. This did not work because on IIS it is looking for appsettings.json and that is required.
So I included both and they are there in the published file set. I then tested and edited the appsettings.json in the IIS folder with the wrong database and recycling the app pool I found the appsettings.json is always read. So how do I get different build's to have the different settings?
JSON example..
Can anyone help?
The goal:
I think I am close? There were a few things for .net7 but they are not how Umbraco setup and running on those guides kills Umbraco.
Hi Liam,
This is my understanding of how it works (I may be wrong)
When you Publish your site from VS, there is a setting for configuration, it uses this value to determine what gets written to the appsettings.json file.
So, if you have an appsettings.Staging.json file and you want these values to be used, te configuration setting for the publish should be set to 'staging' then when you publish, any settings that are in appsettings.staging will overwrite/replace any equivalent settings in the appsettings.json which will be used by the app when running
I didn't have to make any manual changes to my csprj for this to work, just added a staging configuration to the 'Solution configurations' settings in VS
I am going through visual studio code and the CLI command but I looked in Visual studio and this did not appear to be the case for me.
You may need to test that for yourself by making a wrong database name in the connection string in that other settings file and doing that. If you see it all still run it is because it is just using the appsetting.json which is what I have been seeing.
I don't use visual studio code, I use visual studio and it works how I described above I tested withe different publish configurations and it worked as expected. I will have a look with VSC over the weekend to see if you need to do anything different, but in VS it is the publishing which combines the different settings files into the published appsettings.json that will be used when the site is run.
It would seem that using the command line and VSC it behaves differently than publishing from VS, odd, I would have expected it to behave the same.
Hi Liam,
From doing some research, I believe this is what you need to do.
On your webserver website you need to set the aspnet core environment variable to Staging
see here for info https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-7.0
Once you have done that, IIS should load your appsettings.Staging.json file
is working on a reply...