Created
June 1, 2021 01:04
-
-
Save bryanknox/22dd459895f50498408e5210a5236f78 to your computer and use it in GitHub Desktop.
PowerShell script to create a Visual Studio Solution that contains an Azure Function app project and an Azure Function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CreateFunctionAppVsSolution.ps1 | |
# | |
# PowerShell script to create a Visual Studio Solution that contains | |
# an Azure Function app project, and an Azure Function. | |
# | |
# Uses: | |
# - .NET CLI | |
# See https://docs.microsoft.com/en-us/dotnet/core/tools/ | |
# - Azure Functions Core Tools | |
# See: https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash | |
# | |
Write-Host | |
Write-Host "CreateFunctionAppVsProject" | |
$ErrorActionPreference = "Stop" | |
# Configure variables. | |
# Configure the names to be used by this script. | |
# Information about the supported Function Template Names can be found at: | |
# https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#create-func | |
# Template names are all related to trigger types. | |
$vsSolutionName = "AzureFunctionApp3.1Sample" | |
$functionAppVsProjectName = "FunctionApp" | |
$functionName = "HttpTriggeredFunction" | |
$functionTemplateName = "HTTP trigger" | |
Write-Host | |
Write-Host "Configured Variables:" | |
Write-Host "vsSolutionName : $vsSolutionName" | |
Write-Host "functionAppVsProjectName : $functionAppVsProjectName" | |
Write-Host "functionName : $functionName" | |
Write-Host "functionTemplateName : $functionTemplateName" | |
# Create the VS solution folder. | |
New-Item -Path . -Name $vsSolutionName -ItemType "directory" | |
$vsSolutionPath = [System.IO.Path]::GetFullPath((Join-Path -Path . -ChildPath $vsSolutionName)) | |
Set-Location -Path $vsSolutionPath | |
# Create the VS Solution. | |
# It is given the same name as the current directory. | |
dotnet new sln | |
# Create the Function App VS project. | |
func init $functionAppVsProjectName --worker-runtime dotnet | |
# Add the Function App VS project to the VS solution. | |
dotnet sln add "$functionAppVsProjectName\$functionAppVsProjectName.csproj" | |
$functionAppPath = Join-Path -Path $vsSolutionPath -ChildPath $functionAppVsProjectName | |
Set-Location -Path $functionAppPath | |
# Create the Function (.cs file) in the Function App project. | |
# https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#create-func | |
func new --name $functionName --template $functionTemplateName --authlevel "anonymous" | |
# Done. | |
Write-Host | |
Write-Host "Done." | |
Write-Host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment