diff --git a/.gitignore b/.gitignore
index 59a05754fc8..06a7882365a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,9 +43,6 @@ dotnet-uninstall-debian-packages.sh
*.pkg
*.nupkg
-# ignore the version file as it is generated at build time
-powershell.version
-
# ignore the telemetry semaphore file
DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY
diff --git a/PowerShell.Common.props b/PowerShell.Common.props
index 540ff72895c..ccbbd1ea40f 100644
--- a/PowerShell.Common.props
+++ b/PowerShell.Common.props
@@ -31,6 +31,9 @@
$([System.Text.RegularExpressions.Regex]::Match($(PowerShellVersion), $(RegexGitVersion)).Groups[2].Value)
$([System.Text.RegularExpressions.Regex]::Match($(PowerShellVersion), $(RegexGitVersion)).Groups[3].Value)
+
$(PSCoreBuildVersion) SHA: $(PSCoreCommitSHA)
$(PSCoreBuildVersion) Commits: $(PSCoreAdditionalCommits) SHA: $(PSCoreCommitSHA)
diff --git a/build.psm1 b/build.psm1
index ed083524322..3d3000b05fc 100644
--- a/build.psm1
+++ b/build.psm1
@@ -393,14 +393,6 @@ function Start-PSBuild {
}
}
- # save git commit id to file for PowerShell to include in PSVersionTable
- $gitCommitId = $ReleaseTag
- if (-not $gitCommitId) {
- # if ReleaseTag is not specified, use 'git describe' to get the commit id
- $gitCommitId = Get-PSCommitId -WarningAction SilentlyContinue
- }
- $gitCommitId > "$psscriptroot/powershell.version"
-
# create the telemetry flag file
$null = new-item -force -type file "$psscriptroot/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY"
diff --git a/src/System.Management.Automation/engine/PSVersionInfo.cs b/src/System.Management.Automation/engine/PSVersionInfo.cs
index 59002c5a679..07af6f347b9 100644
--- a/src/System.Management.Automation/engine/PSVersionInfo.cs
+++ b/src/System.Management.Automation/engine/PSVersionInfo.cs
@@ -45,7 +45,7 @@ internal class PSVersionInfo
private static Version s_psV4Version = new Version(4, 0);
private static Version s_psV5Version = new Version(5, 0);
private static Version s_psV51Version = new Version(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
- private static SemanticVersion s_psV6Version = new SemanticVersion(6, 0, 0, "beta");
+ private static SemanticVersion s_psV6Version;
///
/// A constant to track current PowerShell Edition
@@ -57,9 +57,38 @@ static PSVersionInfo()
{
s_psVersionTable = new PSVersionHashTable(StringComparer.OrdinalIgnoreCase);
+ string assemblyPath = typeof(PSVersionInfo).Assembly.Location;
+ string productVersion = FileVersionInfo.GetVersionInfo(assemblyPath).ProductVersion;
+
+ // Get 'GitCommitId' and 'PSVersion' from the 'productVersion' assembly attribute.
+ //
+ // The strings can be one of the following format examples:
+ // when powershell is built from a commit:
+ // productVersion = '6.0.0-beta.7 Commits: 29 SHA: 52c6b...' convert to GitCommitId = 'v6.0.0-beta.7-29-g52c6b...'
+ // PSVersion = '6.0.0-beta.7'
+ // when powershell is built from a release tag:
+ // productVersion = '6.0.0-beta.7 SHA: f1ec9...' convert to GitCommitId = 'v6.0.0-beta.7'
+ // PSVersion = '6.0.0-beta.7'
+ // when powershell is built from a release tag for RTM:
+ // productVersion = '6.0.0 SHA: f1ec9...' convert to GitCommitId = 'v6.0.0'
+ // PSVersion = '6.0.0'
+ string rawGitCommitId;
+ string mainVersion = productVersion.Substring(0, productVersion.IndexOf(' '));
+
+ if (productVersion.Contains(" Commits: "))
+ {
+ rawGitCommitId = "v" + productVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g");
+ }
+ else
+ {
+ rawGitCommitId = "v" + mainVersion;
+ }
+
+ s_psV6Version = new SemanticVersion(mainVersion);
+
s_psVersionTable[PSVersionInfo.PSVersionName] = s_psV6Version;
s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue;
- s_psVersionTable[PSGitCommitIdName] = GetCommitInfo();
+ s_psVersionTable[PSGitCommitIdName] = rawGitCommitId;
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version };
s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion);
s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion;
@@ -81,20 +110,6 @@ internal static Hashtable GetPSVersionTableForDownLevel()
return result;
}
- // Get the commit id from the powershell.version file. If the powershell.version file doesn't exist, use the string "N/A"
- internal static string GetCommitInfo()
- {
- try
- {
- string assemblyPath = IO.Path.GetDirectoryName(typeof(PSVersionInfo).GetTypeInfo().Assembly.Location);
- return (IO.File.ReadAllLines(IO.Path.Combine(assemblyPath, "powershell.version"))[0]);
- }
- catch (Exception e)
- {
- return e.Message;
- }
- }
-
#region Private helper methods
// Gets the current WSMan stack version from the registry.
@@ -826,4 +841,4 @@ internal Exception GetVersionParseException()
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs
index c28b7939ddf..5178faa489c 100644
--- a/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs
+++ b/src/System.Management.Automation/engine/remoting/commands/CustomShellCommands.cs
@@ -132,7 +132,7 @@ function Register-PSSessionConfiguration
$pluginWsmanRunAsUserPath = [System.IO.Path]::Combine(""WSMan:\localhost\Plugin"", ""$pluginName"", ""RunAsUser"")
set-item -WarningAction SilentlyContinue $pluginWsmanRunAsUserPath $runAsCredential -confirm:$false
}} catch {{
-
+
remove-item (Join-Path WSMan:\localhost\Plugin ""$pluginName"") -recurse -force
write-error $_
# Do not add anymore clean up code after Write-Error, because if EA=Stop is set by user
@@ -1561,10 +1561,9 @@ internal static string GetRunAsVirtualAccountGroupsString(string[] groups)
internal static string GetWinrmPluginShellName()
{
// PowerShell Core uses a versioned directory to hold the plugin
- Hashtable versionTable = PSVersionInfo.GetPSVersionTable();
// TODO: This should be PSVersionInfo.PSVersionName once we get
// closer to release. Right now it doesn't support alpha versions.
- return System.String.Concat("PowerShell.", (string)versionTable["GitCommitId"]);
+ return System.String.Concat("PowerShell.", PSVersionInfo.GitCommitId);
}
///
@@ -1574,10 +1573,9 @@ internal static string GetWinrmPluginShellName()
internal static string GetWinrmPluginDllPath()
{
// PowerShell Core uses its versioned directory instead of system32
- Hashtable versionTable = PSVersionInfo.GetPSVersionTable();
// TODO: This should be PSVersionInfo.PSVersionName once we get
// closer to release. Right now it doesn't support alpha versions.
- string pluginDllDirectory = System.IO.Path.Combine("%windir%\\system32\\PowerShell", (string)versionTable["GitCommitId"]);
+ string pluginDllDirectory = System.IO.Path.Combine("%windir%\\system32\\PowerShell", PSVersionInfo.GitCommitId);
return System.IO.Path.Combine(pluginDllDirectory, RemotingConstants.PSPluginDLLName);
}
@@ -2555,7 +2553,7 @@ function Unregister-PSSessionConfiguration
return
}}
}}
-
+
$shellsFound++
$shouldProcessTargetString = $targetTemplate -f $_.Name
@@ -2779,12 +2777,12 @@ function ExtractPluginProperties([string]$pluginDir, $objectToWriteTo)
}}
Get-Details $pluginDir $h
-
+
# Workflow is not supported in PowerShell Core. Attempting to load the
# assembly results in a FileNotFoundException.
if (![System.Management.Automation.Platform]::IsCoreCLR -AND
$h[""AssemblyName""] -eq ""Microsoft.PowerShell.Workflow.ServiceCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"") {{
-
+
$serviceCore = [Reflection.Assembly]::Load(""Microsoft.Powershell.Workflow.ServiceCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"")
if ($null -ne $serviceCore) {{
@@ -4967,7 +4965,7 @@ function Enable-PSRemoting
}}
}}
}}
-
+
# remove the 'network deny all' tag
Get-PSSessionConfiguration -Force:$Force | ForEach-Object {{
$sddl = $null
diff --git a/src/powershell-unix/powershell-unix.csproj b/src/powershell-unix/powershell-unix.csproj
index bc83fafcae2..d52667fdb42 100644
--- a/src/powershell-unix/powershell-unix.csproj
+++ b/src/powershell-unix/powershell-unix.csproj
@@ -16,7 +16,7 @@
PreserveNewest
PreserveNewest
-
+
PreserveNewest
PreserveNewest
diff --git a/src/powershell-win-core/powershell-win-core.csproj b/src/powershell-win-core/powershell-win-core.csproj
index 3d19fec1cd0..ce061e85929 100644
--- a/src/powershell-win-core/powershell-win-core.csproj
+++ b/src/powershell-win-core/powershell-win-core.csproj
@@ -19,7 +19,7 @@
PreserveNewest
PreserveNewest
-
+
PreserveNewest
PreserveNewest
diff --git a/test/powershell/Host/PSVersionTable.Tests.ps1 b/test/powershell/Host/PSVersionTable.Tests.ps1
index a9513d4f518..d9ae1f863a4 100644
--- a/test/powershell/Host/PSVersionTable.Tests.ps1
+++ b/test/powershell/Host/PSVersionTable.Tests.ps1
@@ -1,4 +1,27 @@
Describe "PSVersionTable" -Tags "CI" {
+
+ BeforeAll {
+ $sma = Get-Item (Join-Path $PSHome "System.Management.Automation.dll")
+ $formattedVersion = $sma.VersionInfo.ProductVersion
+
+ $mainVersionPattern = "(\d+\.\d+\.\d+)(-.+)?"
+ $fullVersionPattern = "^v(\d+\.\d+\.\d+)-(.+)-(\d+)-g(.+)$"
+
+ $expectedPSVersion = ($formattedVersion -split " ")[0]
+ $expectedVersionPattern = "^$mainVersionPattern$"
+
+ if ($formattedVersion.Contains(" Commits: "))
+ {
+ $rawGitCommitId = "v" + $formattedVersion.Replace(" Commits: ", "-").Replace(" SHA: ", "-g")
+ $expectedGitCommitIdPattern = $fullVersionPattern
+ $unexpectectGitCommitIdPattern = "qwerty"
+ } else {
+ $rawGitCommitId = "v" + ($formattedVersion -split " SHA: ")[0]
+ $expectedGitCommitIdPattern = "^v$mainVersionPattern$"
+ $unexpectectGitCommitIdPattern = $fullVersionPattern
+ }
+ }
+
It "Should have version table entries" {
$PSVersionTable.Count | Should Be 9
}
@@ -15,20 +38,31 @@ Describe "PSVersionTable" -Tags "CI" {
$PSVersionTable.ContainsKey("OS") | Should Be True
}
- It "GitCommitId property should not contain an error" {
- $PSVersionTable.GitCommitId | Should not match "powershell.version"
+
+ It "PSVersion property" {
+ $PSVersionTable.PSVersion | Should BeOfType "System.Management.Automation.SemanticVersion"
+ $PSVersionTable.PSVersion | Should BeExactly $expectedPSVersion
+ $PSVersionTable.PSVersion | Should Match $expectedVersionPattern
+ $PSVersionTable.PSVersion.Major | Should Be 6
+ }
+
+ It "GitCommitId property" {
+ $PSVersionTable.GitCommitId | Should BeOfType "System.String"
+ $PSVersionTable.GitCommitId | Should Match $expectedGitCommitIdPattern
+ $PSVersionTable.GitCommitId | Should Not Match $unexpectectGitCommitIdPattern
+ $PSVersionTable.GitCommitId | Should BeExactly $rawGitCommitId
}
It "Should have the correct platform info" {
$platform = [String][System.Environment]::OSVersion.Platform
- [String]$PSVersionTable["Platform"] | Should Be $platform
+ [String]$PSVersionTable["Platform"] | Should Be $platform
}
It "Should have the correct OS info" {
if ($IsCoreCLR)
{
$OSDescription = [String][System.Runtime.InteropServices.RuntimeInformation]::OSDescription
- [String]$PSVersionTable["OS"] | Should Be $OSDescription
+ [String]$PSVersionTable["OS"] | Should Be $OSDescription
}
else
{