简体   繁体   English

在Visual Studio中调试Azure功能

[英]Debugging Azure functions in Visual Studio

I am developing a logic app and hosting there several custom functions. 我正在开发一个逻辑应用程序并托管几个自定义功能。 These are csx files, so it is C# code (script code). 这些是csx文件,因此它是C#代码(脚本代码)。

For now I use only the Azure web frontend to edit the function and testing it. 现在,我只使用Azure Web前端来编辑功能并对其进行测试。 But I think that this is not the best way, because I want have a continuous deployment. 但我认为这不是最好的方法,因为我希望有一个持续的部署。 So I want to use a git repo to store there my code. 所以我想使用git repo存储我的代码。 That the deployment process take to publish the changes. 部署过程用于发布更改。

So is it possible to debug my function locally? 那么可以在本地调试我的功能吗? Maybe with an emulator or s.th.? 也许与模拟器或s.th.?

I tried this link to setup a local environment: https://azure.microsoft.com/da-dk/documentation/articles/functions-run-local/#to-run-locally 我尝试使用此链接来设置本地环境: https//azure.microsoft.com/da-dk/documentation/articles/functions-run-local/#to-run-locally

But I do not know if this is the right way to debugg the functions locally. 但我不知道这是否是在本地调试函数的正确方法。

by the way, is it possible to run a logic app locally too? 顺便说一句,是否可以在本地运行逻辑应用程序?

Check this doc out 检查此文档

It's what I use to develop locally. 这是我用来在本地开发的东西。 Basically after installing the tools you just hit F5 (or Debug) and Visual Studio compiles your functions and sets up a localhost connection for them. 基本上在安装工具之后,只需按F5(或Debug),Visual Studio就会编译您的函数并为它们设置localhost连接。 You can then use a free program like Postman (my personal favorite) to trigger the functions. 然后你可以使用像Postman这样的免费程序(我个人最喜欢的)来触发这些功能。 If you have a breakpoint set, it will then be hit after calling the function. 如果设置了断点,则在调用该函数后将触发该断点。 Once it starts up, you'll eventually see something like this after everything is done: 一旦启动,在完成所有操作后,您最终会看到类似的内容:

在此输入图像描述

Note that it's using http and not https. 请注意,它使用的是http,而不是https。 You can then use Postman or whatever to access the function via the URL listed. 然后,您可以使用Postman或其他任何内容通过列出的URL访问该功能。 Also note that when running locally, it doesn't seem to care if you have your function set to require an admin/function key, nor will it care if it requires authentication. 另请注意,在本地运行时,如果您将功能设置为需要管理员/功能键,它似乎并不在意,如果需要身份验证,它也不关心。

With this set up, I test all my code locally, then when it's done I submit it to source control and then, using the plugin obtained from the link, I publish my functions to Azure. 通过这个设置,我在本地测试我的所有代码,然后当它完成后我将它提交给源代码控制,然后,使用从链接获得的插件,我将我的函数发布到Azure。 In my case, I'm using TFS and not Git so I can't (currently as of this writing) hook it up to Azure's continuous integration. 在我的情况下,我使用TFS而不是Git,所以我不能(目前正在撰写本文)将其与Azure的持续集成联系起来。 Since you're using Git, you won't have to deal with the publish step. 由于您使用的是Git,因此您无需处理发布步骤。

I would say that it depends. 我会说这取决于。 For example, if you'll use blob triggers, you won't be able to test locally, just "mock" that. 例如,如果你将使用blob触发器,你将无法在本地测试,只是“模拟”它。

Here's a useful link from the offical doc: 这是官方文档的有用链接:

https://azure.microsoft.com/en-us/documentation/articles/functions-run-local/ https://azure.microsoft.com/en-us/documentation/articles/functions-run-local/

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

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