Skip to content

Commit 29e2147

Browse files
SteveL-MSFTdaxian-dbw
authored andcommitted
Port PowerShell to .NET Core 3.0 (PowerShell#9597)
1 parent afa76de commit 29e2147

File tree

43 files changed

+695
-631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+695
-631
lines changed

PowerShell.Common.props

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
Tracking Issue https://github.com/dotnet/sdk/issues/1557
6363
-->
6464
<PackageVersion>$(PSCoreBuildVersion)</PackageVersion>
65+
<ApplicationIcon Condition="$(ProductVersion.Contains('preview'))">..\..\assets\Powershell_av_colors.ico</ApplicationIcon>
66+
<ApplicationIcon Condition="!$(ProductVersion.Contains('preview'))">..\..\assets\Powershell_black.ico</ApplicationIcon>
6567

6668
</PropertyGroup>
6769

@@ -93,9 +95,8 @@
9395
<Company>Microsoft Corporation</Company>
9496
<Copyright>(c) Microsoft Corporation. All rights reserved.</Copyright>
9597

96-
<TargetFramework>netcoreapp2.1</TargetFramework>
97-
<RuntimeFrameworkVersion>2.1.8</RuntimeFrameworkVersion>
98-
<LangVersion>Latest</LangVersion>
98+
<TargetFramework>netcoreapp3.0</TargetFramework>
99+
<LangVersion>8.0</LangVersion>
99100

100101
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
101102
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

assets/files.wxs

Lines changed: 481 additions & 435 deletions
Large diffs are not rendered by default.

build.psm1

Lines changed: 8 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# On Windows paths is separated by semicolon
66
$script:TestModulePathSeparator = [System.IO.Path]::PathSeparator
77

8-
$dotnetCLIChannel = "release"
8+
$dotnetCLIChannel = 'preview' # TODO: Change this to 'release' once .Net Core 3.0 goes RTM
99
$dotnetCLIRequiredVersion = $(Get-Content $PSScriptRoot/global.json | ConvertFrom-Json).Sdk.Version
1010

1111
# Track if tags have been sync'ed
@@ -410,7 +410,7 @@ Fix steps:
410410
Pop-Location
411411
}
412412

413-
# publish netcoreapp2.1 reference assemblies
413+
# publish reference assemblies
414414
try {
415415
Push-Location "$PSScriptRoot/src/TypeCatalogGen"
416416
$refAssemblies = Get-Content -Path $incFileName | Where-Object { $_ -like "*microsoft.netcore.app*" } | ForEach-Object { $_.TrimEnd(';') }
@@ -449,51 +449,6 @@ Fix steps:
449449
}
450450
}
451451

452-
if ($Environment.IsWindows) {
453-
## need RCEdit to modify the binaries embedded resources
454-
$rcedit = "~/.rcedit/rcedit-x64.exe"
455-
if (-not (Test-Path -Type Leaf $rcedit)) {
456-
$rcedit = Get-Command "rcedit-x64.exe" -CommandType Application -ErrorAction Ignore | Select-Object -First 1 | ForEach-Object Name
457-
}
458-
if (-not $rcedit) {
459-
throw "RCEdit is required to modify pwsh.exe resources, please run 'Start-PSBootStrap' to install"
460-
}
461-
462-
$ReleaseVersion = ""
463-
if ($ReleaseTagToUse) {
464-
$ReleaseVersion = $ReleaseTagToUse
465-
} else {
466-
$ReleaseVersion = (Get-PSCommitId -WarningAction SilentlyContinue) -replace '^v'
467-
}
468-
# in VSCode, depending on where you started it from, the git commit id may be empty so provide a default value
469-
if (!$ReleaseVersion) {
470-
$ReleaseVersion = "6.0.0"
471-
$fileVersion = "6.0.0"
472-
} else {
473-
$fileVersion = $ReleaseVersion.Split("-")[0]
474-
}
475-
476-
# in VSCode, the build output folder doesn't include the name of the exe so we have to add it for rcedit
477-
$pwshPath = $Options.Output
478-
if (!$pwshPath.EndsWith("pwsh.exe")) {
479-
$pwshPath = Join-Path $Options.Output "pwsh.exe"
480-
}
481-
482-
if (Test-IsPreview $ReleaseVersion) {
483-
$iconPath = "$PSScriptRoot\assets\Powershell_av_colors.ico"
484-
} else {
485-
$iconPath = "$PSScriptRoot\assets\Powershell_black.ico"
486-
}
487-
488-
# fxdependent package does not have an executable to set iconPath etc.
489-
if ($Options.Runtime -ne 'fxdependent') {
490-
Start-NativeExecution { & $rcedit $pwshPath --set-icon $iconPath `
491-
--set-file-version $fileVersion --set-product-version $ReleaseVersion --set-version-string "ProductName" "PowerShell 7" `
492-
--set-version-string "LegalCopyright" "(C) Microsoft Corporation. All Rights Reserved." `
493-
--application-manifest "$PSScriptRoot\assets\pwsh.manifest" } | Write-Verbose
494-
}
495-
}
496-
497452
# download modules from powershell gallery.
498453
# - PowerShellGet, PackageManagement, Microsoft.PowerShell.Archive
499454
if ($PSModuleRestore) {
@@ -617,8 +572,8 @@ function New-PSOptions {
617572
[ValidateSet("Debug", "Release", "CodeCoverage", '')]
618573
[string]$Configuration,
619574

620-
[ValidateSet("netcoreapp2.1")]
621-
[string]$Framework,
575+
[ValidateSet("netcoreapp3.0")]
576+
[string]$Framework = "netcoreapp3.0",
622577

623578
# These are duplicated from Start-PSBuild
624579
# We do not use ValidateScript since we want tab completion
@@ -656,6 +611,7 @@ function New-PSOptions {
656611
}
657612

658613
Write-Verbose "Using configuration '$Configuration'"
614+
Write-Verbose "Using framework '$Framework'"
659615

660616
if (-not $Runtime) {
661617
if ($Environment.IsLinux) {
@@ -1741,19 +1697,6 @@ function Start-PSBootstrap {
17411697
$psInstallFile = [System.IO.Path]::Combine($PSScriptRoot, "tools", "install-powershell.ps1")
17421698
& $psInstallFile -AddToPath
17431699
}
1744-
1745-
## need RCEdit to modify the binaries embedded resources
1746-
if (-not (Test-Path "~/.rcedit/rcedit-x64.exe"))
1747-
{
1748-
Write-Log "Install RCEdit for modifying exe resources"
1749-
$rceditUrl = "https://github.com/electron/rcedit/releases/download/v1.0.0/rcedit-x64.exe"
1750-
New-Item -Path "~/.rcedit" -Type Directory -Force > $null
1751-
1752-
## need to specify TLS version 1.2 since GitHub API requires it
1753-
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
1754-
1755-
Invoke-WebRequest -OutFile "~/.rcedit/rcedit-x64.exe" -Uri $rceditUrl
1756-
}
17571700
}
17581701
} finally {
17591702
Pop-Location
@@ -1854,12 +1797,13 @@ function Start-TypeGen
18541797
<Target Name="_GetDependencies"
18551798
DependsOnTargets="ResolveAssemblyReferencesDesignTime">
18561799
<ItemGroup>
1857-
<_RefAssemblyPath Include="%(_ReferencesFromRAR.HintPath)%3B" Condition=" '%(_ReferencesFromRAR.NuGetPackageId)' != 'Microsoft.Management.Infrastructure' "/>
1800+
<_RefAssemblyPath Include="%(_ReferencesFromRAR.OriginalItemSpec)%3B" Condition=" '%(_ReferencesFromRAR.NuGetPackageId)' != 'Microsoft.Management.Infrastructure' "/>
18581801
</ItemGroup>
18591802
<WriteLinesToFile File="$(_DependencyFile)" Lines="@(_RefAssemblyPath)" Overwrite="true" />
18601803
</Target>
18611804
</Project>
18621805
'@
1806+
New-Item -ItemType Directory -Path (Split-Path -Path $GetDependenciesTargetPath -Parent) -Force > $null
18631807
Set-Content -Path $GetDependenciesTargetPath -Value $GetDependenciesTargetValue -Force -Encoding Ascii
18641808

18651809
Push-Location "$PSScriptRoot/src/Microsoft.PowerShell.SDK"
@@ -2317,7 +2261,7 @@ function Copy-PSGalleryModules
23172261
Remove-Item -Force -ErrorAction Ignore -Recurse "$Destination/$name"
23182262
New-Item -Path $dest -ItemType Directory -Force -ErrorAction Stop > $null
23192263
# Exclude files/folders that are not needed. The fullclr folder is coming from the PackageManagement module
2320-
$dontCopy = '*.nupkg', '*.nupkg.sha512', '*.nuspec', 'System.Runtime.InteropServices.RuntimeInformation.dll', 'fullclr'
2264+
$dontCopy = '*.nupkg', '*.nupkg.metadata', '*.nupkg.sha512', '*.nuspec', 'System.Runtime.InteropServices.RuntimeInformation.dll', 'fullclr'
23212265
Copy-Item -Exclude $dontCopy -Recurse $src/* $dest
23222266
}
23232267
}

docs/building/linux.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Start-PSBuild
7171
Congratulations! If everything went right, PowerShell is now built.
7272
The `Start-PSBuild` script will output the location of the executable:
7373

74-
`./src/powershell-unix/bin/Debug/netcoreapp2.1/linux-x64/publish/pwsh`.
74+
`./src/powershell-unix/bin/Debug/netcoreapp3.0/linux-x64/publish/pwsh`.
7575

7676
You should now be running the PowerShell Core that you just built, if your run the above executable.
7777
You can run our cross-platform Pester tests with `Start-PSPester`, and our xUnit tests with `Start-PSxUnit`.

docs/building/macos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ We cannot do this for you in the build module due to #[847][].
3636

3737
Start a PowerShell session by running `pwsh`, and then use `Start-PSBuild` from the module.
3838

39-
After building, PowerShell will be at `./src/powershell-unix/bin/Debug/netcoreapp2.1/osx-x64/publish/pwsh`.
39+
After building, PowerShell will be at `./src/powershell-unix/bin/Debug/netcoreapp3.0/osx-x64/publish/pwsh`.

docs/building/windows-core.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ Import-Module ./build.psm1
5858
Start-PSBuild
5959
```
6060

61-
Congratulations! If everything went right, PowerShell is now built and executable as `./src/powershell-win-core/bin/Debug/netcoreapp2.1/win7-x64/publish/pwsh.exe`.
61+
Congratulations! If everything went right, PowerShell is now built and executable as `./src/powershell-win-core/bin/Debug/netcoreapp3.0/win7-x64/publish/pwsh.exe`.
6262

6363
This location is of the form `./[project]/bin/[configuration]/[framework]/[rid]/publish/[binary name]`,
6464
and our project is `powershell`, configuration is `Debug` by default,
65-
framework is `netcoreapp2.1`, runtime identifier is `win7-x64` by default,
65+
framework is `netcoreapp3.0`, runtime identifier is `win7-x64` by default,
6666
and binary name is `pwsh`.
6767
The function `Get-PSOutput` will return the path to the executable;
6868
thus you can execute the development copy via `& (Get-PSOutput)`.

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "2.1.504"
3+
"version": "3.0.100-preview5-011568"
44
}
55
}

src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ private void LoadAssemblies(IEnumerable<string> assemblies)
663663
/// </summary>
664664
private static IEnumerable<PortableExecutableReference> InitDefaultRefAssemblies()
665665
{
666-
// netcoreapp2.1 currently comes with 144 reference assemblies (maybe more in future), so we use a capacity of '150'.
666+
// netcoreapp3.0 currently comes with 148 reference assemblies (maybe more in future), so we use a capacity of '150'.
667667
var defaultRefAssemblies = new List<PortableExecutableReference>(150);
668668

669669
foreach (string file in Directory.EnumerateFiles(s_netcoreAppRefFolder, "*.dll", SearchOption.TopDirectoryOnly))

src/ResGen/ResGen.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
<PropertyGroup>
44
<Description>Generates C# typed bindings for .resx files</Description>
5-
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
<TargetFramework>netcoreapp3.0</TargetFramework>
66
<AssemblyName>resgen</AssemblyName>
77
<OutputType>Exe</OutputType>
88
<TieredCompilation>true</TieredCompilation>
9+
<TieredCompilationQuickJit>true</TieredCompilationQuickJit>
910
<RuntimeIdentifiers>win7-x86;win7-x64;osx-x64;linux-x64</RuntimeIdentifiers>
1011
</PropertyGroup>
1112

src/System.Management.Automation/engine/PSVersionInfo.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public class PSVersionInfo
6060
private static Version s_psV4Version = new Version(4, 0);
6161
private static Version s_psV5Version = new Version(5, 0);
6262
private static Version s_psV51Version = new Version(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
63-
private static SemanticVersion s_psV6Version;
63+
private static SemanticVersion s_psV6Version = new SemanticVersion(6, 0, 0, null, null);
64+
private static SemanticVersion s_psV7Version;
6465

6566
/// <summary>
6667
/// A constant to track current PowerShell Edition.
@@ -99,12 +100,12 @@ static PSVersionInfo()
99100
rawGitCommitId = mainVersion;
100101
}
101102

102-
s_psV6Version = new SemanticVersion(mainVersion);
103+
s_psV7Version = new SemanticVersion(mainVersion);
103104

104-
s_psVersionTable[PSVersionInfo.PSVersionName] = s_psV6Version;
105+
s_psVersionTable[PSVersionInfo.PSVersionName] = s_psV7Version;
105106
s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue;
106107
s_psVersionTable[PSGitCommitIdName] = rawGitCommitId;
107-
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version };
108+
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psV7Version };
108109
s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion);
109110
s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion;
110111
s_psVersionTable[PSVersionInfo.WSManStackVersionName] = GetWSManStackVersion();
@@ -271,6 +272,11 @@ internal static string FeatureVersionString
271272

272273
internal static bool IsValidPSVersion(Version version)
273274
{
275+
if (version.Major == s_psV7Version.Major)
276+
{
277+
return version.Minor == s_psV7Version.Minor;
278+
}
279+
274280
if (version.Major == s_psV6Version.Major)
275281
{
276282
return version.Minor == s_psV6Version.Minor;
@@ -321,6 +327,11 @@ internal static SemanticVersion PSV6Version
321327
get { return s_psV6Version; }
322328
}
323329

330+
internal static SemanticVersion PSV7Version
331+
{
332+
get { return s_psV7Version; }
333+
}
334+
324335
#endregion
325336
}
326337

0 commit comments

Comments
 (0)