@@ -134,6 +134,12 @@ $depEntriesXml </group>
134134 $script :localRepoDir = Join-Path $TestDrive ' platformFilterRepo'
135135 $null = New-Item $localRepoDir - ItemType Directory - Force
136136
137+ # Import the local build of the module (handles PS 7.6+ where it ships built-in)
138+ $outModulePath = Join-Path $PSScriptRoot ' ../../out/Microsoft.PowerShell.PSResourceGet'
139+ if (Test-Path $outModulePath ) {
140+ Import-Module $outModulePath - Force
141+ }
142+
137143 $script :localRepoName = ' PlatformFilterTestRepo'
138144 Register-PSResourceRepository - Name $localRepoName - Uri $localRepoDir - Trusted - Force - ErrorAction SilentlyContinue
139145
@@ -396,4 +402,166 @@ $depEntriesXml </group>
396402 }
397403 }
398404 }
405+
406+
407+ Context ' TFM Merge Install (already installed, explicit -TargetFramework)' {
408+
409+ BeforeAll {
410+ $script :tfmMergePkgName = ' TestTfmMergeModule'
411+ $script :tfmMergePkgVersion = ' 1.0.0'
412+
413+ New-TestNupkg - Name $tfmMergePkgName - Version $tfmMergePkgVersion `
414+ - OutputDir $localRepoDir `
415+ - LibTfms @ (' net472' , ' net8.0' ) `
416+ - IncludeModuleManifest
417+ }
418+
419+ AfterEach {
420+ Uninstall-PSResource $tfmMergePkgName - Version " *" - ErrorAction SilentlyContinue
421+ }
422+
423+ It " Should merge net472 into an existing net8.0 install" - Skip:($PSVersionTable.PSVersion.Major -le 5 ) {
424+ # Step 1: Install normally — should select net8.0 on PS7+
425+ Install-PSResource - Name $tfmMergePkgName - Repository $localRepoName - TrustRepository - Version $tfmMergePkgVersion
426+ $installed = Get-InstalledPSResource - Name $tfmMergePkgName
427+ $installed | Should -Not - BeNullOrEmpty
428+
429+ $installPath = Get-VersionInstallPath $installed
430+ $libDir = Join-Path $installPath ' lib'
431+
432+ # Verify only net8.0 was installed
433+ Test-Path (Join-Path $libDir ' net8.0' ) | Should - BeTrue
434+ Test-Path (Join-Path $libDir ' net472' ) | Should - BeFalse
435+
436+ # Step 2: Merge net472 using -TargetFramework
437+ Install-PSResource - Name $tfmMergePkgName - Repository $localRepoName - TrustRepository - Version $tfmMergePkgVersion - TargetFramework ' net472'
438+
439+ # Verify both TFMs are now present
440+ Test-Path (Join-Path $libDir ' net8.0' ) | Should - BeTrue
441+ Test-Path (Join-Path $libDir ' net472' ) | Should - BeTrue
442+
443+ # Verify the assembly file exists in the merged folder
444+ Test-Path (Join-Path $libDir " net472/$tfmMergePkgName .dll" ) | Should - BeTrue
445+ }
446+
447+ It " Should merge net8.0 into an existing net472 install" - Skip:($PSVersionTable.PSVersion.Major -gt 5 ) {
448+ # Step 1: Install normally on WinPS — should select net472
449+ Install-PSResource - Name $tfmMergePkgName - Repository $localRepoName - TrustRepository - Version $tfmMergePkgVersion
450+ $installed = Get-InstalledPSResource - Name $tfmMergePkgName
451+ $installed | Should -Not - BeNullOrEmpty
452+
453+ $installPath = Get-VersionInstallPath $installed
454+ $libDir = Join-Path $installPath ' lib'
455+
456+ # Verify only net472 was installed
457+ Test-Path (Join-Path $libDir ' net472' ) | Should - BeTrue
458+ Test-Path (Join-Path $libDir ' net8.0' ) | Should - BeFalse
459+
460+ # Step 2: Merge net8.0 using -TargetFramework
461+ Install-PSResource - Name $tfmMergePkgName - Repository $localRepoName - TrustRepository - Version $tfmMergePkgVersion - TargetFramework ' net8.0'
462+
463+ # Verify both TFMs are now present
464+ Test-Path (Join-Path $libDir ' net472' ) | Should - BeTrue
465+ Test-Path (Join-Path $libDir ' net8.0' ) | Should - BeTrue
466+ }
467+
468+ It " Should not overwrite existing files during merge" - Skip:($PSVersionTable.PSVersion.Major -le 5 ) {
469+ # Step 1: Install normally — gets net8.0
470+ Install-PSResource - Name $tfmMergePkgName - Repository $localRepoName - TrustRepository - Version $tfmMergePkgVersion
471+
472+ $installed = Get-InstalledPSResource - Name $tfmMergePkgName
473+ $installPath = Get-VersionInstallPath $installed
474+ $psd1Path = Join-Path $installPath " $tfmMergePkgName .psd1"
475+
476+ # Record the original .psd1 write time
477+ $originalWriteTime = (Get-Item $psd1Path ).LastWriteTime
478+
479+ # Small delay to ensure timestamp difference
480+ Start-Sleep - Milliseconds 100
481+
482+ # Step 2: Merge net472
483+ Install-PSResource - Name $tfmMergePkgName - Repository $localRepoName - TrustRepository - Version $tfmMergePkgVersion - TargetFramework ' net472'
484+
485+ # The .psd1 should NOT have been overwritten
486+ $newWriteTime = (Get-Item $psd1Path ).LastWriteTime
487+ $newWriteTime | Should - Be $originalWriteTime
488+ }
489+ }
490+
491+
492+ Context ' RID Merge Install (already installed, explicit -RuntimeIdentifier)' {
493+
494+ BeforeAll {
495+ $script :ridMergePkgName = ' TestRidMergeModule'
496+ $script :ridMergePkgVersion = ' 1.0.0'
497+
498+ New-TestNupkg - Name $ridMergePkgName - Version $ridMergePkgVersion `
499+ - OutputDir $localRepoDir `
500+ - RuntimeIdentifiers @ (' win-x64' , ' linux-x64' , ' osx-arm64' ) `
501+ - LibTfms @ (' netstandard2.0' ) `
502+ - IncludeModuleManifest
503+ }
504+
505+ AfterEach {
506+ Uninstall-PSResource $ridMergePkgName - Version " *" - ErrorAction SilentlyContinue
507+ }
508+
509+ It " Should merge a foreign RID into an existing install" {
510+ # Step 1: Install normally — gets current platform RID
511+ Install-PSResource - Name $ridMergePkgName - Repository $localRepoName - TrustRepository - Version $ridMergePkgVersion
512+ $installed = Get-InstalledPSResource - Name $ridMergePkgName
513+ $installed | Should -Not - BeNullOrEmpty
514+
515+ $installPath = Get-VersionInstallPath $installed
516+
517+ # Pick a foreign RID
518+ $foreignRid = if ($IsWindows ) { ' linux-x64' } elseif ($IsMacOS ) { ' win-x64' } else { ' osx-arm64' }
519+
520+ # Verify foreign RID is not present yet
521+ Test-Path (Join-Path $installPath $foreignRid ) | Should - BeFalse
522+
523+ # Step 2: Merge foreign RID
524+ Install-PSResource - Name $ridMergePkgName - Repository $localRepoName - TrustRepository - Version $ridMergePkgVersion - RuntimeIdentifier $foreignRid
525+
526+ # Verify both RIDs are now present
527+ $currentRidDir = Join-Path $installPath $script :currentRid
528+ $foreignRidDir = Join-Path $installPath $foreignRid
529+ Test-Path $currentRidDir | Should - BeTrue
530+ Test-Path $foreignRidDir | Should - BeTrue
531+ }
532+ }
533+
534+
535+ Context ' Missing TFM/RID Validation Warnings' {
536+
537+ BeforeAll {
538+ $script :warnPkgName = ' TestMissingTfmRidModule'
539+ $script :warnPkgVersion = ' 1.0.0'
540+
541+ # Package only has net8.0 and win-x64
542+ New-TestNupkg - Name $warnPkgName - Version $warnPkgVersion `
543+ - OutputDir $localRepoDir `
544+ - RuntimeIdentifiers @ (' win-x64' ) `
545+ - LibTfms @ (' net8.0' ) `
546+ - IncludeModuleManifest
547+ }
548+
549+ AfterEach {
550+ Uninstall-PSResource $warnPkgName - Version " *" - ErrorAction SilentlyContinue
551+ }
552+
553+ It " Should warn when -TargetFramework does not exist in the package" {
554+ $warnings = $null
555+ Install-PSResource - Name $warnPkgName - Repository $localRepoName - TrustRepository - Version $warnPkgVersion - TargetFramework ' net472' - WarningVariable warnings
556+ $warnings | Should -Not - BeNullOrEmpty
557+ ($warnings | Out-String ) | Should - BeLike " *net472*not found*"
558+ }
559+
560+ It " Should warn when -RuntimeIdentifier does not exist in the package" {
561+ $warnings = $null
562+ Install-PSResource - Name $warnPkgName - Repository $localRepoName - TrustRepository - Version $warnPkgVersion - RuntimeIdentifier ' linux-arm64' - WarningVariable warnings
563+ $warnings | Should -Not - BeNullOrEmpty
564+ ($warnings | Out-String ) | Should - BeLike " *linux-arm64*not found*"
565+ }
566+ }
399567}
0 commit comments