Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 918
Tyler Pohl Avatar asked Jan 22 '15 16:01

Tyler Pohl


People also ask

How do I publish a WebJob?

In Solution Explorer, right-click the project and select Publish. In the Settings section, choose Show all settings. In the Profile settings dialog box, choose Continuous for WebJob Type, and then choose Save. Select Publish in the Publish tab to republish the WebJob with the updated settings.

Can you change a connection string after you deploy your Web application to Azure Web app service?

Configure connection strings. In the Azure portal, search for and select App Services, and then select your app. In the app's left menu, select Configuration > Application settings. For ASP.NET and ASP.NET Core developers, setting connection strings in App Service are like setting them in <connectionStrings> in Web.

How do I change my Azure Web config?

If you want to change web. config files you can use the Azure portal, there is a tool called "App Service Editor" in preview or Kudu that lets you edit any of the files you've deployed.

How do I change my Azure WebJob schedule?

To change the schedule, or to Modify the CRON value just use the App Service Editor to modify the WWWROOT/App_Data/jobs/triggered/YOUR_WEBJOB_NAME/settings. job file; By the time of writing, App Service Editor is still in preview but it will work.


2 Answers

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.

like image 197
Chai Avatar answered Sep 17 '22 14:09

Chai


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

like image 35
binard Avatar answered Sep 18 '22 14:09

binard