Is it possible to have App.config transforms for an Azure WebJob for different publish profiles?
Asked Answered
J

2

19

Where I work, we create Azure web sites and SQL databases for development purposes as needed as well as for staging and production environments. We create a web.config transform for each publish profile to change the database connection string to the database associated with that web site.

Now, I am trying to create an Azure WebJob that will need to make updates to a database. I create it by right-clicking on a web app project and selecting to Add a new Azure WebJob.

What I need to get this to do what I need it to is the SQL Database connection string that points to the same database the Web App is using. I know that these can be set in the Azure portal and grabbed with the configuration manager, but I would rather be able to have it in the App.config of the WebJob and transform the App.config as needed.

I tried using Slow Cheetah for this, but it seems that you can only have a transform for Debug and Release configurations.

I started going through the steps specified in this blog: http://gunnarpeipman.com/2013/11/using-web-config-transforms-with-app-config-files/

It tells you how to manually edit the .csproj file to enable App.config transforms. However, this is not a better solution, because you would have to go manually edit the project file for every transform you need.

Can anyone tell me how to accomplish this? Is it even possible? OR is there a way to share the values in my web app's web.config file that I know will be transformed to what I need them to be?

Jeffcott answered 22/1, 2015 at 16:1 Comment(3)
Are you using a CI environment? If so, you could create multiple build configurations (e.g. Dev, Staging) and create a script that runs on every build to modify whatever you want from the App.config file. If you need more info, let me know and i'll post a complete answerAudie
We are not using a CI environment yet. That is coming soon. This is a pretty good idea, but we found another solution for what I needed. I realized that I don't need transforms at all. An Azure webjob has the website name in ConfigurationManager.AppSettings. So, we put connection strings in the app.config for each website as needed and then select the correct one based off of the website name. Thank you for taking some time out of your day to help me out!Jeffcott
Is it not possible to create more configurations in Configuration Manager? I've created multiple 'release' configurations before for web apps with the sole purpose of being able to use config transforms to publish the same application with different branding and connection strings on publish.Overspend
C
8

As @binard suggested, Slow Cheetah is a great way to create web.config or app.config transforms. Once you create the transforms, you can also Preview the transforms for a specific configuration.

My preferred way is to create custom configurations e.g. Dev and Prod and using the "Slow Cheetah XML Transforms" extension create the transforms for Dev and Prod apart from Debug and Release.

Once this step is complete, the next challenge is to make sure the correct configuration is picked up by the Continuous deployment setup in Azure. For doing this, you must setup the configuration that is associated with your Azure Web App in the "Application Settings" section in the Azure Portal. Example:

SCM_BUILD_ARGS=-p:Configuration=Dev

Once this is setup, all the webjobs under this Web App in Azure will pickup the transforms for the configuration specified in the parent Web App.

Changeup answered 12/1, 2016 at 23:11 Comment(0)
M
3

You can use SlowCheetah. It's an extension for visual studio that add transforms possibilities on App.config => https://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

Marisolmarissa answered 10/11, 2015 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.