Skip to content

Using the templates directly via dotnet new

Paul Batum edited this page Apr 9, 2018 · 6 revisions

You can create Azure Functions projects and execute individual templates from the command line using dotnet new. Please note that this experience has not received much in the way of polish yet. These templates could use some cleanup from a metadata perspective (we need to make sure they use the right name, tag, etc).

  1. Use the metadata feed to discover and download the appropriate packages. Grab the latest copy of the feed from: https://functionscdn.azureedge.net/public/cli-feed-v3.json

  2. In the tags section, find the entry for "v2" and look up the corresponding release. At time of writing its 2.0.1-beta.25.

  3. Find that release in the releases section, and grab the links for itemTemplates and projectTemplates. Take those links and use them to download the template .nupkg's.

  4. Install the templates using dotnet new -i <packagepath> e.g.

dotnet new -i "D:\downloads\Microsoft.AzureFunctions.ProjectTemplates.2.0.0-beta-10177.nupkg"
dotnet new -i "D:\downloads\Azure.Functions.Templates.2.0.0-beta-10177.nupkg"
  1. If this worked, you should see a bunch of templates tagged with Azure Function when you run dotnew new:
Templates                                         Short Name                          Language          Tags
-------------------------------------------------------------------------------------------------------------------------------
QueueTrigger                                      Queue                               [C#]              Azure Function
HttpTrigger                                       Http                                [C#]              Azure Function
BlobTrigger                                       Blob                                [C#]              Azure Function
TimerTrigger                                      Timer                               [C#]              Azure Function
DurableFunctionsOrchestration                     DurableFunctionsOrchestration       [C#]              Azure Function
SendGrid                                          SendGrid                            [C#]              Azure Function
EventHubTrigger                                   EventHub                            [C#]              Azure Function
ServiceBusQueueTrigger                            SBQueue                             [C#]              Azure Function
ServiceBusTopicTrigger                            SBTopic                             [C#]              Azure Function
EventGridTrigger                                  EventGrid                           [C#]              Azure Function
Azure Functions                                   azureFunctionsProjectTemplates      [C#]              AzureFunctions/ClassLib
  1. Create a new functions project:
dotnet new "Azure Functions"
  1. Add a function - lets use the HTTP trigger template:
dotnet new HttpTrigger -n Function1
  1. Compile:
dotnet build
  1. After package restore and build, the bin\Debug\netstandard2.0 directory will contain your compiled function app:
λ ls bin\Debug\netstandard2.0


    Directory: D:\code\temp\dotnetnew\FunctionsCmdLineTest\bin\Debug\netstandard2.0


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----         4/9/2018   9:29 AM                bin
d-----         4/9/2018   9:27 AM                Function1
-a----         4/9/2018   9:27 AM          77422 FunctionsCmdLineTest.deps.json
-a----         4/9/2018   9:25 AM              4 host.json
-a----         4/9/2018   9:25 AM            128 local.settings.json
  1. You can run the output via the commandline if you've installed the azure-functions-core-tools. Today you can do this using npm:
npm install azure-functions-core-tools@core -g
  1. Start the functions host using the output from the build process:
func start --script-root bin\Debug\netstandard2.0
  1. If done correctly, you should see at the bottom of the output:
[4/9/2018 4:37:27 PM] Job host started
Listening on http://localhost:7071/
Hit CTRL-C to exit...

Http Functions:

        Function1: http://localhost:7071/api/Function1
  1. Invoke the function:
λ curl http://localhost:7071/api/Function1?name=paul


StatusCode        : 200
StatusDescription : OK
Content           : Hello, paul
Clone this wiki locally