-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dd15a8e
commit d806335
Showing
5 changed files
with
147 additions
and
79 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#Requires -Version 7.4 | ||
<# | ||
.SYNOPSIS | ||
Populates the Powershell module. | ||
.DESCRIPTION | ||
This script populates the Powershell module with the assemblies | ||
from the build output. It is intended to be called by MSBuild | ||
during the normal build process. The script will be called once | ||
for each target framework! | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ $_ -match '[a-zA-Z\.]+' }, ErrorMessage = "The module name '{0}' is invalid.")] | ||
$ModuleName, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ Test-Path $_ }, ErrorMessage = "The path '{0}' is invalid.")] | ||
$OutputDirectory, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ Test-Path $_ }, ErrorMessage = "The path '{0}' is invalid.")] | ||
$TargetPath, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ $_ -match 'net\d+\.?\d+' }, ErrorMessage = "The target framework '{0}' is invalid.")] | ||
$TargetFramework | ||
) | ||
|
||
$PSNativeCommandUseErrorActionPreference = $true | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$excludedFiles = @("System.Management.Automation.dll", "JetBrains.Annotations.dll") | ||
|
||
$modulePath = Join-Path $OutputDirectory "PsModule" $ModuleName | ||
$isWindowsPowershell = $TargetFramework -like 'net4*' | ||
$moduleAssemblyPath = Join-Path $modulePath ($isWindowsPowershell ? 'desktop' : 'coreclr') | ||
|
||
# Copy the assemblies from the build output | ||
if (Test-Path $moduleAssemblyPath) { | ||
Remove-Item -Path $moduleAssemblyPath -Force -Recurse | ||
} | ||
$null = New-Item -ItemType Directory -Path $moduleAssemblyPath | ||
$targetDirectory = (Get-Item $TargetPath).Directory.FullName | ||
Copy-Item -Path (Join-Path $targetDirectory "*") -Destination $moduleAssemblyPath -Exclude $excludedFiles -Recurse |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#Requires -Version 7.4 | ||
<# | ||
.SYNOPSIS | ||
Prepares the Powershell module. | ||
.DESCRIPTION | ||
This script prepares the Powershell module for distribution. | ||
It is intended to be called by MSBuild during the normal build | ||
process. The script prepares the module metadata (e.g. the manifest). | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ $_ -match '[a-zA-Z\.]+' }, ErrorMessage = "The module name '{0}' is invalid.")] | ||
$ModuleName, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ Test-Path $_ -IsValid }, ErrorMessage = "The path '{0}' is invalid.")] | ||
$OutputDirectory, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ $_ -match '\d+\.\d+\.\d+' }, ErrorMessage = "The version '{0}' is invalid.")] | ||
$MajorMinorPatch, | ||
[Parameter()] | ||
[string] | ||
$NuGetPreReleaseTag | ||
) | ||
|
||
$PSNativeCommandUseErrorActionPreference = $true | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$modulePath = Join-Path $OutputDirectory "PsModule" $ModuleName | ||
|
||
# Prepare the output directory | ||
if (Test-Path $modulePath) { | ||
Remove-Item -Path $modulePath -Force -Recurse | ||
} | ||
|
||
$null = New-Item -ItemType Directory -Path $modulePath | ||
|
||
$isPrerelease = -not [string]::IsNullOrWhiteSpace($NuGetPreReleaseTag) | ||
|
||
# Prepare the module manifest | ||
$config = Get-Content (Join-Path $PSScriptRoot "$ModuleName.psd1") -Raw | ||
$config = $config.Replace("ModuleVersion = '0.1'", "ModuleVersion = '$MajorMinorPatch'"); | ||
if ($isPrerelease) { | ||
$config = $config.Replace("# Prerelease = ''", "Prerelease = '$NuGetPreReleaseTag'"); | ||
} | ||
Set-Content -Path (Join-Path $modulePath "$ModuleName.psd1") -Value $config | ||
Copy-Item -Path (Join-Path $PSScriptRoot "$ModuleName.psm1") -Destination $modulePath |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#Requires -Version 7.4 | ||
<# | ||
.SYNOPSIS | ||
Test the Powershell module. | ||
.DESCRIPTION | ||
This script tests the fully packaged Powershell module. | ||
It is intended to be called by MSBuild during the normal build | ||
process. | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ $_ -match '[a-zA-Z\.]+' }, ErrorMessage = "The module name '{0}' is invalid.")] | ||
$ModuleName, | ||
[Parameter()] | ||
[string] | ||
[ValidateScript({ Test-Path $_ }, ErrorMessage = "The path '{0}' is invalid.")] | ||
$OutputDirectory | ||
) | ||
|
||
$PSNativeCommandUseErrorActionPreference = $true | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$modulePath = Join-Path $OutputDirectory "PsModule" $ModuleName | ||
|
||
# Verify that all Cmdlets are exposed in the manifest. We must load the modules | ||
# in separate Powershell processes to avoid conflicts. | ||
$moduleCmdlets = (powershell.exe -Command "[array](Import-Module -Scope Local $modulePath -PassThru).ExportedCmdlets.Keys -join ','") -split ',' | ||
$assemblyCmdlets = (powershell.exe -Command "[array](Import-Module -Scope Local $(Join-Path $modulePath "desktop" "$ModuleName.Commands.dll") -PassThru).ExportedCmdlets.Keys -join ','") -split ',' | ||
$missingCmdlets = [Linq.Enumerable]::Except($assemblyCmdlets, $moduleCmdlets) | ||
if ($missingCmdlets.Count -gt 0) { | ||
throw "The following Cmdlets are not exposed in the module manifest when checking with Windows Powershell: $($missingCmdlets -join ', ')" | ||
} | ||
|
||
$moduleCmdlets = (pwsh.exe -Command "[array](Import-Module -Scope Local $modulePath -PassThru).ExportedCmdlets.Keys -join ','") -split ',' | ||
$assemblyCmdlets = (pwsh.exe -Command "[array](Import-Module -Scope Local $(Join-Path $modulePath "coreclr" "$ModuleName.Commands.dll") -PassThru).ExportedCmdlets.Keys -join ','") -split ',' | ||
$missingCmdlets = [Linq.Enumerable]::Except($assemblyCmdlets, $moduleCmdlets) | ||
if ($missingCmdlets.Count -gt 0) { | ||
throw "The following Cmdlets are not exposed in the module manifest when checking with Powershell 7: $($missingCmdlets -join ', ')" | ||
} |
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