When I use Windows Azure configuration settings, each time I publish an update to my cloud service, the settings are overwritten with the default from my project. This seems rather pointless to me, since if I want to override the default settings in the cloud, it makes sense that I want to preserve those overrides even when publishing an update to the app's code. Is there a way to preserve the settings when publishing from Visual Studio?
NO - A redeploy of your service will override all the settings to whatever is set in the config file (.cscfg) that you provide. To preserve the settings you have to update both, the configuration file in the cloud and the configuration file on your local disk.
Yes - create a local ServiceConfiguration.cscfg (the default) and a cloud or prod configuration ServiceConfiguration.Cloud.cscfg. Right click The cloud project and then "Manage Configurations" to add a new cscfg file. In your publish settings, then specify "Cloud" as your service configuration.
But, if you are asking if you are asking if you can update the Azure Role without uploading settings, then NO - you have to upload a Service configuration file.
Related
I have Azure functions with configs (database connection strings, active directory, etc) set up for dev and live environments, right now I have everything in a class and I comment in/out the bits I'm using or not using.
Is there a way to upload a json file with the azure functions that will guide its config?
You mention "upload a json file" so I'm assuming that you're referring to some sort of release management activity. My suggestion is to simply use the built in AppSettings. Your use case is essentially what they are built for. Generally speaking if you store your settings within the appsettings of a function app and you have separate environments for your functions (dev & live) then you don't need to manage a separate json configuration file. The environment owns the configuration and your code will get the settings from the current environment.
If you have a more complex deployment and configuration management scenario I would consider using a release management tool such as VSTS to manage those configuration settings as part of the release pipeline so each environment has the correct settings at deployment time. Most CI\CD tools have functionality to update json configuration and\or update Azure App configuration directly.
Yes. You need to add connection strings as Application Settings. Azure Functions Core Tools uses local.settings.json file to read your connection strings when running locally and these settings are not pushed to Azure when published.
I do realize I can use Azure AppSettings to override settings in Web.Config files.
https://learn.microsoft.com/en-us/azure/app-service/web-sites-staged-publishing says:
App settings (can be configured to stick to a slot)
Connection strings (can be configured to stick to a slot)
So far so good.
But how do I version these settings?
I don't want to add them manually through the Azure Portal.
Also I don't exactly understand why I can add custom application settings in the Azure App Service release pipeline task. These settings are then copied to the configured slot. Consider following scenario...
There is a new appsetting (which would usually live in Web.Config).
Okay Web.Config is not a good idea because it is specific per deployment slot. So you add it to the release task configuration - for your "staging" slot.
Next you swap staging and production - and of course the new production system has no clue about the new setting (not even the staging configuration which would anyway be equally bad).
In the "on premise" world, when creating an application like a Windows Service I'd classically use an App.config file to store a variety of configuration information about the application, from database connection strings to WCF endpoint information.
In the Azure Worker Role world, I am now presented with .cscfg files which are said to contain information "for the role".
I don't understand whether these files are there to supplement the configuration of the application, or replace App.config files entirely. How do these two files work to configure Azure Worker roles?
Very Basic Explanation:
Conceptually they're the same. In a traditional application, you use app.config file to define various settings related to the application (in appSettings section). Similarly, you use cscfg file to define various settings related to your cloud application (in ConfigurationSettings section). Like app.config file, you get to define other things (e.g. number of instances of your cloud application) in the cscfg file.
If you want, you can still define some of the settings in app.config file but one thing to keep in mind is that app.config file gets "packaged" and deployed and in order to change the settings, you would have to repackage your application and deploy it. However you could change the settings in a cscfg file on the fly using either the portal or Service Management API without having to repackage and redeploy the application. For example consider the scenario where you're defining the database connection string in settings file. If you specify that in app.config, in order to change it you would need to make change in app.config file --> Build the application --> publish the application. Where as in case of a cscfg file, you would just change this value in the portal.
For Web/Worker Roles the traditional configuration files (app/web.config) will keep working like they do on an on-premises deployment. But it's important to know that this file is included in the Service Package, meaning it's part of the deployment.
This means you can't change the settings you have in your app/web.config without redeploying your application. The ServiceConfiguration.cscfg on the other hand is something which is defined at Cloud Service deployment slot level, next to the actual Service Package. This means you can change this configuration file without having to redeploy your application. These settings can also be accessed from your application by calling RoleEnvironment.GetConfigurationSettingValue (similar to ConfigurationManager.AppSettings).
If you consider building an application that works both on-premises and in Windows Azure, consider using the Microsoft.WindowsAzure.ConfigurationManager package. Which automatically chooses the cscfg or app/web.config based on where your application runs.
Tip: By subscribing to the RoleEnvironment.Changing/Changed event you can intercept changes to this configuration file. You can handle this to update the web.config in code for example (explained here).
I have an single Azure Web Role CSPKG with multiple CSCFG files for different customers.
When I deploy a new version I need to specify both which package and configuration file to use.
But sometimes there are changes made in the Azure portal that not have been changed in source cscfg files. (Ex: custom logging levels, etc).
Is there any way I can upgrade an existing instance without overwriting existing settings in Azure. (Of course the scheme needs to be the same).
That's pretty easy to do:
Create a console application which gets the current properties from the Service Management API (Get Hosted Service Properties with embed-detail=true, look for the ExtendedProperties element).
Have it update your local CSCFG file
Deploy the CSPKG and the updated CSCFG file
I have configured my application to use the Service configuration Local in the development settings.
I have two cscfg files (as per default) Cloud and Local. I have added connection strings for Storage that tell it to use a live account in Cloud.cscfg and dev storage for Local.cscfg.
However when I run my project and use the line
var setting = CloudConfigurationManager.GetSetting("StorageConnectionString");
It is using my Cloud configuration and returning my live storage. It is definitely my Cloud cscfg and not something else setting the value as if I change it in Cloud the setting returned changes.
Is this by design? Is there any way to see the logic CloudConfigurationManager is using to select the configuration?
The weird thing was I am sure this was working earlier.
Deleted all compiled versions of projects. Restarted Compute and Development storage services and the issue went away.
Tried deleted all compiled version and restart Emulator many times to no avail.
Found out my setting wasn't right.
So, right click on your Cloud Service project (not the Roles, but the project) and "Properties".
Then go to "Development" tab (from left), and you will see "Service Configuration" setting under "Run/Debug category".
This needs to be Local for Cloud Service project to use Local setting.