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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions PowerShell.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<PSCoreAdditionalCommits>$([System.Text.RegularExpressions.Regex]::Match($(PowerShellVersion), $(RegexGitVersion)).Groups[2].Value)</PSCoreAdditionalCommits>
<PSCoreCommitSHA>$([System.Text.RegularExpressions.Regex]::Match($(PowerShellVersion), $(RegexGitVersion)).Groups[3].Value)</PSCoreCommitSHA>

<!--
Caution! 'PSVersion' and 'GitCommitId' from 'PSVersionInfo.cs' depend on the format of this version string.
-->
<PSCoreFormattedVersion Condition = "'$(ReleaseTag)' != '' or '$(PSCoreAdditionalCommits)' == '0'">$(PSCoreBuildVersion) SHA: $(PSCoreCommitSHA)</PSCoreFormattedVersion>
<PSCoreFormattedVersion Condition = "'$(PSCoreFormattedVersion)' == ''">$(PSCoreBuildVersion) Commits: $(PSCoreAdditionalCommits) SHA: $(PSCoreCommitSHA)</PSCoreFormattedVersion>

Expand Down
8 changes: 0 additions & 8 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to remove powershell.version from .gitignore as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

# create the telemetry flag file
$null = new-item -force -type file "$psscriptroot/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY"

Expand Down
49 changes: 32 additions & 17 deletions src/System.Management.Automation/engine/PSVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// A constant to track current PowerShell Edition
Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -826,4 +841,4 @@ internal Exception GetVersionParseException()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand All @@ -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);
}

Expand Down Expand Up @@ -2555,7 +2553,7 @@ function Unregister-PSSessionConfiguration
return
}}
}}

$shellsFound++

$shouldProcessTargetString = $targetTemplate -f $_.Name
Expand Down Expand Up @@ -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) {{
Expand Down Expand Up @@ -4967,7 +4965,7 @@ function Enable-PSRemoting
}}
}}
}}

# remove the 'network deny all' tag
Get-PSSessionConfiguration -Force:$Force | ForEach-Object {{
$sddl = $null
Expand Down
2 changes: 1 addition & 1 deletion src/powershell-unix/powershell-unix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
Expand Down
2 changes: 1 addition & 1 deletion src/powershell-win-core/powershell-win-core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<Content Include="..\..\license_thirdparty_proprietary.txt;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
Expand Down
42 changes: 38 additions & 4 deletions test/powershell/Host/PSVersionTable.Tests.ps1
Original file line number Diff line number Diff line change
@@ -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
}
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not match test case is not necessary IMO since you are doing a BeExactly comparison below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do two checks - 1. for string values (line below). 2. for regex patterns (this line).
I split regex patterns to check GitCommitId and ReleaseTag cases and keep the patterns simple. The double "Should" is needed because ReleaseTag pattern can pass GitCommitId.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the point. It's to guarantee that the reconstructed rawGitCommitId to be in the expected regx pattern. #Close

$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
{
Expand Down