diff --git a/.gitignore b/.gitignore
index befc0d7a24b..214e465ce5b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,9 +39,6 @@ dotnet-uninstall-debian-packages.sh
*.rpm
*.pkg
-# 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/.spelling b/.spelling
index 8c881de6717..174c887cab3 100644
--- a/.spelling
+++ b/.spelling
@@ -840,7 +840,6 @@ Coveralls.io.
Coveralls.net
csmacnz
OpenCover.zip
-powershell.version
Start-CodeCoverageRun
tests.zip
v5.0
diff --git a/build.psm1 b/build.psm1
index 364fea38c58..a907d2151a3 100644
--- a/build.psm1
+++ b/build.psm1
@@ -150,6 +150,42 @@ function Start-PSBuild {
Stop-Process -Verbose
}
+ # Generate version constant for $PSVersionTable
+ function Start-PowerShellVersionGen {
+ $powershellVersion = git --git-dir="$PSScriptRoot/.git" describe --abbrev=60 --long
+ $matchVersion = ([regex]::Match($powershellVersion, "^v(.+)-(\d+)-g(.+)")).Groups.Value
+ $null, $ps6MajorVersion, $ps6MinorVersion, $ps6PatchVersion, $ps6LabelVersion = ([regex]::Match($matchVersion[1], "^(\d+).(\d+).(\d+)-(.+)")).Groups.Value
+ $Global:formattedVersion = "$($matchVersion[1])"
+ if ($($matchVersion[1]) -ne "0") {
+ $Global:formattedVersion += " Additional commits: $($matchVersion[2])"
+ }
+ $Global:formattedVersion += " Commit Hash: $($matchVersion[3])"
+
+ $template = @"
+//------------------------------------------------------------------------------
+//
+// This code was generated by Build.psm1\Start-PSBuild.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+//------------------------------------------------------------------------------
+
+namespace System.Management.Automation
+{
+ internal class GitCommitInfo
+ {
+ internal const string s_GitCommitInfo = "$formattedVersion";
+ internal static readonly SemanticVersion s_psV6Version = new SemanticVersion($ps6MajorVersion, $ps6MinorVersion, $ps6PatchVersion, "$ps6LabelVersion");
+ }
+}
+"@
+
+ Set-Content -Path "$PSScriptRoot\src\System.Management.Automation\gen\PSVersionInfo.generated.cs" -Value $template
+
+ $Global:formattedVersion = $Global:formattedVersion -replace ' ', '%20'
+ }
+
if ($Clean) {
log "Cleaning your working directory. You can also do it with 'git clean -fdX'"
Push-Location $PSScriptRoot
@@ -165,14 +201,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 = git --git-dir="$PSScriptRoot/.git" describe --dirty --abbrev=60
- }
- $gitCommitId > "$psscriptroot/powershell.version"
-
# create the telemetry flag file
$null = new-item -force -type file "$psscriptroot/DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY"
@@ -196,7 +224,7 @@ function Start-PSBuild {
Write-Warning @"
The currently installed .NET Command Line Tools is not the required version.
-Installed version: $dotnetCLIIntalledVersion
+Installed version: $dotnetCLIIntalledVersion
Required version: $dotnetCLIRequiredVersion
Fix steps:
@@ -302,6 +330,14 @@ Fix steps:
Start-ResGen
}
+ # Generate version constant for $PSVersionTable
+ # (Call after 'Start-ResGen'!)
+ Start-PowerShellVersionGen
+
+# $Arguments += "/p:ProductVersion=$formattedVersion;InformationalVersion=$formattedVersion;"
+ $Arguments += "/p:ProductVersion=$formattedVersion;InformationalVersion=$formattedVersion"
+
+
# handle xaml files
# Heuristic to resolve xaml on the fresh machine
if ($FullCLR -and ($XamlGen -or -not (Test-Path "$PSScriptRoot/src/Microsoft.PowerShell.Activities/gen/*.g.cs"))) {
diff --git a/src/Microsoft.Management.Infrastructure.CimCmdlets/Microsoft.Management.Infrastructure.CimCmdlets.csproj b/src/Microsoft.Management.Infrastructure.CimCmdlets/Microsoft.Management.Infrastructure.CimCmdlets.csproj
index 4daa71078a3..f260a609712 100644
--- a/src/Microsoft.Management.Infrastructure.CimCmdlets/Microsoft.Management.Infrastructure.CimCmdlets.csproj
+++ b/src/Microsoft.Management.Infrastructure.CimCmdlets/Microsoft.Management.Infrastructure.CimCmdlets.csproj
@@ -8,6 +8,8 @@
Microsoft.Management.Infrastructure.CimCmdlets
+
+
diff --git a/src/Microsoft.PowerShell.Commands.Diagnostics/Microsoft.PowerShell.Commands.Diagnostics.csproj b/src/Microsoft.PowerShell.Commands.Diagnostics/Microsoft.PowerShell.Commands.Diagnostics.csproj
index e4a845624bc..cb4ca01934a 100644
--- a/src/Microsoft.PowerShell.Commands.Diagnostics/Microsoft.PowerShell.Commands.Diagnostics.csproj
+++ b/src/Microsoft.PowerShell.Commands.Diagnostics/Microsoft.PowerShell.Commands.Diagnostics.csproj
@@ -9,6 +9,8 @@
false
+
+
diff --git a/src/Microsoft.PowerShell.Commands.Management/Microsoft.PowerShell.Commands.Management.csproj b/src/Microsoft.PowerShell.Commands.Management/Microsoft.PowerShell.Commands.Management.csproj
index 2df8b6132a8..f7bb27238ae 100644
--- a/src/Microsoft.PowerShell.Commands.Management/Microsoft.PowerShell.Commands.Management.csproj
+++ b/src/Microsoft.PowerShell.Commands.Management/Microsoft.PowerShell.Commands.Management.csproj
@@ -9,6 +9,8 @@
false
+
+
diff --git a/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj b/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj
index ec8d3a1e391..abb10637952 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj
+++ b/src/Microsoft.PowerShell.Commands.Utility/Microsoft.PowerShell.Commands.Utility.csproj
@@ -9,6 +9,8 @@
false
+
+
diff --git a/src/Microsoft.PowerShell.ConsoleHost/Microsoft.PowerShell.ConsoleHost.csproj b/src/Microsoft.PowerShell.ConsoleHost/Microsoft.PowerShell.ConsoleHost.csproj
index d4db09c8e1c..61f34d062ab 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/Microsoft.PowerShell.ConsoleHost.csproj
+++ b/src/Microsoft.PowerShell.ConsoleHost/Microsoft.PowerShell.ConsoleHost.csproj
@@ -8,6 +8,8 @@
Microsoft.PowerShell.ConsoleHost
+
+
diff --git a/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.csproj b/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.csproj
index 04a453363a8..2d68138643c 100644
--- a/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.csproj
+++ b/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.csproj
@@ -7,6 +7,8 @@
Microsoft.PowerShell.CoreCLR.AssemblyLoadContext
+
+
$(DefineConstants);CORECLR
diff --git a/src/Microsoft.PowerShell.CoreCLR.Eventing/Microsoft.PowerShell.CoreCLR.Eventing.csproj b/src/Microsoft.PowerShell.CoreCLR.Eventing/Microsoft.PowerShell.CoreCLR.Eventing.csproj
index 291c8f1e05b..83bbb2402ed 100644
--- a/src/Microsoft.PowerShell.CoreCLR.Eventing/Microsoft.PowerShell.CoreCLR.Eventing.csproj
+++ b/src/Microsoft.PowerShell.CoreCLR.Eventing/Microsoft.PowerShell.CoreCLR.Eventing.csproj
@@ -8,6 +8,8 @@
Microsoft.PowerShell.CoreCLR.Eventing
+
+
$(DefineConstants);CORECLR
diff --git a/src/Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.csproj b/src/Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.csproj
index fe81a6b4a7e..d40ba074c65 100644
--- a/src/Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.csproj
+++ b/src/Microsoft.PowerShell.LocalAccounts/Microsoft.PowerShell.LocalAccounts.csproj
@@ -8,6 +8,8 @@
false
+
+
diff --git a/src/Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj b/src/Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj
index aee7a367bab..90cbc52e80f 100644
--- a/src/Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj
+++ b/src/Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj
@@ -8,6 +8,8 @@
false
+
+
diff --git a/src/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.csproj b/src/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.csproj
index e5d6ee982c6..e7d042f257e 100644
--- a/src/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.csproj
+++ b/src/Microsoft.PowerShell.Security/Microsoft.PowerShell.Security.csproj
@@ -10,6 +10,8 @@
false
+
+
diff --git a/src/Microsoft.WSMan.Management/Microsoft.WSMan.Management.csproj b/src/Microsoft.WSMan.Management/Microsoft.WSMan.Management.csproj
index a0698b1739d..94c1a1a063b 100644
--- a/src/Microsoft.WSMan.Management/Microsoft.WSMan.Management.csproj
+++ b/src/Microsoft.WSMan.Management/Microsoft.WSMan.Management.csproj
@@ -7,6 +7,8 @@
Microsoft.WSMan.Management
+
+
diff --git a/src/Microsoft.WSMan.Runtime/Microsoft.WSMan.Runtime.csproj b/src/Microsoft.WSMan.Runtime/Microsoft.WSMan.Runtime.csproj
index 205983e5aa4..60aeda9f478 100644
--- a/src/Microsoft.WSMan.Runtime/Microsoft.WSMan.Runtime.csproj
+++ b/src/Microsoft.WSMan.Runtime/Microsoft.WSMan.Runtime.csproj
@@ -7,6 +7,8 @@
Microsoft.WSMan.Runtime
+
+
$(DefineConstants);CORECLR
diff --git a/src/System.Management.Automation/System.Management.Automation.csproj b/src/System.Management.Automation/System.Management.Automation.csproj
index 92ee303d057..a4f838d7b03 100644
--- a/src/System.Management.Automation/System.Management.Automation.csproj
+++ b/src/System.Management.Automation/System.Management.Automation.csproj
@@ -9,6 +9,8 @@
false
+
+
diff --git a/src/System.Management.Automation/engine/PSVersionInfo.cs b/src/System.Management.Automation/engine/PSVersionInfo.cs
index 45a4d17ebe6..415afc15ef7 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 = GitCommitInfo.s_psV6Version;
///
/// A constant to track current PowerShell Edition
@@ -63,7 +63,8 @@ static PSVersionInfo()
s_psVersionTable[PSVersionInfo.PSVersionName] = s_psV6Version;
s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue;
- s_psVersionTable[PSGitCommitIdName] = GetCommitInfo();
+ s_psVersionTable[PSBuildVersionName] = GetBuildVersion();
+ s_psVersionTable[PSGitCommitIdName] = GitCommitInfo.s_GitCommitInfo;
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;
@@ -89,18 +90,11 @@ 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()
+ internal static Version GetBuildVersion()
{
- 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;
- }
+ string assemblyPath = typeof(PSVersionInfo).GetTypeInfo().Assembly.Location;
+ string buildVersion = FileVersionInfo.GetVersionInfo(assemblyPath).FileVersion;
+ return new Version(buildVersion);
}
#region Private helper methods
diff --git a/src/powershell-native/Install-PowerShellRemoting.ps1 b/src/powershell-native/Install-PowerShellRemoting.ps1
index dffe2286942..3ed973395a4 100644
--- a/src/powershell-native/Install-PowerShellRemoting.ps1
+++ b/src/powershell-native/Install-PowerShellRemoting.ps1
@@ -20,7 +20,7 @@ param
[parameter(ParameterSetName = "ByPath")]
[ValidateNotNullOrEmpty()]
[string]
- $PowerShellVersion = "6.0.0-alpha.8"
+ $PowerShellVersion
)
function Register-WinRmPlugin
@@ -130,19 +130,9 @@ else
{
$targetPsHome = $PSHOME
- # Parse the version string from the version file so that users do not have
- # to enter it manually.
- $targetPsVersionFilePath = Join-Path $targetPsHome "Powershell.Version"
- $versionString = (Get-Content $targetPsVersionFilePath).Trim()
- if($versionString.StartsWith("v"))
- {
- $versionString = $versionString.substring(1)
- }
- $index = $versionString.LastIndexOf(".")
- $version = $versionString.Substring(0,$index)
- $revision = $versionString.Substring($index).split("-")
- $version= $version + $revision[0]
- $targetPsVersion = $version
+ # Get the version string from PowerShell so that users do not have to enter it manually.
+ $powershell = Join-Path -Path $targetPsHome -ChildPath "powershell"
+ $targetPsVersion = & $powershell -c "$PSVersionTable.PSVersion.ToString()"
Write-Verbose "Using PowerShell Version: $targetPsVersion" -Verbose
}
diff --git a/src/powershell-unix/powershell-unix.csproj b/src/powershell-unix/powershell-unix.csproj
index 5014a55cd2d..078ac41bc1f 100644
--- a/src/powershell-unix/powershell-unix.csproj
+++ b/src/powershell-unix/powershell-unix.csproj
@@ -9,6 +9,8 @@
ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;debian.8-x64;centos.7-x64;fedora.24-x64;osx.10.11-x64;osx.10.12-x64;opensuse.13.2-x64;opensuse.42.1-x64
+
+
@@ -16,7 +18,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 f468542f464..a91f790d8af 100644
--- a/src/powershell-win-core/powershell-win-core.csproj
+++ b/src/powershell-win-core/powershell-win-core.csproj
@@ -9,6 +9,8 @@
win7-x86;win7-x64;win81-x64;win10-x64
+
+
@@ -20,7 +22,7 @@
PreserveNewest
PreserveNewest
-
+
PreserveNewest
PreserveNewest
diff --git a/src/powershell-win-core/powershell-win-core.targets b/src/powershell-win-core/powershell-win-core.targets
new file mode 100644
index 00000000000..7cf48114004
--- /dev/null
+++ b/src/powershell-win-core/powershell-win-core.targets
@@ -0,0 +1,22 @@
+
+
+ PowerShell Core
+ Microsoft Corporation
+ (c) Microsoft Corporation. All rights reserved.
+
+ 6.0.0.0
+ 6.0.0.0
+
+ netcoreapp2.0
+ true
+ true
+ true
+
+ true
+ ../signing/visualstudiopublic.snk
+ true
+
+
diff --git a/test/powershell/Host/PSVersionTable.Tests.ps1 b/test/powershell/Host/PSVersionTable.Tests.ps1
index a9513d4f518..98ac2f7e5a9 100644
--- a/test/powershell/Host/PSVersionTable.Tests.ps1
+++ b/test/powershell/Host/PSVersionTable.Tests.ps1
@@ -15,8 +15,16 @@ 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 "GitCommitId property" {
+ $PSVersionTable.GitCommitId | Should Not BeNullOrEmpty
+ $PSVersionTable.GitCommitId | Should BeOfType "System.String"
+ $PSVersionTable.GitCommitId | Should Match $PSVersionTable.PSVersion.ToString()
+ }
+
+ It "PSVersion property" {
+ $PSVersionTable.PSVersion | Should BeOfType "System.Management.Automation.SemanticVersion"
+ $PSVersionTable.PSVersion.Major | Should Be 6
}
It "Should have the correct platform info" {