Skip to content

Commit 3fe5946

Browse files
daxian-dbwTravisEz13
authored andcommitted
Update the NuGet package generation to include cimcmdlet.dll and most of the built-in modules (PowerShell#11832)
1 parent c01589f commit 3fe5946

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

test/hosting/test_HostingBasic.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,30 @@ public static void TestConsoleShellScenario()
182182
int ret = ConsoleShell.Start("Hello", string.Empty, new string[] { "-noprofile", "-c", "exit 42" });
183183
Assert.Equal(42, ret);
184184
}
185+
186+
[Fact]
187+
public static void TestBuiltInModules()
188+
{
189+
var iss = System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2();
190+
if (System.Management.Automation.Platform.IsWindows)
191+
{
192+
iss.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.RemoteSigned;
193+
}
194+
195+
using var runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(iss);
196+
runspace.Open();
197+
198+
using var ps = System.Management.Automation.PowerShell.Create(runspace);
199+
var results_1 = ps.AddScript("Write-Output Hello > $null; Get-Module").Invoke<System.Management.Automation.PSModuleInfo>();
200+
Assert.Single(results_1);
201+
202+
var module = results_1[0];
203+
Assert.Equal("Microsoft.PowerShell.Utility", module.Name);
204+
205+
ps.Commands.Clear();
206+
var results_2 = ps.AddScript("Join-Path $PSHOME 'Modules' 'Microsoft.PowerShell.Utility' 'Microsoft.PowerShell.Utility.psd1'").Invoke<string>();
207+
var moduleManifestPath = results_2[0];
208+
Assert.Equal(moduleManifestPath, module.Path, ignoreCase: true);
209+
}
185210
}
186211
}

tools/packaging/packaging.psm1

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,7 @@ function New-ILNugetPackage
16591659
}
16601660

16611661
$fileList = @(
1662+
"Microsoft.Management.Infrastructure.CimCmdlets.dll",
16621663
"Microsoft.PowerShell.Commands.Diagnostics.dll",
16631664
"Microsoft.PowerShell.Commands.Management.dll",
16641665
"Microsoft.PowerShell.Commands.Utility.dll",
@@ -1672,14 +1673,14 @@ function New-ILNugetPackage
16721673
"Microsoft.PowerShell.MarkdownRender.dll")
16731674

16741675
$linuxExceptionList = @(
1676+
"Microsoft.Management.Infrastructure.CimCmdlets.dll",
16751677
"Microsoft.PowerShell.Commands.Diagnostics.dll",
16761678
"Microsoft.PowerShell.CoreCLR.Eventing.dll",
16771679
"Microsoft.WSMan.Management.dll",
16781680
"Microsoft.WSMan.Runtime.dll")
16791681

16801682
if ($PSCmdlet.ShouldProcess("Create nuget packages at: $PackagePath"))
16811683
{
1682-
16831684
$refBinPath = New-TempFolder
16841685
$SnkFilePath = "$RepoRoot\src\signing\visualstudiopublic.snk"
16851686

@@ -1715,13 +1716,54 @@ function New-ILNugetPackage
17151716
$contentFolder = New-Item (Join-Path $filePackageFolder "contentFiles\any\any") -ItemType Directory -Force
17161717
$dotnetRefAsmFolder = Join-Path -Path $WinFxdBinPath -ChildPath "ref"
17171718
Copy-Item -Path $dotnetRefAsmFolder -Destination $contentFolder -Recurse -Force
1719+
Write-Log "Copied the reference assembly folder to contentFiles for the SDK package"
1720+
1721+
# Copy the built-in module folders to the NuGet package, so 'dotnet publish' can deploy those modules to the $pshome module path.
1722+
# This is for enabling applications that hosts PowerShell to ship the built-in modules.
1723+
1724+
$winBuiltInModules = @(
1725+
"CimCmdlets",
1726+
"Microsoft.PowerShell.Diagnostics",
1727+
"Microsoft.PowerShell.Host",
1728+
"Microsoft.PowerShell.Management",
1729+
"Microsoft.PowerShell.Security",
1730+
"Microsoft.PowerShell.Utility",
1731+
"Microsoft.WSMan.Management",
1732+
"PSDiagnostics"
1733+
)
1734+
1735+
$unixBuiltInModules = @(
1736+
"Microsoft.PowerShell.Host",
1737+
"Microsoft.PowerShell.Management",
1738+
"Microsoft.PowerShell.Security",
1739+
"Microsoft.PowerShell.Utility"
1740+
)
1741+
1742+
$winModuleFolder = New-Item (Join-Path $contentFolder "runtimes\win\lib\netcoreapp3.1\Modules") -ItemType Directory -Force
1743+
$unixModuleFolder = New-Item (Join-Path $contentFolder "runtimes\unix\lib\netcoreapp3.1\Modules") -ItemType Directory -Force
1744+
1745+
foreach ($module in $winBuiltInModules) {
1746+
$source = Join-Path $WinFxdBinPath "Modules\$module"
1747+
Copy-Item -Path $source -Destination $winModuleFolder -Recurse -Force
1748+
}
1749+
1750+
foreach ($module in $unixBuiltInModules) {
1751+
$source = Join-Path $LinuxFxdBinPath "Modules\$module"
1752+
Copy-Item -Path $source -Destination $unixModuleFolder -Recurse -Force
1753+
}
1754+
1755+
Write-Log "Copied the built-in modules to contentFiles for the SDK package"
17181756
}
17191757

17201758
#region nuspec
17211759
# filed a tracking bug for automating generation of dependecy list: https://github.com/PowerShell/PowerShell/issues/6247
17221760
$deps = [System.Collections.ArrayList]::new()
17231761

17241762
switch ($fileBaseName) {
1763+
'Microsoft.Management.Infrastructure.CimCmdlets' {
1764+
$deps.Add([tuple]::Create([tuple]::Create('id', 'System.Management.Automation'), [tuple]::Create('version', $PackageVersion))) > $null
1765+
}
1766+
17251767
'Microsoft.PowerShell.Commands.Diagnostics' {
17261768
$deps.Add([tuple]::Create([tuple]::Create('id', 'System.Management.Automation'), [tuple]::Create('version', $PackageVersion))) > $null
17271769
}
@@ -1771,6 +1813,7 @@ function New-ILNugetPackage
17711813
}
17721814
$deps.Add([tuple]::Create([tuple]::Create('id', 'Microsoft.WSMan.Management'), [tuple]::Create('version', $PackageVersion))) > $null
17731815
$deps.Add([tuple]::Create([tuple]::Create('id', 'Microsoft.PowerShell.Commands.Diagnostics'), [tuple]::Create('version', $PackageVersion))) > $null
1816+
$deps.Add([tuple]::Create([tuple]::Create('id', 'Microsoft.Management.Infrastructure.CimCmdlets'), [tuple]::Create('version', $PackageVersion))) > $null
17741817
}
17751818

17761819
'Microsoft.PowerShell.Security' {

0 commit comments

Comments
 (0)