Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/hosting/test_HostingBasic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,5 +182,30 @@ public static void TestConsoleShellScenario()
int ret = ConsoleShell.Start("Hello", string.Empty, new string[] { "-noprofile", "-c", "exit 42" });
Assert.Equal(42, ret);
}

[Fact]
public static void TestBuiltInModules()
{
var iss = System.Management.Automation.Runspaces.InitialSessionState.CreateDefault2();
if (System.Management.Automation.Platform.IsWindows)
{
iss.ExecutionPolicy = Microsoft.PowerShell.ExecutionPolicy.RemoteSigned;
}

using var runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(iss);
runspace.Open();

using var ps = System.Management.Automation.PowerShell.Create(runspace);
var results_1 = ps.AddScript("Write-Output Hello > $null; Get-Module").Invoke<System.Management.Automation.PSModuleInfo>();
Assert.Single(results_1);

var module = results_1[0];
Assert.Equal("Microsoft.PowerShell.Utility", module.Name);

ps.Commands.Clear();
var results_2 = ps.AddScript("Join-Path $PSHOME 'Modules' 'Microsoft.PowerShell.Utility' 'Microsoft.PowerShell.Utility.psd1'").Invoke<string>();
var moduleManifestPath = results_2[0];
Assert.Equal(moduleManifestPath, module.Path, ignoreCase: true);
}
}
}
45 changes: 44 additions & 1 deletion tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ function New-ILNugetPackage
}

$fileList = @(
"Microsoft.Management.Infrastructure.CimCmdlets.dll",
"Microsoft.PowerShell.Commands.Diagnostics.dll",
"Microsoft.PowerShell.Commands.Management.dll",
"Microsoft.PowerShell.Commands.Utility.dll",
Expand All @@ -1672,14 +1673,14 @@ function New-ILNugetPackage
"Microsoft.PowerShell.MarkdownRender.dll")

$linuxExceptionList = @(
"Microsoft.Management.Infrastructure.CimCmdlets.dll",
"Microsoft.PowerShell.Commands.Diagnostics.dll",
"Microsoft.PowerShell.CoreCLR.Eventing.dll",
"Microsoft.WSMan.Management.dll",
"Microsoft.WSMan.Runtime.dll")

if ($PSCmdlet.ShouldProcess("Create nuget packages at: $PackagePath"))
{

$refBinPath = New-TempFolder
$SnkFilePath = "$RepoRoot\src\signing\visualstudiopublic.snk"

Expand Down Expand Up @@ -1715,13 +1716,54 @@ function New-ILNugetPackage
$contentFolder = New-Item (Join-Path $filePackageFolder "contentFiles\any\any") -ItemType Directory -Force
$dotnetRefAsmFolder = Join-Path -Path $WinFxdBinPath -ChildPath "ref"
Copy-Item -Path $dotnetRefAsmFolder -Destination $contentFolder -Recurse -Force
Write-Log "Copied the reference assembly folder to contentFiles for the SDK package"

# Copy the built-in module folders to the NuGet package, so 'dotnet publish' can deploy those modules to the $pshome module path.
# This is for enabling applications that hosts PowerShell to ship the built-in modules.

$winBuiltInModules = @(
"CimCmdlets",
"Microsoft.PowerShell.Diagnostics",
"Microsoft.PowerShell.Host",
"Microsoft.PowerShell.Management",
"Microsoft.PowerShell.Security",
"Microsoft.PowerShell.Utility",
"Microsoft.WSMan.Management",
"PSDiagnostics"
)

$unixBuiltInModules = @(
"Microsoft.PowerShell.Host",
"Microsoft.PowerShell.Management",
"Microsoft.PowerShell.Security",
"Microsoft.PowerShell.Utility"
)

$winModuleFolder = New-Item (Join-Path $contentFolder "runtimes\win\lib\netcoreapp3.1\Modules") -ItemType Directory -Force
$unixModuleFolder = New-Item (Join-Path $contentFolder "runtimes\unix\lib\netcoreapp3.1\Modules") -ItemType Directory -Force

foreach ($module in $winBuiltInModules) {
$source = Join-Path $WinFxdBinPath "Modules\$module"
Copy-Item -Path $source -Destination $winModuleFolder -Recurse -Force
}

foreach ($module in $unixBuiltInModules) {
$source = Join-Path $LinuxFxdBinPath "Modules\$module"
Copy-Item -Path $source -Destination $unixModuleFolder -Recurse -Force
}

Write-Log "Copied the built-in modules to contentFiles for the SDK package"
}

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

switch ($fileBaseName) {
'Microsoft.Management.Infrastructure.CimCmdlets' {
$deps.Add([tuple]::Create([tuple]::Create('id', 'System.Management.Automation'), [tuple]::Create('version', $PackageVersion))) > $null
}

'Microsoft.PowerShell.Commands.Diagnostics' {
$deps.Add([tuple]::Create([tuple]::Create('id', 'System.Management.Automation'), [tuple]::Create('version', $PackageVersion))) > $null
}
Expand Down Expand Up @@ -1771,6 +1813,7 @@ function New-ILNugetPackage
}
$deps.Add([tuple]::Create([tuple]::Create('id', 'Microsoft.WSMan.Management'), [tuple]::Create('version', $PackageVersion))) > $null
$deps.Add([tuple]::Create([tuple]::Create('id', 'Microsoft.PowerShell.Commands.Diagnostics'), [tuple]::Create('version', $PackageVersion))) > $null
$deps.Add([tuple]::Create([tuple]::Create('id', 'Microsoft.Management.Infrastructure.CimCmdlets'), [tuple]::Create('version', $PackageVersion))) > $null
}

'Microsoft.PowerShell.Security' {
Expand Down