Skip to content

Instantly share code, notes, and snippets.

View bryanknox's full-sized avatar

Bryan Knox bryanknox

View GitHub Profile
@bryanknox
bryanknox / Test-Remove-BinObjFolders.ps1
Last active May 18, 2022 00:12
PowerShell script module file to remove all bin and obj folders under the current folder and any subfolders. Handy for Visual Studio projects and solutions.
# Test of Remove-BinObjFolders function.
$ErrorActionPreference = "Stop"
Write-Host
Write-Host "----------------------"
# Arrange
Write-Host
@bryanknox
bryanknox / CreateFunctionAppVsSolution.ps1
Created June 1, 2021 01:04
PowerShell script to create a Visual Studio Solution that contains an Azure Function app project and an Azure Function.
# 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
@bryanknox
bryanknox / .editorconfig
Last active January 4, 2023 13:00
.editorconfig for C# Visual Studio projects
# EditorConfig is awesome: https://EditorConfig.org
#
# More info about editorconfig for C# and .NET in Visual Studio see:
# https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2019
#
# Most of the .NET and C# rules below were taken from the
# Microsoft Roslyn team's editorconfig at:
# https://github.com/dotnet/roslyn/blob/master/.editorconfig
# Top-most EditorConfig file.
@bryanknox
bryanknox / disable-function-if-exists.template.md
Last active February 9, 2024 10:25
Azure DevOps YAML pipeline template to disable an Azure Function if it exists.

Disable Azure Function if Exists using YAML Pipeline

The disable-function-if-exists.template.yml below is a sample Azure DevOps YAML pipeline template that can be used to disable an Azure Function if it exists.

In some deployment scenarios you may need to disable an Azure Function, such as a queue triggered function, before deploying down stream resources. The function to be disabled may not exist the first time the deployment pipeline is run in a particular environment, so the template checks for its existance before attempting to disalbe it.

Links and References

Pass variables between job steps in Azure DevOps YAML Pipelines

@bryanknox
bryanknox / Pass-variables-between-steps-in-Azure-YAML-Pipelines.md
Last active October 15, 2020 13:53
Pass variables between job steps in Azure DevOps YAML Pipelines.

Pass variables between job steps in Azure DevOps YAML Pipelines

Example YAML pipeline

The example (see sample-azure-pipeline.yml) uses the pwsh shortcut for the PowerShell task so it works across platforms.

In Step 1 the inline PowerShell script logic determines and sets the value of the IsFooBar variable. It uses "logging commands" to set the variable.

Write-Host "##vso[task.setvariable variable=IsFooBar]$IsFooEqualToBar"
@bryanknox
bryanknox / Resource_Authorization_Issue_in_Azure_YAML_Pipeline.md
Last active January 9, 2024 03:49
Use ConnectedServiceNameARM instead of azureSubscription for the input argument name in AzurePowerShell tasks in Azure DevOps YAML pipelines

Use ConnectedServiceNameARM instead of azureSubscription in AzurePowerShell tasks in Azure DevOps YAML pipelines

tl;dr

Don't get fooled into providing an Azure Subscription name to a AzurePowerShell task in an Azure DevOps YAML pipeline, just because the input argument is named azureSubscription. It really needs the name of an Azure DevOps Service Connection!

For AzurePowerShell tasks use the ConnectedServiceNameARM input name instead of the misleading azureSubscription alias.

The Context of the Error

I made a copy of an Azure YAML pipeline I found on the internet as a baseline for what I needed.

@bryanknox
bryanknox / ServiceBusOutputBindingAzureFunctions.cs
Last active May 17, 2020 14:29
Examples of Service Bus output binding in an Azure Function. Custom class vs Message.
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.ServiceBus;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Newtonsoft.Json;
using System.Text;
using System.Threading.Tasks;
namespace K0x.Eample.AzureFunctions
@bryanknox
bryanknox / DurableOrchestrationStatusProcessor.cs
Created March 23, 2020 19:19
Use paging to process status of many Azure Durable Functions.
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
namespace K0x.DurableFunctionsHelpers
{
public static class DurableOrchestrationStatusProcessor
{
@bryanknox
bryanknox / EntityProxyCreator.cs
Last active October 20, 2020 14:06
OBSOLETE: Since Azure Functions Durable Extensions 2.3.0, this technique is no longer needed. Wraps the `DurableEntityProxyExtensions.CreateEntityProxy` extension methods for use in Azure Durable Function Orchestrations unit testing.
using Microsoft.Azure.WebJobs.Extensions.DurableTask;
namespace K0x.DurableFunctionsHelpers
{
/// <summary>
/// Wraps the DurableEntityProxyExtensions.CreateEntityProxy extension methods
/// for use in durable orchestrations that are unit tested.
/// </summary>
/// <remarks>
/// Instead of using the DurableEntityProxyExtensions.CreateEntityProxy<>(..) extension method
@bryanknox
bryanknox / EnumParseUtils.cs
Last active June 30, 2021 03:53
Parse an enum value from a string in C#
using System;
namespace K0x.Utilities
{
public static class EnumParseUtils
{
/// <summary>
/// Try to parse an enum value from the given string.
/// </summary>
/// <typeparam name="TEnum">