[英]How to create a F# Azure Functions (v1 & v2) Project in Visual Studio 2017?
I want to easily create a F# Azure Functions (v2) Project in Visual Studio 2017. 我想在Visual Studio 2017中轻松创建F#Azure Functions(v2)项目。
Is there some ZIP file with a Template F# project that I can use and publish using Visual Studio Publish context menu? 是否有一些带有Template F#项目的ZIP文件,我可以使用Visual Studio Publish上下文菜单进行发布?
I would like that VS has a F# Azure Function Project template, like it has for C#. 我希望VS有一个F#Azure Function Project模板,就像它对C#一样。
Azure Functions templates for F# are missing, which means lack of possibility to create F# precompiled projects in Visual Studio and Functions CLI. 缺少F#的Azure Functions模板,这意味着无法在Visual Studio和Functions CLI中创建F#预编译项目。
There is an open github issue to introduce such support. 有一个开放的github问题来介绍这种支持。 Even though it's not apparent from this issue, I was told that templates are coming very soon.
即使从这个问题不明显,我被告知模板即将推出。
For now, you need to: 目前,您需要:
You could use this sample as a starting point, but be sure to update to latest versions of NuGet packages. 您可以使用此示例作为起点,但请务必更新到最新版本的NuGet包。
For me, I had to go through converting a C# function project into F#: 对我来说,我不得不将C#函数项目转换为F#:
.csproj
to .fsproj
.csproj
重命名为.fsproj
.fsproj
file and make sure the following items are in there: .fsproj
文件并确保其中包含以下项目: <PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
</ItemGroup>
<ItemGroup>
<Compile Include="Function1.fs" />
<Content Include="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
</ItemGroup>
Make sure you set host.json
and local.settings.json
to <Content...
instead of <None...
so it copies it to the output file. 确保将
host.json
和local.settings.json
设置为<Content...
而不是<None...
因此将其复制到输出文件。
Microsoft.NET.Sdk.Functions
installed Microsoft.NET.Sdk.Functions
Function1.fs
file should look something like that (for an HttpTrigger
) Function1.fs
文件看起来应该是这样的(对于HttpTrigger
) namespace FunctionApp1
open System
open Microsoft.Azure.WebJobs
open Microsoft.Azure.WebJobs.Host
open System;
open System.IO;
open System.Threading.Tasks;
open Microsoft.AspNetCore.Mvc;
open Microsoft.Azure.WebJobs;
open Microsoft.Azure.WebJobs.Extensions.Http;
open Microsoft.AspNetCore.Http;
open Microsoft.Extensions.Logging;
module Function1 =
[<FunctionName("Function1")>]
let Run ([<HttpTrigger(AuthorizationLevel.Function, [|"post"|])>] req: HttpRequest) (log: ILogger) =
async {
return "some result"
}
|> Async.StartAsTask
Publish...
Publish...
Azure Function App
and follow the instructions. Azure Function App
并按照说明操作。 Make sure to select Run from pakcage file
. Run from pakcage file
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.