diff --git a/build_projects/update-dependencies/Config.cs b/build_projects/update-dependencies/Config.cs index e9c08ac10..9938cce68 100644 --- a/build_projects/update-dependencies/Config.cs +++ b/build_projects/update-dependencies/Config.cs @@ -2,6 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.IO; +using System.Linq; +using System.Xml.Linq; namespace Microsoft.DotNet.Scripts { @@ -35,11 +38,10 @@ namespace Microsoft.DotNet.Scripts private Lazy _password = new Lazy(() => GetEnvironmentVariable("GITHUB_PASSWORD")); private Lazy _dotNetVersionUrl = new Lazy(() => GetEnvironmentVariable("DOTNET_VERSION_URL", "https://raw.githubusercontent.com/dotnet/versions/master/build-info")); - private Lazy _roslynVersionFragment = new Lazy(() => GetEnvironmentVariable("ROSLYN_VERSION_FRAGMENT", "dotnet/roslyn/netcore1.0")); - private Lazy _coreSetupVersionFragment = new Lazy(() => GetEnvironmentVariable("CORESETUP_VERSION_FRAGMENT", "dotnet/core-setup/master")); + private Lazy _coreSetupVersionFragment = new Lazy(() => GetEnvironmentVariable("CORESETUP_VERSION_FRAGMENT", GetDefaultCoreSetupVersionFragment())); private Lazy _gitHubUpstreamOwner = new Lazy(() => GetEnvironmentVariable("GITHUB_UPSTREAM_OWNER", "dotnet")); private Lazy _gitHubProject = new Lazy(() => GetEnvironmentVariable("GITHUB_PROJECT", "cli")); - private Lazy _gitHubUpstreamBranch = new Lazy(() => GetEnvironmentVariable("GITHUB_UPSTREAM_BRANCH", "master")); + private Lazy _gitHubUpstreamBranch = new Lazy(() => GetEnvironmentVariable("GITHUB_UPSTREAM_BRANCH", GetDefaultUpstreamBranch())); private Lazy _gitHubPullRequestNotifications = new Lazy(() => GetEnvironmentVariable("GITHUB_PULL_REQUEST_NOTIFICATIONS", "") .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)); @@ -51,7 +53,6 @@ namespace Microsoft.DotNet.Scripts public string Email => _email.Value; public string Password => _password.Value; public string DotNetVersionUrl => _dotNetVersionUrl.Value; - public string RoslynVersionFragment => _roslynVersionFragment.Value; public string CoreSetupVersionFragment => _coreSetupVersionFragment.Value; public string GitHubUpstreamOwner => _gitHubUpstreamOwner.Value; public string GitHubProject => _gitHubProject.Value; @@ -73,5 +74,38 @@ namespace Microsoft.DotNet.Scripts return value; } + + private static string GetDefaultUpstreamBranch() + { + return GetRepoMSBuildPropValue("BranchInfo.props", "BranchName") ?? "master"; + } + + private static string GetDefaultCoreSetupVersionFragment() + { + string coreSetupChannel = GetRepoMSBuildPropValue("BundledRuntimes.props", "CoreSetupChannel") ?? "master"; + + return $"dotnet/core-setup/{coreSetupChannel}"; + } + + private static string GetRepoMSBuildPropValue(string propsFileName, string propertyName) + { + var propsFilePath = Path.Combine(Dirs.RepoRoot, "build", propsFileName); + var root = XDocument.Load(propsFilePath).Root; + var ns = root.Name.Namespace; + + var value = root + .Elements(ns + "PropertyGroup") + .Elements(ns + propertyName) + .FirstOrDefault() + ?.Value; + + if (string.IsNullOrEmpty(value)) + { + Console.WriteLine($"Could not find a property named '{propertyName}' in {propsFilePath}"); + return null; + } + + return value; + } } } diff --git a/build_projects/update-dependencies/Program.cs b/build_projects/update-dependencies/Program.cs index 6da45dc9a..296ad2d0a 100644 --- a/build_projects/update-dependencies/Program.cs +++ b/build_projects/update-dependencies/Program.cs @@ -25,7 +25,6 @@ namespace Microsoft.DotNet.Scripts List buildInfos = new List(); - buildInfos.Add(GetBuildInfo("Roslyn", s_config.RoslynVersionFragment, fetchLatestReleaseFile: false)); buildInfos.Add(GetBuildInfo("CoreSetup", s_config.CoreSetupVersionFragment, fetchLatestReleaseFile: false)); IEnumerable updaters = GetUpdaters();