-
-
Save dylan-asos/309f7dd3a59c43dab60fd645293aad3e to your computer and use it in GitHub Desktop.
Install Logic Apps Local Extension
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
function GetLatestExtensionsPath() { | |
$userprofile = [environment]::GetFolderPath('USERPROFILE') | |
$extensionModulePath = Join-Path -Path $userprofile -ChildPath ".azure-functions-core-tools" | |
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "Functions" | |
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "ExtensionBundles" | |
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "Microsoft.Azure.Functions.ExtensionBundle.Workflows" | |
if ( Test-Path -Path $extensionModulePath ) | |
{ | |
write-host "Extension bundle module path is $extensionModulePath" | |
} | |
else | |
{ | |
throw "Extension bundle module path does not exist $extensionModulePath" | |
} | |
$latest = Get-ChildItem -Path $extensionModulePath | Sort-Object LastWriteTime -Descending | Select-Object -First 1 | |
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath $latest.name | |
return $extensionModulePath; | |
} | |
function GetLocalTempPackagesPath() { | |
$userprofile = [environment]::GetFolderPath('USERPROFILE') | |
$tempPackages = $userprofile + "\AppData\Local\TempPackages" | |
return $tempPackages; | |
} | |
function add-extension | |
{ | |
param( | |
[String] | |
$Name, | |
[String] | |
$NuGetPackageName, | |
[String] | |
$NuGetPackageVersion | |
) | |
process | |
{ | |
$extensionName = $Name | |
$extensionNameServiceProvider = $extensionName + "ServiceProvider" | |
$extensionDllName = "YourNameSpace.Azure.Workflows.ServiceProviders." + $extensionName + ".Extension" | |
$tempPackages = GetLocalTempPackagesPath | |
$extensionModulePath = GetLatestExtensionsPath; | |
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath $latest.name | |
$extensionProjectRoot = $extensionModulePath | |
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "bin" | |
$extensionModulePath = Join-Path -Path $extensionModulePath -ChildPath "extensions.json" | |
if ( Test-Path -Path $extensionModulePath ) | |
{ | |
write-host "EXTENSION PATH is $extensionModulePath and dll Path is $dll" | |
} | |
else | |
{ | |
throw "The extensions.json in extension bundle does not exist $extensionModulePath" | |
} | |
# Resolve all nuget dependencies | |
nuget install $NuGetPackageName -version $nugetPackageVersion -OutputDirectory $tempPackages -PreRelease | |
$nugetTempPackagePath = $tempPackages + "\$NuGetPackageName.$nugetPackageVersion\" | |
$nugetDll = Get-ChildItem -Path $nugetTempPackagePath -Filter "$extensionDllName.dll" -Recurse | |
if ( Test-Path -Path $nugetDll.FullName ) | |
{ | |
write-host "Extension dll path is $nugetDll" | |
} | |
else | |
{ | |
throw "Extension does not exist at $nugetDll" | |
} | |
$fullAssemblyName = [System.Reflection.AssemblyName]::GetAssemblyName($nugetDll.FullName).FullName | |
try | |
{ | |
# Kill all the existing func.exe else modeule extension cannot be modified. | |
taskkill /IM "func.exe" /F | |
} | |
catch | |
{ | |
write-host "func.exe not found" | |
} | |
$extensionFullName = "YourNameSpace.Azure.Workflows.ServiceProviders." + $extensionName + ".Extension.Initialization" | |
$startupClass = $extensionFullName + "." + $extensionName + "ServiceProviderStartup" | |
# 1. Add Nuget package to existing project | |
dotnet add $extensionProjectRoot package $NuGetPackageName --version $NuGetPackageVersion --source $nugetTempPackagePath | |
# 2. Update extensions.json under extension module | |
$typeFullName = $startupClass + ", " + $fullAssemblyName | |
$newNode = [pscustomobject] @{ | |
name = $extensionNameServiceProvider | |
typeName = $typeFullName} | |
$jsonContent = Get-Content $extensionModulePath -raw | ConvertFrom-Json | |
if ( ![bool]($jsonContent.extensions.name -match $extensionNameServiceProvider)) | |
{ | |
$jsonContent.extensions += $newNode | |
} | |
else | |
{ | |
$jsonContent.extensions | % {if($_.name -eq $extensionNameServiceProvider){$_.typeName=$typeFullName}} | |
} | |
$jsonContent | ConvertTo-Json -depth 32| set-content $extensionModulePath | |
# 3. update dll in extension module. | |
$spl = Split-Path $extensionModulePath | |
Get-ChildItem -Path $nugetTempPackagePath -Filter '*.dll' -Recurse | Copy-Item -Destination $spl | |
Write-host "Extension $extensionName is successfully added. " | |
} | |
} | |
add-extension "Cosmos" "YourNameSpace.Azure.Workflows.ServiceProviders.Cosmos.Extension" "1.0.15" | |
# For the UI to work properly at design time, requires the binaries included from the extensions | |
$extensionModulePath = GetLatestExtensionsPath; | |
$extensionsBinaryDirectory = Join-Path -Path $extensionModulePath -ChildPath "bin" | |
# Copy any additional files you might need | |
# $tempPackages = GetLocalTempPackagesPath | |
# $sourceDirectory = $tempPackages + "\Microsoft.Azure.Cosmos.3.18.0\lib\netstandard2.0" | |
# Get-ChildItem -Path $sourceDirectory -Recurse | Copy-Item -Destination $extensionsBinaryDirectory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment