Skip to content

Commit 398f785

Browse files
author
Kapil Borle
committed
Allow importing module on NanoServer
1 parent 0ab216e commit 398f785

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

Engine/PSScriptAnalyzer.psm1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ $PSModuleRoot = $PSModule.ModuleBase
1212

1313
# Import the appropriate nested binary module based on the current PowerShell version
1414
$binaryModuleRoot = $PSModuleRoot
15-
if ($PSVersionTable.PSVersion -lt [Version]'5.0') {
16-
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath 'PSv3'
15+
16+
if ($PSVersionTable.PSEdition -ne 'Desktop') {
17+
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath 'coreclr'
18+
}
19+
else
20+
{
21+
if ($PSVersionTable.PSVersion -lt [Version]'5.0') {
22+
$binaryModuleRoot = Join-Path -Path $PSModuleRoot -ChildPath 'PSv3'
23+
}
1724
}
1825

1926
$binaryModulePath = Join-Path -Path $binaryModuleRoot -ChildPath 'Microsoft.Windows.PowerShell.ScriptAnalyzer.dll'

buildCoreClr.ps1

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@ if (-not (Test-Path "$solutionDir/global.json"))
1010
throw "Not in solution root"
1111
}
1212

13-
$itemsToCopy = @("$solutionDir\Engine\bin\Debug\netcoreapp1.0\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
14-
"$solutionDir\Rules\bin\Debug\netcoreapp1.0\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll",
15-
"$solutionDir\Engine\PSScriptAnalyzer.psd1",
13+
$itemsToCopyCoreCLR = @("$solutionDir\Engine\bin\Debug\netcoreapp1.0\Microsoft.Windows.PowerShell.ScriptAnalyzer.dll",
14+
"$solutionDir\Rules\bin\Debug\netcoreapp1.0\Microsoft.Windows.PowerShell.ScriptAnalyzer.BuiltinRules.dll")
15+
16+
$itemsToCopyCommon = @("$solutionDir\Engine\PSScriptAnalyzer.psd1",
1617
"$solutionDir\Engine\PSScriptAnalyzer.psm1",
1718
"$solutionDir\Engine\ScriptAnalyzer.format.ps1xml",
1819
"$solutionDir\Engine\ScriptAnalyzer.types.ps1xml")
1920

20-
$destinationDir = "$solutionDir/out/coreclr/PSScriptAnalyzer"
21+
$destinationDir = "$solutionDir/out/PSScriptAnalyzer"
22+
$destinationDirCoreCLR = "$destinationDir/coreclr"
2123

2224
if ($build)
2325
{
@@ -31,20 +33,21 @@ if ($build)
3133
dotnet build
3234
Pop-Location
3335

34-
if (-not (Test-Path $destinationDir))
35-
{
36-
New-Item -ItemType Directory $destinationDir -Force
37-
}
38-
else
36+
Function CopyToDestinationDir($itemsToCopy, $destination)
3937
{
40-
Remove-Item "$destinationDir\*" -Recurse
41-
}
42-
43-
foreach ($file in $itemsToCopy)
44-
{
45-
Copy-Item -Path $file -Destination (Join-Path $destinationDir (Split-Path $file -Leaf)) -Verbose
38+
if (-not (Test-Path $destination))
39+
{
40+
New-Item -ItemType Directory $destination -Force
41+
}
42+
foreach ($file in $itemsToCopy)
43+
{
44+
Copy-Item -Path $file -Destination (Join-Path $destination (Split-Path $file -Leaf)) -Verbose -Force
45+
}
4646
}
47+
CopyToDestinationDir $itemsToCopyCommon $destinationDir
4748
(Get-Content "$destinationDir\PSScriptAnalyzer.psd1") -replace "ModuleVersion = '1.6.0'","ModuleVersion = '0.0.1'" | Out-File "$destinationDir\PSScriptAnalyzer.psd1" -Encoding ascii
49+
50+
CopyToDestinationDir $itemsToCopyCoreCLR $destinationDirCoreCLR
4851
}
4952

5053
$modulePath = "$HOME\Documents\WindowsPowerShell\Modules";

0 commit comments

Comments
 (0)