Lillvik
Lillvik

Reputation: 405

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, e.g. 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, e.g. we could configure directly in Azure. But I haven't found a way to configure config sections directly in Azure.

Upvotes: 4

Views: 3245

Answers (2)

Magnus Danielson
Magnus Danielson

Reputation: 1

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!

Upvotes: 0

mathewc
mathewc

Reputation: 13558

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.

Upvotes: 2

Related Questions