简体   繁体   English

如何在 Visual Studio 中针对不同环境使用不同配置部署 Azure WebJob

[英]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.我们有几个 Web 应用程序和 WebJobs,它们针对不同的环境进行不同的配置,例如测试和发布。

Each WebJob is deployed to a Web App using "Publish as Azure WebJob" in Visual Studio.每个 WebJob 都使用 Visual Studio 中的“发布为 Azure WebJob”部署到 Web 应用程序。

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.我们正在使用 Config Transform 扩展来转换由不同的配置部分、连接字符串和需要转换的应用程序设置组成的 App.config。 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.问题是,当我们使用“发布为 Azure WebJob”时,无法指定要使用的配置,即使在 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我们还尝试将 WebJob 与 Web 应用程序一起部署,但它几乎总是挂起,与使用 WebJob 将 Web 应用程序发布到 Azure 时卡住中所述相同

We don't need to use config transform if that's not possible, eg we could configure directly in Azure.如果不可能,我们不需要使用配置转换,例如,我们可以直接在 Azure 中进行配置。 But I haven't found a way to configure config sections directly in Azure.但我还没有找到直接在 Azure 中配置配置部分的方法。

Yes this is a known VS tooling pain point that comes up often.是的,这是一个经常出现的已知 VS 工具痛点。 The short answer is that web.config style transforms aren't supported for general application types like Console apps.简短的回答是,控制台应用程序等一般应用程序类型不支持 web.config 样式转换。

This has been discussed recently in the context of WebJobs in our public repo here .最近在我们此处的公共存储库中的 WebJobs 上下文中讨论了这一点。 That issue also links to the VS User Voice issue for this.该问题还链接到VS User Voice 问题 That item also links to the SlowCheetah VS extension which some users have said works for them.该项目还链接到一些用户说对他们有用的SlowCheetah VS 扩展 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.如果这对你不起作用,则你必须通过 Azure 门户中的应用设置边栏选项卡手动管理你的设置。

I added a prebuild step to change the webjob-publishing-setting.json file and the app.config file depending on which Configuration is selected.我添加了一个预构建步骤来根据选择的配置更改 webjob-publishing-setting.json 文件和 app.config 文件。

The webjob-publishing-settings.json only had the name. webjob-publishing-settings.json 只有名称。 Then from Visual Studio 2019 I used "Publish as Azure WebJob" and that created a second webjob with the new name and new configuration.然后在 Visual Studio 2019 中,我使用了“发布为 Azure WebJob”,并使用新名称和新配置创建了第二个 Web 作业。

Works great!效果很好!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Visual Studio:用于配置的不同 DLL - Visual Studio: Different DLLs for configurations CMake:如何为Visual Studio的不同构建配置指定不同的步骤? - CMake: how to specify different steps for different build configurations for Visual Studio? 如何在不同的Visual Studio配置中指向正确的DLL? - How to point to the right DLLs in different visual studio configurations? 使用VSTS部署Azure WebJob - Deploy Azure WebJob using VSTS 如何在项目中使用不同的文件以用于不同的构建配置 - Visual Studio C#.net - How to use different files in a project for different build configurations - Visual Studio C# .net 如何为不同的构建配置部署不同版本的文件? - How to deploy different version of file for different build configurations? 在 Visual Studio 2019 中根据配置使用不同的 assemblyNames 进行调试 - Debugging in Visual Studio 2019 with different assemblyNames based on configurations 在多项目Visual Studio解决方案中以不同配置编译项目 - Compiling projects in different configurations in a multi-projects Visual Studio Solution 如何使用 Visual Studio Online 在 Azure VM 中部署 Web 应用程序 - How deploy Web application in Azure VM using Visual studio online 如何使用Visual Code Studio在Azure上部署静态网站? - How to deploy a static website on azure using Visual Code studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM