From 1e20550f5df202cbc2950fd3abf770572ca49478 Mon Sep 17 00:00:00 2001
From: Eric Erhardt <eric.erhardt@microsoft.com>
Date: Thu, 9 Feb 2017 16:25:48 -0600
Subject: [PATCH 1/4] Upgrade update-dependencies script.

- Take the latest VersionTools, so we can take advantage of new features.
- Update what files need to be updated - DependencyVersions.props.
- Clean up the powershell script.
---
 build_projects/update-dependencies/Config.cs  | 10 +--
 build_projects/update-dependencies/Program.cs | 80 +++++++------------
 .../update-dependencies.csproj                | 15 +---
 .../update-dependencies.ps1                   | 20 ++---
 4 files changed, 42 insertions(+), 83 deletions(-)

diff --git a/build_projects/update-dependencies/Config.cs b/build_projects/update-dependencies/Config.cs
index c88680802..3b5df02d6 100644
--- a/build_projects/update-dependencies/Config.cs
+++ b/build_projects/update-dependencies/Config.cs
@@ -17,10 +17,8 @@ namespace Microsoft.DotNet.Scripts
     ///
     /// The following Environment Variables can optionally be specified:
     /// 
-    /// COREFX_VERSION_URL - The Url to get the current CoreFx package versions. (ex. "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/corefx/release/1.0.0")
-    /// CORECLR_VERSION_URL - The Url to get the current CoreCLR version. (ex. "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/coreclr/release/1.0.0")
     /// ROSLYN_VERSION_URL - The Url to get the current Roslyn version. (ex. "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/roslyn/netcore1.0")
-    /// CORESETUP_VERSION_URL - The Url to get the current dotnet/core-setup package versions. (ex. "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/core-setup/release/1.0.0")
+    /// CORESETUP_VERSION_URL - The Url to get the current dotnet/core-setup package versions. (ex. "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/core-setup/master")
     /// GITHUB_ORIGIN_OWNER - The owner of the GitHub fork to push the commit and create the PR from. (ex. "dotnet-bot")
     /// GITHUB_UPSTREAM_OWNER - The owner of the GitHub base repo to create the PR to. (ex. "dotnet")
     /// GITHUB_PROJECT - The repo name under the ORIGIN and UPSTREAM owners. (ex. "cli")
@@ -35,10 +33,8 @@ namespace Microsoft.DotNet.Scripts
         private Lazy<string> _email = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_EMAIL"));
         private Lazy<string> _password = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_PASSWORD"));
         
-        private Lazy<string> _coreFxVersionUrl = new Lazy<string>(() => GetEnvironmentVariable("COREFX_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/corefx/release/1.0.0"));
-        private Lazy<string> _coreClrVersionUrl = new Lazy<string>(() => GetEnvironmentVariable("CORECLR_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/coreclr/release/1.0.0"));
         private Lazy<string> _roslynVersionUrl = new Lazy<string>(() => GetEnvironmentVariable("ROSLYN_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/roslyn/netcore1.0"));
-        private Lazy<string> _coreSetupVersionUrl = new Lazy<string>(() => GetEnvironmentVariable("CORESETUP_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/core-setup/release/1.0.0"));
+        private Lazy<string> _coreSetupVersionUrl = new Lazy<string>(() => GetEnvironmentVariable("CORESETUP_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/core-setup/master"));
         private Lazy<string> _gitHubUpstreamOwner = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_UPSTREAM_OWNER", "dotnet"));
         private Lazy<string> _gitHubProject = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_PROJECT", "cli"));
         private Lazy<string> _gitHubUpstreamBranch = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_UPSTREAM_BRANCH", "rel/1.0.0"));
@@ -53,8 +49,6 @@ namespace Microsoft.DotNet.Scripts
         public string UserName => _userName.Value;
         public string Email => _email.Value; 
         public string Password => _password.Value;
-        public string CoreFxVersionUrl => _coreFxVersionUrl.Value;
-        public string CoreClrVersionUrl => _coreClrVersionUrl.Value;
         public string RoslynVersionUrl => _roslynVersionUrl.Value;
         public string CoreSetupVersionUrl => _coreSetupVersionUrl.Value;
         public string GitHubUpstreamOwner => _gitHubUpstreamOwner.Value;
diff --git a/build_projects/update-dependencies/Program.cs b/build_projects/update-dependencies/Program.cs
index 62dcd0ed5..c3cc79ded 100644
--- a/build_projects/update-dependencies/Program.cs
+++ b/build_projects/update-dependencies/Program.cs
@@ -21,75 +21,57 @@ namespace Microsoft.DotNet.Scripts
         {
             DebugHelper.HandleDebugSwitch(ref args);
 
+            bool onlyUpdate = args.Length > 0 && string.Equals("--Update", args[0], StringComparison.OrdinalIgnoreCase);
+
             List<BuildInfo> buildInfos = new List<BuildInfo>();
 
-            buildInfos.Add(BuildInfo.Get("CoreFx", s_config.CoreFxVersionUrl, fetchLatestReleaseFile: false));
-            buildInfos.Add(BuildInfo.Get("CoreClr", s_config.CoreClrVersionUrl, fetchLatestReleaseFile: false));
             buildInfos.Add(BuildInfo.Get("Roslyn", s_config.RoslynVersionUrl, fetchLatestReleaseFile: false));
             buildInfos.Add(BuildInfo.Get("CoreSetup", s_config.CoreSetupVersionUrl, fetchLatestReleaseFile: false));
 
             IEnumerable<IDependencyUpdater> updaters = GetUpdaters();
+            var dependencyBuildInfos = buildInfos.Select(i =>
+                new DependencyBuildInfo(
+                    i,
+                    upgradeStableVersions: true,
+                    disabledPackages: Enumerable.Empty<string>()));
+            DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(updaters, dependencyBuildInfos);
 
-            GitHubAuth gitHubAuth = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email);
-
-            DependencyUpdater dependencyUpdater = new DependencyUpdater(
-                gitHubAuth,
-                s_config.GitHubProject,
-                s_config.GitHubUpstreamOwner,
-                s_config.GitHubUpstreamBranch,
-                s_config.UserName,
-                s_config.GitHubPullRequestNotifications);
-
-            if (args.Length > 0 && string.Equals("--Update", args[0], StringComparison.OrdinalIgnoreCase))
+            if (updateResults.ChangesDetected() && !onlyUpdate)
             {
-                dependencyUpdater.Update(updaters, buildInfos);
-            }
-            else
-            {
-                dependencyUpdater.UpdateAndSubmitPullRequestAsync(updaters, buildInfos);
+                GitHubAuth gitHubAuth = new GitHubAuth(s_config.Password, s_config.UserName, s_config.Email);
+                GitHubProject origin = new GitHubProject(s_config.GitHubProject, s_config.UserName);
+                GitHubBranch upstreamBranch = new GitHubBranch(
+                    s_config.GitHubUpstreamBranch,
+                    new GitHubProject(s_config.GitHubProject, s_config.GitHubUpstreamOwner));
+
+                string suggestedMessage = updateResults.GetSuggestedCommitMessage();
+                string body = string.Empty;
+                if (s_config.GitHubPullRequestNotifications != null)
+                {
+                    body += PullRequestCreator.NotificationString(s_config.GitHubPullRequestNotifications);
+                }
+
+                new PullRequestCreator(gitHubAuth, origin, upstreamBranch)
+                    .CreateOrUpdateAsync(
+                        suggestedMessage,
+                        suggestedMessage + $" ({upstreamBranch.Name})",
+                        body)
+                    .Wait();
             }
         }
 
         private static IEnumerable<IDependencyUpdater> GetUpdaters()
         {
-            yield return CreateProjectJsonUpdater();
-
-            yield return CreateRegexUpdater(@"build_projects\shared-build-targets-utils\DependencyVersions.cs", "CoreCLRVersion", "Microsoft.NETCore.Runtime.CoreCLR");
-            yield return CreateRegexUpdater(@"build_projects\shared-build-targets-utils\DependencyVersions.cs", "JitVersion", "Microsoft.NETCore.Jit");
-
-            yield return CreateRegexUpdater(@"build_projects\dotnet-cli-build\CliDependencyVersions.cs", "SharedFrameworkVersion", "Microsoft.NETCore.App");
-            yield return CreateRegexUpdater(@"build_projects\dotnet-cli-build\CliDependencyVersions.cs", "HostFxrVersion", "Microsoft.NETCore.DotNetHostResolver");
-            yield return CreateRegexUpdater(@"build_projects\dotnet-cli-build\CliDependencyVersions.cs", "SharedHostVersion", "Microsoft.NETCore.DotNetHost");
+            yield return CreateRegexUpdater(@"build\Microsoft.DotNet.Cli.DependencyVersions.props", "CLI_SharedFrameworkVersion", "Microsoft.NETCore.App");
         }
 
-        private static IDependencyUpdater CreateProjectJsonUpdater()
-        {
-            IEnumerable<string> projectJsonFiles = GetProjectJsonsToUpdate();
-
-            return new ProjectJsonUpdater(projectJsonFiles)
-            {
-                SkipStableVersions = false
-            };
-        }
-
-        private static IEnumerable<string> GetProjectJsonsToUpdate()
-        {
-            const string noUpdateFileName = ".noautoupdate";
-
-            return Enumerable.Union(
-                Directory.GetFiles(Dirs.RepoRoot, "project.json", SearchOption.AllDirectories),
-                Directory.GetFiles(Path.Combine(Dirs.RepoRoot, @"src\dotnet\commands\dotnet-new"), "project.json.template", SearchOption.AllDirectories))
-                .Where(p => !File.Exists(Path.Combine(Path.GetDirectoryName(p), noUpdateFileName)) &&
-                    !Path.GetDirectoryName(p).EndsWith("CSharp_Web", StringComparison.Ordinal));
-        }
-
-        private static IDependencyUpdater CreateRegexUpdater(string repoRelativePath, string dependencyPropertyName, string packageId)
+        private static IDependencyUpdater CreateRegexUpdater(string repoRelativePath, string propertyName, string packageId)
         {
             return new FileRegexPackageUpdater()
             {
                 Path = Path.Combine(Dirs.RepoRoot, repoRelativePath),
                 PackageId = packageId,
-                Regex = new Regex($@"{dependencyPropertyName} = ""(?<version>.*)"";"),
+                Regex = new Regex($@"<{propertyName}>(?<version>.*)</{propertyName}>"),
                 VersionGroupName = "version"
             };
         }
diff --git a/build_projects/update-dependencies/update-dependencies.csproj b/build_projects/update-dependencies/update-dependencies.csproj
index 42c4d52f2..daa3308a1 100644
--- a/build_projects/update-dependencies/update-dependencies.csproj
+++ b/build_projects/update-dependencies/update-dependencies.csproj
@@ -3,10 +3,8 @@
 
   <PropertyGroup>
     <Description>Updates the repos dependencies</Description>
-    <TargetFramework>netcoreapp1.0</TargetFramework>
-    <AssemblyName>update-dependencies</AssemblyName>
     <OutputType>Exe</OutputType>
-    <RuntimeIdentifiers>win7-x64;win7-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.23-x64;opensuse.13.2-x64</RuntimeIdentifiers>
+    <TargetFramework>netcoreapp1.0</TargetFramework>
   </PropertyGroup>
 
   <ItemGroup>
@@ -14,15 +12,8 @@
   </ItemGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.NETCore.App">
-      <Version>1.0.0</Version>
-    </PackageReference>
-    <PackageReference Include="Microsoft.DotNet.VersionTools">
-      <Version>1.0.26-prerelease-00615-07</Version>
-    </PackageReference>
+    <PackageReference Include="Microsoft.NETCore.App" Version="1.0.0" />
+    <PackageReference Include="Microsoft.DotNet.VersionTools" Version="1.0.27-prerelease-01308-02" />
   </ItemGroup>
 
-  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
-    <DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
-  </PropertyGroup>
 </Project>
diff --git a/build_projects/update-dependencies/update-dependencies.ps1 b/build_projects/update-dependencies/update-dependencies.ps1
index 8ed440f64..fbddb081f 100644
--- a/build_projects/update-dependencies/update-dependencies.ps1
+++ b/build_projects/update-dependencies/update-dependencies.ps1
@@ -18,7 +18,7 @@ if($Help)
 $Architecture='x64'
 
 $RepoRoot = "$PSScriptRoot\..\.."
-$AppPath = "$PSScriptRoot"
+$ProjectPath = "$PSScriptRoot\update-dependencies.csproj"
 
 # Use a repo-local install directory (but not the artifacts directory because that gets cleaned a lot
 if (!$env:DOTNET_INSTALL_DIR)
@@ -28,26 +28,18 @@ if (!$env:DOTNET_INSTALL_DIR)
 
 # Install a stage 0
 Write-Host "Installing .NET Core CLI Stage 0"
-& "$RepoRoot\scripts\obtain\dotnet-install.ps1" -Architecture $Architecture
+& "$RepoRoot\scripts\obtain\dotnet-install.ps1" -Channel "master" -Architecture $Architecture
 if($LASTEXITCODE -ne 0) { throw "Failed to install stage0" }
 
 # Put the stage0 on the path
 $env:PATH = "$env:DOTNET_INSTALL_DIR;$env:PATH"
 
 # Restore the app
-Write-Host "Restoring update-dependencies..."
-pushd "$AppPath"
-dotnet restore
+Write-Host "Restoring $ProjectPath..."
+dotnet restore "$ProjectPath"
 if($LASTEXITCODE -ne 0) { throw "Failed to restore" }
-popd
-
-# Publish the app
-Write-Host "Compiling App..."
-dotnet publish "$AppPath" -o "$AppPath\bin" --framework netcoreapp1.0
-if($LASTEXITCODE -ne 0) { throw "Failed to compile build scripts" }
 
 # Run the app
-Write-Host "Invoking App $AppPath..."
-Write-Host " Configuration: $env:CONFIGURATION"
-& "$AppPath\bin\update-dependencies.exe"
+Write-Host "Invoking App $ProjectPath..."
+dotnet run -p "$ProjectPath"
 if($LASTEXITCODE -ne 0) { throw "Build failed" }

From 72af77de1b78a1a16d83dd3f27eb46c3aa5d2b9d Mon Sep 17 00:00:00 2001
From: eerhardt <eric.erhardt@microsoft.com>
Date: Thu, 9 Feb 2017 16:56:32 -0600
Subject: [PATCH 2/4] Update CoreSetup to beta-001509

---
 build/Microsoft.DotNet.Cli.DependencyVersions.props | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build/Microsoft.DotNet.Cli.DependencyVersions.props b/build/Microsoft.DotNet.Cli.DependencyVersions.props
index c073e263d..7550da827 100644
--- a/build/Microsoft.DotNet.Cli.DependencyVersions.props
+++ b/build/Microsoft.DotNet.Cli.DependencyVersions.props
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
-    <CLI_SharedFrameworkVersion>2.0.0-beta-001507-00</CLI_SharedFrameworkVersion>
+    <CLI_SharedFrameworkVersion>2.0.0-beta-001509-00</CLI_SharedFrameworkVersion>
     <CLI_MSBuild_Version>15.2.0-preview-000002-01</CLI_MSBuild_Version>
     <CLI_Roslyn_Version>2.0.0-rc4-61325-08</CLI_Roslyn_Version>
     <CLI_NETSDK_Version>1.0.0-alpha-20170125-1</CLI_NETSDK_Version>

From bee34cc0ffca46d1d9432a38823502f2c1ac5a07 Mon Sep 17 00:00:00 2001
From: jonsequitur <jonsequeira@gmail.com>
Date: Thu, 9 Feb 2017 18:28:34 -0800
Subject: [PATCH 3/4] remove redundant word 'create'

---
 src/Microsoft.DotNet.Configurer/LocalizableStrings.cs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Microsoft.DotNet.Configurer/LocalizableStrings.cs b/src/Microsoft.DotNet.Configurer/LocalizableStrings.cs
index 0bb19cc55..5e5ec9d3b 100644
--- a/src/Microsoft.DotNet.Configurer/LocalizableStrings.cs
+++ b/src/Microsoft.DotNet.Configurer/LocalizableStrings.cs
@@ -19,6 +19,6 @@ Configuring...
 -------------------
 A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.";
 
-        public const string FailedToPrimeCacheError = "Failed to create prime the NuGet cache. {0} failed with: {1}";
+        public const string FailedToPrimeCacheError = "Failed to prime the NuGet cache. {0} failed with: {1}";
     }
 }
\ No newline at end of file

From 31ff72e62d9c1293222d876631a155e77db8ed67 Mon Sep 17 00:00:00 2001
From: Eric Erhardt <eric.erhardt@microsoft.com>
Date: Fri, 10 Feb 2017 11:32:22 -0600
Subject: [PATCH 4/4] Respond to PR feedback.

---
 build_projects/update-dependencies/Config.cs  | 4 ++--
 build_projects/update-dependencies/Program.cs | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/build_projects/update-dependencies/Config.cs b/build_projects/update-dependencies/Config.cs
index 3b5df02d6..7f020bfeb 100644
--- a/build_projects/update-dependencies/Config.cs
+++ b/build_projects/update-dependencies/Config.cs
@@ -22,7 +22,7 @@ namespace Microsoft.DotNet.Scripts
     /// GITHUB_ORIGIN_OWNER - The owner of the GitHub fork to push the commit and create the PR from. (ex. "dotnet-bot")
     /// GITHUB_UPSTREAM_OWNER - The owner of the GitHub base repo to create the PR to. (ex. "dotnet")
     /// GITHUB_PROJECT - The repo name under the ORIGIN and UPSTREAM owners. (ex. "cli")
-    /// GITHUB_UPSTREAM_BRANCH - The branch in the GitHub base repo to create the PR to. (ex. "rel/1.0.0")
+    /// GITHUB_UPSTREAM_BRANCH - The branch in the GitHub base repo to create the PR to. (ex. "master")
     /// GITHUB_PULL_REQUEST_NOTIFICATIONS - A semi-colon ';' separated list of GitHub users to notify on the PR.
     /// </remarks>
     public class Config
@@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Scripts
         private Lazy<string> _coreSetupVersionUrl = new Lazy<string>(() => GetEnvironmentVariable("CORESETUP_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/build-info/dotnet/core-setup/master"));
         private Lazy<string> _gitHubUpstreamOwner = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_UPSTREAM_OWNER", "dotnet"));
         private Lazy<string> _gitHubProject = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_PROJECT", "cli"));
-        private Lazy<string> _gitHubUpstreamBranch = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_UPSTREAM_BRANCH", "rel/1.0.0"));
+        private Lazy<string> _gitHubUpstreamBranch = new Lazy<string>(() => GetEnvironmentVariable("GITHUB_UPSTREAM_BRANCH", "master"));
         private Lazy<string[]> _gitHubPullRequestNotifications = new Lazy<string[]>(() => 
                                                 GetEnvironmentVariable("GITHUB_PULL_REQUEST_NOTIFICATIONS", "")
                                                     .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
diff --git a/build_projects/update-dependencies/Program.cs b/build_projects/update-dependencies/Program.cs
index c3cc79ded..a10692bed 100644
--- a/build_projects/update-dependencies/Program.cs
+++ b/build_projects/update-dependencies/Program.cs
@@ -29,9 +29,9 @@ namespace Microsoft.DotNet.Scripts
             buildInfos.Add(BuildInfo.Get("CoreSetup", s_config.CoreSetupVersionUrl, fetchLatestReleaseFile: false));
 
             IEnumerable<IDependencyUpdater> updaters = GetUpdaters();
-            var dependencyBuildInfos = buildInfos.Select(i =>
+            var dependencyBuildInfos = buildInfos.Select(buildInfo =>
                 new DependencyBuildInfo(
-                    i,
+                    buildInfo,
                     upgradeStableVersions: true,
                     disabledPackages: Enumerable.Empty<string>()));
             DependencyUpdateResults updateResults = DependencyUpdateUtils.Update(updaters, dependencyBuildInfos);
@@ -46,7 +46,7 @@ namespace Microsoft.DotNet.Scripts
 
                 string suggestedMessage = updateResults.GetSuggestedCommitMessage();
                 string body = string.Empty;
-                if (s_config.GitHubPullRequestNotifications != null)
+                if (s_config.GitHubPullRequestNotifications.Any())
                 {
                     body += PullRequestCreator.NotificationString(s_config.GitHubPullRequestNotifications);
                 }