Build and Deploy Azure Functions without using Visual Studio 2017


If you use C# for Azure Functions, I highly recommend to use Visual Studio and Visual Studio Team Services. It is the easiest way to automate the continuous delivery pipeline. However, some people might want to deploy it manually without Visual Studio and Visual Studio Team Services. I'll share how to do it.

In my case, customer wants to use Visual Studio for development. However, Ops people don't want to use it. I recommend the VSTS, however, they can't use it for some company policies.  Also it might be helpful for other CI tools like Jenkins.

We already have a project of the Azure Fucntions written in C#.

1. Download Prerequisite

Visual Studio Build Tools (latest MSBuild)

If you want to build/deploy Azure Functions C# project without using Visual Studio, you need to download the Visual Studio Build Tools. It includes latest msbuld.exe. For the Azure Functions app, the old version doesn't work. msbuild 15.0 for visual studio 2017 works.

You can download it from here. Then install it on your windows 10 or some other windows platform.

https://www.visualstudio.com/downloads/?q=msbuild

Nuget.exe

You need to restore nuget packages. Get the Nuget.exe. You can download from here.

https://www.nuget.org/downloads

MSDeploy

You might already have it. Usually you can find it on

C:\Program Files (x86)\IIS\Microsoft Web Deploy V3

Now we are ready to write a scirpt

 

NOTE: You might need to install visual studio even if you don't need to edit via visual studio. If so, please let me know.

2.Write a deploy.bat script

This is the sample script to build an Azure Functions project then deploy to the Azure Functions.  My Solution name is "Telemetry.sln".  The project Name is "Telemetry" and "Telemetry.Test". You can edit according to your project.

"C:\Users\tsushi\Downloads\nuget.exe" restore "Telemetry.sln"

copy Telemetry\Settings\local.settings.peter.json Telemetry\local.settings.json

"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" "Telemetry.sln" /nologo /nr:false /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="WebApp.zip" /p:DeployIisAppPath="Default Web Site" /t:"Telemetry:Clean;Build";"Telemetry_Test:Clean;Build" /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="15.0"

"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package='Telemetry\WebApp.zip' -dest:auto,ComputerName='https://japanfunctions.scm.azurewebsites.net:443/msdeploy.axd?site=JapanFunctions',UserName='YOUR_USER_NAME',Password='YOUR_PASSWORD',AuthType='Basic' -setParam:name='IIS Web Application Name',value='JapanFunctions' -enableRule:DoNotDeleteRule

 

My project name is "Telemetry". I'd like to explain it.

2.1. Restore Nuget packages

Before building the app, you need to restore the nuget packages.

"C:\Users\tsushi\Downloads\nuget.exe" restore "Telemetry.sln"

2.2. Make sure you have local.settings.jason

You need local.settings.json for building the project. Even if it is not used on the Azure. You don't need to contents because it is not used on the Azure. On Azure, the function uses the AppSettings and Connection Strings on your Azure Functions.

copy Telemetry\Settings\local.settings.peter.json Telemetry\local.settings.json

2.3. Build it and Create a zip file

If you want to deploy the Azure functions, you need to build it and zip it. In this case, I use /t option for selecting projects which is necessary for this build.

"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" "Telemetry.sln" /nologo /nr:false /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="WebApp.zip" /p:DeployIisAppPath="Default Web Site" /t:"Telemetry:Clean;Build";"Telemetry_Test:Clean;Build" /p:platform="any cpu" /p:configuration="release" /p:VisualStudioVersion="15.0"

This blog explains some parameters on the /p options.

https://blogs.endjin.com/2016/10/how-to-package-a-web-project-for-deployment-from-the-command-line/

2.4. Deploy to your Azure Functions

Deploy the zip file using your credential. japanFunctions is my Azure Function's name. Please change it to your azure functions name.

"C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package='Telemetry\WebApp.zip' -dest:auto,ComputerName='https://japanfunctions.scm.azurewebsites.net:443/msdeploy.axd?site=JapanFunctions',UserName='YOUR_USER_NAME',Password='YOUR_PASSWORD',AuthType='Basic' -setParam:name='IIS Web Application Name',value='JapanFunctions' -enableRule:DoNotDeleteRule

Maybe you don't know your credential of the Azure Functions. You can find on your Azure Functions.

You can donwload the publish profile. You can find username and password.

Resource


Comments (0)

Skip to main content