From 5fae89b96249d17bb758fa19cca3f890aa7aa9d4 Mon Sep 17 00:00:00 2001
From: Nate McMaster <natemcmaster@users.noreply.github.com>
Date: Tue, 30 Jan 2018 10:38:09 -0800
Subject: [PATCH] Update versions to include prodcon build id (#819)

* Update versions to include prodcon build id
* Ensure version metadata does not appear in the package version
* Update build tools
---
 build/repo.targets |  2 +-
 korebuild-lock.txt |  4 ++--
 korebuild.json     |  2 +-
 run.ps1            |  8 ++++++++
 run.sh             | 12 ++++++++++++
 version.props      | 24 ++++++++++++++++++++----
 6 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/build/repo.targets b/build/repo.targets
index 3285a78ab14..02cf9ad6392 100644
--- a/build/repo.targets
+++ b/build/repo.targets
@@ -15,7 +15,7 @@
     <GeneratedPackageVersionPropsPath>$(IntermediateDir)dependencies.g.props</GeneratedPackageVersionPropsPath>
     <GeneratedRestoreSourcesPropsPath>$(IntermediateDir)sources.g.props</GeneratedRestoreSourcesPropsPath>
 
-    <PrepareDependsOn>$(PrepareDependsOn);VerifyPackageArtifactConfig;PrepareOutputPaths</PrepareDependsOn>
+    <PrepareDependsOn>SetTeamCityBuildNumberToVersion;$(PrepareDependsOn);VerifyPackageArtifactConfig;PrepareOutputPaths</PrepareDependsOn>
     <CleanDependsOn>$(CleanDependsOn);CleanArtifacts;CleanUniverseArtifacts</CleanDependsOn>
     <RestoreDependsOn>$(RestoreDependsOn);InstallDotNet;RestoreExternalDependencies</RestoreDependsOn>
     <CompileDependsOn>$(CompileDependsOn);BuildRepositories</CompileDependsOn>
diff --git a/korebuild-lock.txt b/korebuild-lock.txt
index 1ae5d69845e..207e91b0f9f 100644
--- a/korebuild-lock.txt
+++ b/korebuild-lock.txt
@@ -1,2 +1,2 @@
-version:2.1.0-preview2-15684
-commithash:308af8e3279892aad7f189ffbddd3ff9a60970d3
+version:2.1.0-preview1-1008
+commithash:e82dffbe8cf67ad9c07b4385cb6a1a1fc8be9fb1
diff --git a/korebuild.json b/korebuild.json
index bd5d51a51b0..13e865430d3 100644
--- a/korebuild.json
+++ b/korebuild.json
@@ -1,4 +1,4 @@
 {
   "$schema": "https://raw.githubusercontent.com/aspnet/BuildTools/dev/tools/korebuild.schema.json",
-  "channel": "dev"
+  "channel": "release/2.1"
 }
diff --git a/run.ps1 b/run.ps1
index cab9fbe6e70..29f826e9aa8 100644
--- a/run.ps1
+++ b/run.ps1
@@ -44,6 +44,9 @@ The path to the configuration file that stores values. Defaults to korebuild.jso
 .PARAMETER RestoreSources
 (optional) Semi-colon delimited list of additional NuGet feeds to use as part of restore.
 
+.PARAMETER ProductBuildId
+(optional) The product build ID for correlation with orchestrated builds.
+
 .PARAMETER MSBuildArguments
 Additional MSBuild arguments to be passed through.
 
@@ -83,6 +86,7 @@ param(
     [string]$AccessTokenSuffix = $null,
     [string]$RestoreSources = $null,
     [string]$AssetRootUrl = $null,
+    [string]$ProductBuildId = $null,
     [Parameter(ValueFromRemainingArguments = $true)]
     [string[]]$MSBuildArguments
 )
@@ -221,6 +225,10 @@ if ($AccessTokenSuffix) {
     $MSBuildArguments += "-p:DotNetAssetRootAccessTokenSuffix=$AccessTokenSuffix"
 }
 
+if ($ProductBuildId) {
+    $MSBuildArguments += "-p:DotNetProductBuildId=$ProductBuildId"
+}
+
 # Execute
 
 $korebuildPath = Get-KoreBuild
diff --git a/run.sh b/run.sh
index 8f861cf149f..2be18220d0f 100755
--- a/run.sh
+++ b/run.sh
@@ -22,6 +22,7 @@ package_version_props_url=''
 asset_root_url=''
 access_token_suffix=''
 restore_sources=''
+product_build_id=''
 msbuild_args=()
 
 #
@@ -44,6 +45,7 @@ __usage() {
     echo "    --package-version-props-url <URL>         The url of the package versions props path containing dependency versions."
     echo "    --access-token <Token>                    The query string to append to any blob store access for PackageVersionPropsUrl, if any."
     echo "    --restore-sources <Sources>               Semi-colon delimited list of additional NuGet feeds to use as part of restore."
+    echo "    --product-build-id <ID>                   The product build ID for correlation with orchestrated builds."
     echo "    -u|--update                               Update to the latest KoreBuild even if the lock file is present."
     echo "    --reinstall                               Reinstall KoreBuild."
     echo ""
@@ -202,6 +204,12 @@ while [[ $# -gt 0 ]]; do
             [ -z "${1+x}" ] && __error "Missing value for parameter --asset-root-url" && __usage
             asset_root_url="$1"
             ;;
+        --product-build-id|-ProductBuildId)
+            shift
+            # This parameter can be an empty string, but it should be set
+            [ -z "${1+x}" ] && __error "Missing value for parameter --product-build-id" && __usage
+            product_build_id="$1"
+            ;;
         -u|--update|-Update)
             update=true
             ;;
@@ -272,6 +280,10 @@ if [ ! -z "$access_token_suffix" ]; then
     msbuild_args[${#msbuild_args[*]}]="-p:DotNetAssetRootAccessTokenSuffix=$access_token_suffix"
 fi
 
+if [ ! -z "$product_build_id" ]; then
+    msbuild_args[${#msbuild_args[*]}]="-p:DotNetProductBuildId=$product_build_id"
+fi
+
 [ -z "$channel" ] && channel='dev'
 [ -z "$tools_source" ] && tools_source='https://aspnetcore.blob.core.windows.net/buildtools'
 
diff --git a/version.props b/version.props
index fefaa33964f..950b5611e7b 100644
--- a/version.props
+++ b/version.props
@@ -2,12 +2,28 @@
   <PropertyGroup>
     <VersionPrefix>2.1.0</VersionPrefix>
     <VersionSuffix>preview1</VersionSuffix>
+
     <ExperimentalVersionPrefix>0.1.0</ExperimentalVersionPrefix>
     <ExperimentalVersionSuffix>alpha1</ExperimentalVersionSuffix>
-    <PackageVersion Condition="'$(IsFinalBuild)' == 'true' AND '$(VersionSuffix)' == 'rtm' ">$(VersionPrefix)</PackageVersion>
-    <PackageVersion Condition="'$(IsFinalBuild)' == 'true' AND '$(VersionSuffix)' != 'rtm' ">$(VersionPrefix)-$(VersionSuffix)-final</PackageVersion>
-    <ExperimentalPackageVersion Condition="'$(IsFinalBuild)' == 'true'">$(ExperimentalVersionPrefix)-$(ExperimentalVersionSuffix)-final</ExperimentalPackageVersion>
-    <VersionSuffix Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' != ''">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
+
+
+    <PackageVersion Condition=" '$(IsFinalBuild)' == 'true' AND '$(VersionSuffix)' == 'rtm' ">$(VersionPrefix)</PackageVersion>
+    <PackageVersion Condition=" '$(IsFinalBuild)' == 'true' AND '$(VersionSuffix)' != 'rtm' ">$(VersionPrefix)-$(VersionSuffix)-final</PackageVersion>
+
+    <VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
+
+    <PackageVersion Condition=" '$(IsFinalBuild)' != 'true' ">$(VersionPrefix)</PackageVersion>
+    <PackageVersion Condition=" '$(IsFinalBuild)' != 'true' AND '$(VersionSuffix)' != '' ">$(VersionPrefix)-$(VersionSuffix)</PackageVersion>
+
+    <!-- Add metadata to the suffix last so it does not appear in package versions. -->
+    <VersionMetadata Condition=" '$(DotNetProductBuildId)' != '' ">pb-$(DotNetProductBuildId)</VersionMetadata>
+    <VersionSuffix Condition=" '$(VersionSuffix)' != '' AND '$(VersionMetadata)' != '' ">$(VersionSuffix)+$(VersionMetadata)</VersionSuffix>
+
+    <ExperimentalPackageVersion Condition=" '$(IsFinalBuild)' == 'true' AND '$(ExperimentalVersionSuffix)' == 'rtm' ">$(ExperimentalVersionPrefix)</ExperimentalPackageVersion>
+    <ExperimentalPackageVersion Condition=" '$(IsFinalBuild)' == 'true' AND '$(ExperimentalVersionSuffix)' != 'rtm' ">$(ExperimentalVersionPrefix)-$(ExperimentalVersionSuffix)-final</ExperimentalPackageVersion>
+    <ExperimentalVersionSuffix Condition=" '$(ExperimentalVersionSuffix)' != '' AND '$(BuildNumber)' != '' ">$(ExperimentalVersionSuffix)-$(BuildNumber)</ExperimentalVersionSuffix>
+
     <SharedFxCliBlobChannel>release/2.1</SharedFxCliBlobChannel>
   </PropertyGroup>
+
 </Project>
-- 
GitLab