In my old project in Visual Studio, I can have Web.config, and its transform files like Web.Debug.config, Web.Staging.config, Web.Release.config
when I publish to Staging and Production environment, some value will be different between the environment depending on setting in the config in the transform files
what is its equivalency in Umbraco 10?
I read about setting ASPNETCORE_ENVIRONMENT in launchSettings.json, and adding appsettings.Development.json, appsettings.Staging.json and appsettings.Release.json, but I can't seem to connect the dots
In the end, what I want is, for example, when I publish my website to Staging, my website should connect to my Staging database, when I publish website to Production, my website should connect to my Production database. These 2 environments are physically on same server in same IIS.
Can someone point some direction on documents and/or code?
In an Asp.Net Core application you can set the value of the IHostEnvironment.EnvironmentName property. If the value of this property corresponds to the "middle" part of appSettings.{EnvironmentName}.json, then this appsettings file will be merged with the default appSettings.json file.
The most common ways of setting IHostEnvironment.EnvironmentName is
Setting the ASPNETCORE_ENVIRONMENT variable in launchSettings.json in Visual Studio.
Setting the environmentVariable element in web.config.
Setting ASPNETCORE_ENVIRONMENT variable in the host process/op.system environment.
Here's the place to set it in web.config (I have removed some attributes for clarity):
Thanks you very much for your info, I have been reading things similar but I must have missed some key point. Can I confirm one thing at a time ?
On the server, not on my local in Visual Studio,
Is that true that the website is only looking into setting in the appSetting.json?
although I have these files in the folder (appsettings.json, appsettings.Development.json, appsettings.Staging.json, appsettings.production.json)
my website is only reading setting in the appSetting.json
these files in the folder (appsettings.json,
appsettings.Development.json, appsettings.Staging.json,
appsettings.production.json) my website is only reading setting in the
appSetting.json
is this correct? thanks
It depends on the envirnment variables set.
Production is the default value if DOTNETENVIRONMENT and
ASPNETCOREENVIRONMENT have not been set. Apps deployed to Azure are
Production by default.
so if you uploaded all those files to your webserver and have not set variables, then it will do this
Settings can be configured in multiple places. Here are the priorities
used when determining the value of a setting, listed from high (1) to
low (3):
Value within the appsettings.Production.json file
Value within the appsettings.json file
Default value set in the code. Used only if a specific setting can't be found within appsettings.Production.json or appsettings.json.
So by default
appsettings.Development.json, appsettings.Staging.json should be ignored.
One thing you need to be aware of, especially when developing is that settings are replaced individually, so if you add the below for example to appsettings.json
ok great, thank you all for helping, I am starting to get it, on my local, in the launchSettings.json,
when I set
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
I am getting config from the appsettings.Development.json
when I set
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Staging"
}
I am getting config from the appsettings.Staging.json
when I set
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
I am getting config from the appsettings.Production.json
this is exciting, now I am going to see how the publish works.
thanks again
thanks, yes,
what I actually meant when I said "I am getting config from the appsettings.Staging.json" is that "the config in appsettings.Staging.json is replacing the one in the appsettings.json"
web.config Transform equivalency in Umbraco 10
Hi,
In my old project in Visual Studio, I can have Web.config, and its transform files like Web.Debug.config, Web.Staging.config, Web.Release.config when I publish to Staging and Production environment, some value will be different between the environment depending on setting in the config in the transform files
what is its equivalency in Umbraco 10?
I read about setting ASPNETCORE_ENVIRONMENT in launchSettings.json, and adding appsettings.Development.json, appsettings.Staging.json and appsettings.Release.json, but I can't seem to connect the dots
In the end, what I want is, for example, when I publish my website to Staging, my website should connect to my Staging database, when I publish website to Production, my website should connect to my Production database. These 2 environments are physically on same server in same IIS.
Can someone point some direction on documents and/or code?
Many thanks
In an Asp.Net Core application you can set the value of the IHostEnvironment.EnvironmentName property. If the value of this property corresponds to the "middle" part of appSettings.{EnvironmentName}.json, then this appsettings file will be merged with the default appSettings.json file.
The most common ways of setting IHostEnvironment.EnvironmentName is
Here's the place to set it in web.config (I have removed some attributes for clarity):
The Microsoft documentation has the details.
Thanks you very much for your info, I have been reading things similar but I must have missed some key point. Can I confirm one thing at a time ?
On the server, not on my local in Visual Studio, Is that true that the website is only looking into setting in the appSetting.json? although I have these files in the folder (appsettings.json, appsettings.Development.json, appsettings.Staging.json, appsettings.production.json) my website is only reading setting in the appSetting.json
is this correct? thanks
It depends on the envirnment variables set.
so if you uploaded all those files to your webserver and have not set variables, then it will do this
So by default appsettings.Development.json, appsettings.Staging.json should be ignored.
One thing you need to be aware of, especially when developing is that settings are replaced individually, so if you add the below for example to appsettings.json
But add this in your appsettings.Development. json
You will get an error because it will still try to use "StartTls"
appsettings.json should just contain a very basic set of settings.
Got it, thanks
if you want to add ASPNETCORE_ENVIRONMENT to web.config you can do it by adding to publish profile
so, I added the following in the publish profile
then I published to staging website it worked
I can see that config from the appsettings.Staging.json replaced the one in the appsettings.json
Thank you!
ok great, thank you all for helping, I am starting to get it, on my local, in the launchSettings.json, when I set
"IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }
I am getting config from the appsettings.Development.jsonwhen I set
"IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Staging" }
I am getting config from the appsettings.Staging.jsonwhen I set
"IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Production" }
I am getting config from the appsettings.Production.jsonthis is exciting, now I am going to see how the publish works. thanks again
And don't forget, you get the defaults from appSettings.json, with overrides and additions from the Development/Staging/Production json file.
thanks, yes, what I actually meant when I said "I am getting config from the appsettings.Staging.json" is that "the config in appsettings.Staging.json is replacing the one in the appsettings.json"
Thank you all again, my problem is solved!
is working on a reply...