如何通过VSC将PowerShell api部署到Azure Functions? [英] How can one deploy a PowerShell api to Azure Functions thru VSC?

查看:110
本文介绍了如何通过VSC将PowerShell api部署到Azure Functions?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将Powershell api部署到Azure Functions. 官方文档仅讨论部署JavaScript函数.

How can one deploy a Powershell api to Azure Functions. The official documentation only talks about deploying a JavaScript function.

在通过Azure Functions扩展创建项目"时,在选择语言时没有选择"Powershell"的选项.

One doesn't get an option to select 'Powershell' during language selection while creating a 'Project' thru the Azure Functions extension.

这是从Azure门户部署时的默认Powershell api.

This is a default Powershell api when deployed from the Azure Portal.

# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$name = $requestBody.name
# GET method: each querystring parameter is its own variable
if ($req_query_name) 
  {$name = $req_query_name}
Out-File -Encoding Ascii -FilePath $res -inputObject "Hello $name"

我尝试使用VSC Azure函数的部署"按钮直接部署以下代码.但是我得到以下错误.

I tried to deploy the below code directly using the VSC Azure Function's 'Deploy' button. But I get the below error.

Unable to write Workspace settings because no workspace is opened. Please open a workspace first and try again

推荐答案

由于未打开任何工作区,因此无法写入工作区设置.请先打开工作区,然后重试.

Unable to write Workspace settings because no workspace is opened. Please open a workspace first and try again.

在VSCode中,我们必须先打开一个文件夹或创建一个功能项目,否则将无法创建用于保存工作区设置的文件,并且在尝试修改工作区设置(如运行时,语言和模板)时会出现错误过滤器.

In VSCode, we have to open a folder or create a function project first, or the file to hold Workspace settings can't be created, and we will get the error when trying to modify Workspace settings like runtime, language and template filter.

在VSCode中开发Azure功能的详细步骤(参考官方教程):

Detailed Steps of Developing Azure Function in VSCode(references from official tutorial):

提示

  1. 类似于Powershell的语言是实验性的,因此请勿在生产中使用它们. Powershell /

  1. Languages like Powershell are experimental so don't use them in production. Powershell/Python support on 2.x runtime are also in progress.

将函数核心工具(cli)安装到本地调试功能.

Install functions core tools(cli) to debug functions locally.

对于Windows Windows .NET Framework是1.x,对于跨平台.NET Core是2.x.

1.x for OS Windows .NET Framework, 2.x for cross platform .NET Core.

安装Azure功能扩展

在浏览器中输入vscode:extension/ms-azuretools.vscode-azurefunctions,它将打开VScode并安装扩展.

Input vscode:extension/ms-azuretools.vscode-azurefunctions in brower, it will open VScode and install extensions.

创建功能项目

  1. 在文件资源管理器中创建一个空文件夹;说MyFunctionApp

登录到Azure帐户.

Log into Azure Account.

在Azure Function Extension中,单击Create New Project并指向创建的文件夹MyFunctionApp.

In Azure Function Extension, Click Create New Project and point to created folder MyFunctionApp.

选择语言JavaScript

Select language JavaScript

创建功能

  1. 单击Create Function并浏览器MyFunctionApp文件夹.然后,您可能会看到如下所示的下拉菜单.项目运行时是根据安装的cli自动设置的.

  1. Click Create Function and browser MyFunctionApp folder. Then you may see the dropdown menu as below. Project runtime is automatically set based on cli installed.

单击Change template filter并将其更改为All,以便我们可以看到所有可用模板.

Click Change template filter and change it to All so that we can see all templates available.

点击Change project language选择实验语言,例如Powershell.

Click Change project language to select experiment language like Powershell.

按照其余提示创建Http触发器.

Follow the rest prompt to create an Http trigger.

在本地调试或运行功能

对于C#,JavaScript和Java,请随意F5.

For c#, javascript and java, feel free to F5.

要在本地运行实验语言的功能,请在VSCode(Ctrl +`)中打开终端并运行func host start,没有调试支持,因此请不要使用F5.

To run function in experimental language locally, open terminal in VSCode(Ctrl+`) and run func host start, no debug support so don't use F5.

要测试httptrigger,请在后缀函数url后面加上?name=World!,以从您的URL获取Hello World响应.

To test a httptrigger, suffix function url with ?name=World! to get Hello World response from your URL.

部署

单击Deploy to Function App按钮并按照提示进行操作.

Click Deploy to Function App button and follow the prompt.

这篇关于如何通过VSC将PowerShell api部署到Azure Functions?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆