Skip to content
88 changes: 87 additions & 1 deletion PowerShell.Common.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,95 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!--
The 'version' property is populated with the default value in 'Microsoft.NET.DefaultAssemblyInfo.targets'
*before* any targets get a chance to execute.
We need to *explicitly* re-assign the 'version' property and other version tags in this target.

In order for the versions assigned here to take effect, we need to execute this target at an early stage:
before 'Restore' target - '_GenerateRestoreProjectSpec'
before 'Pack' target - 'GenerateNuspec'
before 'Build' target - 'BeforeBuild'
-->
<Target Name="GetPSCoreVersionFromGit"
BeforeTargets="_GenerateRestoreProjectSpec;GenerateNuspec;BeforeBuild"
>

<Exec Command='git describe --abbrev=60 --long'
WorkingDirectory="$(MSBuildProjectDirectory)"
ConsoleToMSBuild="true"
StandardOutputImportance="Low">
<Output TaskParameter="ConsoleOutput" PropertyName="PowerShellVersion" />
</Exec>

<PropertyGroup Condition = "'$(ReleaseTag)' != ''">
<PSCoreBuildVersion>$(ReleaseTag)</PSCoreBuildVersion>
</PropertyGroup>

<PropertyGroup>
<RegexGitVersion>^v(.+)-(\d+)-g(.+)</RegexGitVersion>
<PSCoreBuildVersion Condition = "'$(PSCoreBuildVersion)' == ''">$([System.Text.RegularExpressions.Regex]::Match($(PowerShellVersion), $(RegexGitVersion)).Groups[1].Value)</PSCoreBuildVersion>
<PSCoreAdditionalCommits>$([System.Text.RegularExpressions.Regex]::Match($(PowerShellVersion), $(RegexGitVersion)).Groups[2].Value)</PSCoreAdditionalCommits>
<PSCoreCommitSHA>$([System.Text.RegularExpressions.Regex]::Match($(PowerShellVersion), $(RegexGitVersion)).Groups[3].Value)</PSCoreCommitSHA>

<PSCoreFormattedVersion Condition = "'$(ReleaseTag)' != '' or '$(PSCoreAdditionalCommits)' == '0'">$(PSCoreBuildVersion) SHA: $(PSCoreCommitSHA)</PSCoreFormattedVersion>
<PSCoreFormattedVersion Condition = "'$(PSCoreFormattedVersion)' == ''">$(PSCoreBuildVersion) Commits: $(PSCoreAdditionalCommits) SHA: $(PSCoreCommitSHA)</PSCoreFormattedVersion>

<!-- Extract the major, minor and patch version numbers, as well as the preview label.
They are currently not used anywhere, so we comment them out for now.
<RegexSymVer>^((\d+).(\d+).(\d+))(?:-(.+))?</RegexSymVer>
<PSCorePrefixVersion>$([System.Text.RegularExpressions.Regex]::Match($(PSCoreBuildVersion), $(RegexSymVer)).Groups[1].Value)</PSCorePrefixVersion>
<PSCoreMajorVersion>$([System.Text.RegularExpressions.Regex]::Match($(PSCoreBuildVersion), $(RegexSymVer)).Groups[2].Value)</PSCoreMajorVersion>
<PSCoreMinorVersion>$([System.Text.RegularExpressions.Regex]::Match($(PSCoreBuildVersion), $(RegexSymVer)).Groups[3].Value)</PSCoreMinorVersion>
<PSCorePatchVersion>$([System.Text.RegularExpressions.Regex]::Match($(PSCoreBuildVersion), $(RegexSymVer)).Groups[4].Value)</PSCorePatchVersion>
<PSCoreLabelVersion>$([System.Text.RegularExpressions.Regex]::Match($(PSCoreBuildVersion), $(RegexSymVer)).Groups[5].Value)</PSCoreLabelVersion>
-->

<!--
Here we define explicitly 'Version' to set 'FileVersion' and 'AssemblyVersion' by 'GetAssemblyVersion' target in 'Microsoft.NET.GenerateAssemblyInfo.targets'.
Here we define explicitly 'InformationalVersion' because by default it is defined as 'Version' by 'GetAssemblyVersion' target in 'Microsoft.NET.GenerateAssemblyInfo.targets'.
-->
<Version>$(PSCoreBuildVersion)</Version>
<InformationalVersion>$(PSCoreFormattedVersion)</InformationalVersion>
<ProductVersion>$(PSCoreFormattedVersion)</ProductVersion>

<!--
We have explicitly assign 'PackageVersion'
because there is a bug: 'PackageVersion' is correctly assigned as 'Version' in 'NuGet.targets'
but then immediately redefined as '1.0.0'.
Copy link
Member

Choose a reason for hiding this comment

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

Do you have an issue tracking this bug? Better put the issue number here 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.

I don't open an Issue. What is right place?

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/dotnet/sdk should be the place for dotnet msbuild issues.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks! Issue dotnet/sdk#1557

Copy link
Member

@daxian-dbw daxian-dbw Aug 31, 2017

Choose a reason for hiding this comment

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

Thank you! #Closed

Tracking Issue https://github.com/dotnet/sdk/issues/1557
-->
<PackageVersion>$(PSCoreBuildVersion)</PackageVersion>

</PropertyGroup>

<!-- Output For Debugging
<WriteLinesToFile File="targetfile1.txt"
Lines="ReleaseTag=$(ReleaseTag);
PowerShellVersion=$(PowerShellVersion);
PSCoreBuildVersion = $(PSCoreBuildVersion);
PSCoreAdditionalCommits = $(PSCoreAdditionalCommits);
PSCoreCommitSHA = $(PSCoreCommitSHA);
PSCoreMajorVersion = $(PSCoreMajorVersion);
PSCoreMinorVersion = $(PSCoreMinorVersion);
PSCorePatchVersion = $(PSCorePatchVersion);
PSCoreLabelVersion = $(PSCoreLabelVersion);
RegexGitVersion = $(RegexGitVersion);
PSCoreFormattedVersion = $(PSCoreFormattedVersion);
ProductVersion = $(ProductVersion);
Version = $(Version);
ProjectVersion = '!$(ProjectVersion)!'
InformationalVersion = $(InformationalVersion);
"
Overwrite="true" />
-->

</Target>

<PropertyGroup>
<Product>PowerShell Core</Product>
<Company>Microsoft Corporation</Company>
<Copyright>(c) Microsoft Corporation. All rights reserved.</Copyright>

<VersionPrefix>6.0.0</VersionPrefix>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>

Expand All @@ -17,4 +102,5 @@
<AssemblyOriginatorKeyFile>../signing/visualstudiopublic.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
</PropertyGroup>

</Project>
35 changes: 23 additions & 12 deletions build.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ function Sync-PSTags
# Gets the latest tag for the current branch
function Get-PSLatestTag
{
[CmdletBinding()]
param()
# This function won't always return the correct value unless tags have been sync'ed
# So, Write a warning to run Sync-PSTags
if(!$tagsUpToDate)
Expand All @@ -63,6 +65,7 @@ function Get-PSLatestTag

function Get-PSVersion
{
[CmdletBinding()]
param(
[switch]
$OmitCommitId
Expand All @@ -79,6 +82,8 @@ function Get-PSVersion

function Get-PSCommitId
{
[CmdletBinding()]
param()
# This function won't always return the correct value unless tags have been sync'ed
# So, Write a warning to run Sync-PSTags
if(!$tagsUpToDate)
Expand Down Expand Up @@ -339,7 +344,7 @@ function Start-PSBuild {
$gitCommitId = $ReleaseTag
if (-not $gitCommitId) {
# if ReleaseTag is not specified, use 'git describe' to get the commit id
$gitCommitId = Get-PSCommitId
$gitCommitId = Get-PSCommitId -WarningAction SilentlyContinue
}
$gitCommitId > "$psscriptroot/powershell.version"

Expand Down Expand Up @@ -416,6 +421,11 @@ Fix steps:
$Arguments += "--runtime", $Options.Runtime
}

if ($ReleaseTag) {
$ReleaseTagToUse = $ReleaseTag -Replace '^v'
$Arguments += "/property:ReleaseTag=$ReleaseTagToUse"
}

# handle Restore
if ($Restore -or -not (Test-Path "$($Options.Top)/obj/project.assets.json")) {
log "Run dotnet restore"
Expand Down Expand Up @@ -1320,20 +1330,21 @@ function Publish-NuGetFeed
{
param(
[string]$OutputPath = "$PSScriptRoot/nuget-artifacts",
[Parameter(Mandatory=$true)]
[string]$VersionSuffix
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+\.\d+)?$")]
[ValidateNotNullOrEmpty()]
[string]$ReleaseTag
)

# Add .NET CLI tools to PATH
Find-Dotnet

if ($VersionSuffix) {
## NuGet/Home #3953, #4337 -- dotnet pack - version suffix missing from ProjectReference
## Workaround:
## dotnet restore /p:VersionSuffix=<suffix> # Bake the suffix into project.assets.json
## dotnet pack --version-suffix <suffix>
$TopProject = (New-PSOptions).Top
dotnet restore $TopProject "/p:VersionSuffix=$VersionSuffix"
## We update 'project.assets.json' files with new version tag value by 'GetPSCoreVersionFromGit' target.
$TopProject = (New-PSOptions).Top
if ($ReleaseTag) {
$ReleaseTagToUse = $ReleaseTag -Replace '^v'
dotnet restore $TopProject "/property:ReleaseTag=$ReleaseTagToUse"
} else {
dotnet restore $TopProject
}

try {
Expand All @@ -1351,8 +1362,8 @@ function Publish-NuGetFeed
'Microsoft.WSMan.Runtime',
'Microsoft.PowerShell.SDK'
) | ForEach-Object {
if ($VersionSuffix) {
dotnet pack "src/$_" --output $OutputPath --version-suffix $VersionSuffix /p:IncludeSymbols=true
if ($ReleaseTag) {
dotnet pack "src/$_" --output $OutputPath "/property:IncludeSymbols=true;ReleaseTag=$ReleaseTagToUse"
} else {
dotnet pack "src/$_" --output $OutputPath
}
Expand Down
19 changes: 10 additions & 9 deletions tools/appveyor.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Function Test-DailyBuild
{
return $true
}

# if [Feature] is in the commit message,
# Run Daily tests
if($env:APPVEYOR_REPO_COMMIT_MESSAGE -match '\[feature\]')
Expand Down Expand Up @@ -208,7 +208,6 @@ function Invoke-AppVeyorInstall
}
elseif($env:APPVEYOR_REPO_COMMIT_MESSAGE -notmatch '^\[Daily\].*$')
{

$buildName += $env:APPVEYOR_REPO_COMMIT_MESSAGE
}
else
Expand Down Expand Up @@ -451,24 +450,26 @@ function Invoke-AppveyorFinish

if ($env:APPVEYOR_REPO_TAG_NAME)
{
# ignore the first part of semver, use the preview part
$preReleaseVersion = ($env:APPVEYOR_REPO_TAG_NAME).Split('-')[1]
$preReleaseVersion = $env:APPVEYOR_REPO_TAG_NAME
}
else
{
$previewLabel = (git describe --abbrev=0).Split('-')[1].replace('.','')
$previewVersion = (git describe --abbrev=0).Split('-')
$previewPrefix = $previewVersion[0]
$previewLabel = $previewVersion[1].replace('.','')

if(Test-DailyBuild)
{
$previewLabel= "daily-{0}" -f $previewLabel
$previewLabel= "daily{0}" -f $previewLabel
}

$preReleaseVersion = "$previewLabel-$($env:APPVEYOR_BUILD_NUMBER.replace('.','-'))"
$preReleaseVersion = "$previewPrefix-$previewLabel.$env:APPVEYOR_BUILD_NUMBER"
}

# only publish to nuget feed if it is a daily build and tests passed
if((Test-DailyBuild) -and $env:TestPassed -eq 'True')
{
Publish-NuGetFeed -OutputPath .\nuget-artifacts -VersionSuffix $preReleaseVersion
Publish-NuGetFeed -OutputPath .\nuget-artifacts -ReleaseTag $preReleaseVersion
}

$nugetArtifacts = Get-ChildItem .\nuget-artifacts -ErrorAction SilentlyContinue | ForEach-Object { $_.FullName }
Expand Down Expand Up @@ -498,7 +499,7 @@ function Invoke-AppveyorFinish
{
log "pushing $_ to $env:NUGET_URL"
Start-NativeExecution -sb {dotnet nuget push $_ --api-key $env:NUGET_KEY --source "$env:NUGET_URL/api/v2/package"} -IgnoreExitcode
}
}
}
if(!$pushedAllArtifacts)
{
Expand Down