There is a PowerShell module developed by Lars Truijens available in PowerShell gallery and source is in GitHub. This module has really useful commands which does not depend in the gacutil coming with Visual Studio, which is not useful in this scenario as gacutil cannot be used in deployment targets even if there is a possibility of usage of it in the build servers, since we cannot install Visual Studio in deployment targets .
You can use below PowerShell script in VSTS/TF build to extract the required assemblies using assembly names (wild cards supported). This script makes sure NuGet package provider exists and then installs the PowerShell Module GAC, before using the GAC related commands.
param ( [string] $AssemblyMask, [string] $AssemblyTargetPath ) Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force Install-Module Gac -Force md -Path $AssemblyTargetPath $AssemblyMaskValues = $AssemblyMask.Split(';') foreach ($AssemblyMaskValue in $AssemblyMaskValues) { Get-GacAssembly $AssemblyMaskValue | Get-GacAssemblyFile | Copy-Item -Destination $AssemblyTargetPath -Verbose }
You can use the script as inline PowerShell task as shown below. Pass the arguments for assembly mask and the path to download assemblies from GAC. (The latest version of out of the box PowerShell task in VSTS does not have Arguments, you can use the extension from VS Marketplace which has a inline PowerShell task which is really flexible)
-AssemblyMask '$(DemoSDKAssemblyMask)' -AssemblyTargetPath '$(GacAssemblyPath)'
These variables can be configured similar to shown below. You can use .nuspec files to make sure the assemblies are packaged into NuGet package if you are using NuGet packages as the build artifact. Or you can copy the assemblies to build drop by putting them in build staging directory.
Then in your release definition you can use the script below to deploy the assemblies to the target machine GAC. This script also makes sure NuGet package provider exists and then installs the PowerShell Module GAC, before using the GAC related commands.
param ( [string] $AssemblyTargetPath ) Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force Install-Module Gac -Force $items = Get-ChildItem -Path $AssemblyTargetPath foreach ($item in $items) { $fullAssemblyPath = Join-Path $AssemblyTargetPath $item.Name Write-Host 'Adding to GAC ' $fullAssemblyPath Add-GacAssembly -Path $fullAssemblyPath -Force -Verbose }
The assemblies will be deployed to GAC in the target machine when the release is executed. If you are using Octopus deploy same PowerShell script can be used to get the assemblies deployed to GAC.
No comments:
Post a Comment