Skip to content

Commit d44c0ea

Browse files
Fix packaging of Powershell module (#26)
1 parent 24ac8f4 commit d44c0ea

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

build/Eryph.IdentityClient.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ ClrVersion = '4.0'
5252

5353
# Modules that must be imported into the global environment prior to importing this module
5454
RequiredModules = @(
55-
@{ ModuleName="Eryph.ClientRuntime.Configuration"; ModuleVersion="0.8.1"; GUID="31a5834e-973e-478f-a48d-cea5f1e92962" }
55+
@{ ModuleName="Eryph.ClientRuntime.Configuration"; ModuleVersion="0.7.1"; GUID="31a5834e-973e-478f-a48d-cea5f1e92962" }
5656
)
5757

5858
# Assemblies that must be loaded prior to importing this module

build/Package-PsModule.ps1

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ $excludedFiles = @("System.Management.Automation.dll", "JetBrains.Annotations.dl
4141

4242
$modulePath = Join-Path $OutputDirectory "PsModule" $ModuleName
4343
$isWindowsPowershell = $TargetFramework -like 'net4*'
44+
$isPrerelease = -not [string]::IsNullOrWhiteSpace($NuGetPreReleaseTag)
4445
$moduleAssemblyPath = Join-Path $modulePath ($isWindowsPowershell ? 'desktop' : 'coreclr')
4546

4647
# Prepare the output directory
@@ -59,7 +60,7 @@ Copy-Item -Path (Join-Path $targetDirectory "*") -Destination $moduleAssemblyPat
5960
# Prepare the module manifest
6061
$config = Get-Content (Join-Path $PSScriptRoot "$ModuleName.psd1") -Raw
6162
$config = $config.Replace("ModuleVersion = '0.1'", "ModuleVersion = '$MajorMinorPatch'");
62-
if (-not [string]::IsNullOrWhiteSpace($NuGetPreReleaseTag)) {
63+
if ($isPrerelease) {
6364
$config = $config.Replace("# Prerelease = ''", "Prerelease = '$NuGetPreReleaseTag'");
6465
}
6566
Set-Content -Path (Join-Path $modulePath "$ModuleName.psd1") -Value $config
@@ -68,17 +69,18 @@ Copy-Item -Path (Join-Path $PSScriptRoot "$ModuleName.psm1") -Destination $modul
6869
# This Powershell module requires the module Eryph.ClientRuntime.Configuration.
6970
# We download that module first to ensure that it is available. Otherwise,
7071
# the import during the test below would fail.
71-
$configData = Import-PowerShellDataFile (Join-Path $modulePath "$ModuleName.psd1")
72-
$clientRuntimeVersion = $configData.RequiredModules[0].ModuleVersion
73-
$clientRuntimeModulePath = Join-Path $OutputDirectory "PsModuleDependencies" "Eryph.ClientRuntime.Configuration"
74-
if (-not (Test-Path (Join-Path $clientRuntimeModulePath $clientRuntimeVersion))) {
75-
Save-Module -Path (Join-Path $OutputDirectory "PsModuleDependencies") -Name 'Eryph.ClientRuntime.Configuration' -AllowPrerelease -Force
72+
$clientRuntimeModule = Find-Module Eryph.ClientRuntime.Configuration -AllowPrerelease:$isPrerelease
73+
$clientRuntimeVersion = $clientRuntimeModule.Version
74+
$null = New-Item -ItemType Directory -Path (Join-Path $OutputDirectory "PsModuleDependencies" $clientRuntimeVersion) -ErrorAction SilentlyContinue
75+
$clientRuntimeModulePath = Join-Path $OutputDirectory "PsModuleDependencies" $clientRuntimeVersion "Eryph.ClientRuntime.Configuration"
76+
if (-not (Test-Path $clientRuntimeModulePath)) {
77+
Save-Module -Path (Join-Path $OutputDirectory "PsModuleDependencies" $clientRuntimeVersion) -Name 'Eryph.ClientRuntime.Configuration' -AllowPrerelease:$isPrerelease
7678
}
7779

7880
# Verify that all Cmdlets are exposed in the manifest. We must load the modules
7981
# in separate Powershell processes to avoid conflicts.
8082
$powershell = $isWindowsPowershell ? 'powershell.exe' : 'pwsh.exe'
81-
$moduleCmdlets = (& $powershell -Command "Import-Module $clientRuntimeModulePath -RequiredVersion $clientRuntimeVersion; [array](Import-Module -Scope Local $modulePath -PassThru).ExportedCmdlets.Keys -join ','") -split ','
83+
$moduleCmdlets = (& $powershell -Command "Import-Module $clientRuntimeModulePath; [array](Import-Module -Scope Local $modulePath -PassThru).ExportedCmdlets.Keys -join ','") -split ','
8284
$assemblyCmdlets = (& $powershell -Command "[array](Import-Module -Scope Local $TargetPath -PassThru).ExportedCmdlets.Keys -join ','") -split ','
8385
$missingCmdlets = [Linq.Enumerable]::Except($assemblyCmdlets, $moduleCmdlets)
8486
if ($missingCmdlets.Count -gt 0) {

0 commit comments

Comments
 (0)