Skip to content
Closed
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 @@ -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

Expand Down
1 change: 0 additions & 1 deletion .spelling
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,6 @@ Coveralls.io.
Coveralls.net
csmacnz
OpenCover.zip
powershell.version
Start-CodeCoverageRun
tests.zip
v5.0
Expand Down
54 changes: 45 additions & 9 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,42 @@ function Start-PSBuild {
Stop-Process -Verbose
}

# Generate version constant for $PSVersionTable
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change in formatting breaks our telemetry

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])"
Copy link
Member

Choose a reason for hiding this comment

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

@JamesWTruher the telemetry you're receiving is from @iSazonov running a build of PowerShell with this (not yet committed to master) change.


$template = @"
//------------------------------------------------------------------------------
// <auto-generated>
// 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.
// </auto-generated>
//------------------------------------------------------------------------------

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
Expand All @@ -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"

Expand All @@ -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:
Expand Down Expand Up @@ -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"))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<AssemblyName>Microsoft.Management.Infrastructure.CimCmdlets</AssemblyName>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\Microsoft.PowerShell.Security\Microsoft.PowerShell.Security.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<AssemblyName>Microsoft.PowerShell.ConsoleHost</AssemblyName>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.3.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<AssemblyName>Microsoft.PowerShell.CoreCLR.AssemblyLoadContext</AssemblyName>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<PropertyGroup>
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<AssemblyName>Microsoft.PowerShell.CoreCLR.Eventing</AssemblyName>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<PropertyGroup>
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<IncludeBuildOutput>false</IncludeBuildOutput>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\Microsoft.PowerShell.Commands.Management\Microsoft.PowerShell.Commands.Management.csproj" />
<ProjectReference Include="..\Microsoft.PowerShell.Commands.Utility\Microsoft.PowerShell.Commands.Utility.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<AssemblyName>Microsoft.WSMan.Management</AssemblyName>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\System.Management.Automation\System.Management.Automation.csproj" />
<ProjectReference Include="..\Microsoft.WSMan.Runtime\Microsoft.WSMan.Runtime.csproj" />
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.WSMan.Runtime/Microsoft.WSMan.Runtime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<AssemblyName>Microsoft.WSMan.Runtime</AssemblyName>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<PropertyGroup>
<DefineConstants>$(DefineConstants);CORECLR</DefineConstants>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<ProjectReference Include="..\Microsoft.PowerShell.CoreCLR.AssemblyLoadContext\Microsoft.PowerShell.CoreCLR.AssemblyLoadContext.csproj" />
<ProjectReference Include="..\Microsoft.PowerShell.CoreCLR.Eventing\Microsoft.PowerShell.CoreCLR.Eventing.csproj" />
Expand Down
20 changes: 7 additions & 13 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 = GitCommitInfo.s_psV6Version;

/// <summary>
/// A constant to track current PowerShell Edition
Expand All @@ -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;
Expand All @@ -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
Expand Down
18 changes: 4 additions & 14 deletions src/powershell-native/Install-PowerShellRemoting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ param
[parameter(ParameterSetName = "ByPath")]
[ValidateNotNullOrEmpty()]
[string]
$PowerShellVersion = "6.0.0-alpha.8"
$PowerShellVersion
)

function Register-WinRmPlugin
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 3 additions & 1 deletion src/powershell-unix/powershell-unix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
<RuntimeIdentifiers>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</RuntimeIdentifiers>
</PropertyGroup>

<Import Project="..\powershell-win-core\powershell-win-core.targets"/>

<ItemGroup>
<Compile Include="..\powershell\Program.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
<Content Include="..\Modules\Unix\**\*;..\Modules\Shared\**\*" Exclude="..\Modules\Shared\Pester\.git*;..\Modules\Shared\Pester\*.yml">
<Link>Modules\%(RecursiveDir)\%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="*.so;*.dylib;..\..\license_thirdparty_proprietary.txt;..\..\powershell.version;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<Content Include="*.so;*.dylib;..\..\license_thirdparty_proprietary.txt;..\..\DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
Expand Down
4 changes: 3 additions & 1 deletion src/powershell-win-core/powershell-win-core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<RuntimeIdentifiers>win7-x86;win7-x64;win81-x64;win10-x64</RuntimeIdentifiers>
</PropertyGroup>

<Import Project="powershell-win-core.targets"/>

<ItemGroup>
<Compile Include="..\powershell\Program.cs" Exclude="bin\**;obj\**;**\*.xproj;packages\**" />
<Content Include="..\System.Management.Automation\PowerShellProperties.json">
Expand All @@ -20,7 +22,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
22 changes: 22 additions & 0 deletions src/powershell-win-core/powershell-win-core.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Product>PowerShell Core</Product>
<Company>Microsoft Corporation</Company>
<Copyright>(c) Microsoft Corporation. All rights reserved.</Copyright>

<FileVersion>6.0.0.0</FileVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<!--
<ProductVersion>6.0.0-beta.1 Additional commits: 1 Commit Hash: 9ebe</ProductVersion>
<InformationalVersion>6.0.0-beta.1 Additional commits: 2 Commit Hash: 59ebe</InformationalVersion>
!-->
<TargetFramework>netcoreapp2.0</TargetFramework>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<DelaySign>true</DelaySign>
<AssemblyOriginatorKeyFile>../signing/visualstudiopublic.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
</Project>
12 changes: 10 additions & 2 deletions test/powershell/Host/PSVersionTable.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down