简体   繁体   中英

How to deploy Azure WebJob using different configurations for different environments in Visual Studio

We have several Web Apps and WebJobs with different configurations for different environment, eg Test and Release.

Each WebJob is deployed to a Web App using "Publish as Azure WebJob" in Visual Studio.

We are using the Config Transform extension to transform the App.config that consist of different config sections, connection strings and app settings that needs to be transformed. This works fine for local Debug and for Release.

The problem is that when we use "Publish as Azure WebJob" there is no way to specify which configuration to use and Release is always built and published even if Test is selected inside Visual Studio.

We have also tried to deploy the WebJob together with the Web App but it almost always hangs, same as described in Stuck when publishing Web App to Azure with WebJob

We don't need to use config transform if that's not possible, eg we could configure directly in Azure. But I haven't found a way to configure config sections directly in Azure.

Yes this is a known VS tooling pain point that comes up often. The short answer is that web.config style transforms aren't supported for general application types like Console apps.

This has been discussed recently in the context of WebJobs in our public repo here . That issue also links to the VS User Voice issue for this. That item also links to the SlowCheetah VS extension which some users have said works for them. You might give that a try.

If that doesn't work for you, then you'll have to manually manage your settings via the app settings blade in the Azure portal.

I added a prebuild step to change the webjob-publishing-setting.json file and the app.config file depending on which Configuration is selected.

The webjob-publishing-settings.json only had the name. Then from Visual Studio 2019 I used "Publish as Azure WebJob" and that created a second webjob with the new name and new configuration.

Works great!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM