diff --git a/src/Shared/FrameworkLocationHelper.cs b/src/Shared/FrameworkLocationHelper.cs index 7214b5cbc47..79ba6fc6afc 100644 --- a/src/Shared/FrameworkLocationHelper.cs +++ b/src/Shared/FrameworkLocationHelper.cs @@ -56,6 +56,7 @@ internal static class FrameworkLocationHelper internal static readonly Version dotNetFrameworkVersion40 = new Version(4, 0); internal static readonly Version dotNetFrameworkVersion45 = new Version(4, 5); internal static readonly Version dotNetFrameworkVersion451 = new Version(4, 5, 1); + internal static readonly Version dotNetFrameworkVersion452 = new Version(4, 5, 2); internal static readonly Version dotNetFrameworkVersion46 = new Version(4, 6); internal static readonly Version dotNetFrameworkVersion461 = new Version(4, 6, 1); @@ -193,6 +194,9 @@ internal static class FrameworkLocationHelper // v4.5.1 CreateDotNetFrameworkSpecForV4(dotNetFrameworkVersion451, visualStudioVersion120), + // v4.5.2 + CreateDotNetFrameworkSpecForV4(dotNetFrameworkVersion452, visualStudioVersion120), + // v4.6 CreateDotNetFrameworkSpecForV4(dotNetFrameworkVersion46, visualStudioVersion140), @@ -236,6 +240,7 @@ internal static class FrameworkLocationHelper dotNetFrameworkVersion40, dotNetFrameworkVersion45, dotNetFrameworkVersion451, + dotNetFrameworkVersion452 }), // VS14 @@ -247,6 +252,7 @@ internal static class FrameworkLocationHelper dotNetFrameworkVersion40, dotNetFrameworkVersion45, dotNetFrameworkVersion451, + dotNetFrameworkVersion452, dotNetFrameworkVersion46, dotNetFrameworkVersion461 }), @@ -265,9 +271,11 @@ internal static class FrameworkLocationHelper { // VS12 { Tuple.Create(dotNetFrameworkVersion451, visualStudioVersion120), Tuple.Create(dotNetFrameworkVersion45, visualStudioVersion120) }, + { Tuple.Create(dotNetFrameworkVersion452, visualStudioVersion120), Tuple.Create(dotNetFrameworkVersion451, visualStudioVersion120) }, // VS14 { Tuple.Create(dotNetFrameworkVersion451, visualStudioVersion140), Tuple.Create(dotNetFrameworkVersion45, visualStudioVersion140) }, + { Tuple.Create(dotNetFrameworkVersion452, visualStudioVersion140), Tuple.Create(dotNetFrameworkVersion451, visualStudioVersion140) }, { Tuple.Create(dotNetFrameworkVersion46, visualStudioVersion140), Tuple.Create(dotNetFrameworkVersion451, visualStudioVersion140) }, { Tuple.Create(dotNetFrameworkVersion461, visualStudioVersion140), Tuple.Create(dotNetFrameworkVersion46, visualStudioVersion140) }, }; diff --git a/src/Utilities/ToolLocationHelper.cs b/src/Utilities/ToolLocationHelper.cs index 67e7e04924f..51db272d944 100644 --- a/src/Utilities/ToolLocationHelper.cs +++ b/src/Utilities/ToolLocationHelper.cs @@ -70,6 +70,12 @@ public enum TargetDotNetFrameworkVersion /// Version461 = 8, + /// + /// version 4.5.2. Enum is out of order because it was shipped out of band from a Visual Studio update + /// without a corresponding SDK release. + /// + Version452 = 9, + // keep this up to date, this should always point to the last entry /// /// the latest version available at the time of release @@ -1766,6 +1772,9 @@ private static Version TargetDotNetFrameworkVersionToSystemVersion(TargetDotNetF case TargetDotNetFrameworkVersion.Version451: return FrameworkLocationHelper.dotNetFrameworkVersion451; + case TargetDotNetFrameworkVersion.Version452: + return FrameworkLocationHelper.dotNetFrameworkVersion452; + case TargetDotNetFrameworkVersion.Version46: return FrameworkLocationHelper.dotNetFrameworkVersion46; diff --git a/src/Utilities/UnitTests/ToolLocationHelper_Tests.cs b/src/Utilities/UnitTests/ToolLocationHelper_Tests.cs index 02ae35d9a82..6e2e3a65833 100644 --- a/src/Utilities/UnitTests/ToolLocationHelper_Tests.cs +++ b/src/Utilities/UnitTests/ToolLocationHelper_Tests.cs @@ -688,6 +688,12 @@ public void TestGetDotNetFrameworkSdkRootRegistryKey() Assert.Equal(ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.Version451, VisualStudioVersion.Version120), fullDotNetFrameworkSdkRegistryPathForV4ToolsOnManagedToolsSDK81A); Assert.Equal(ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.Version451, VisualStudioVersion.Version140), fullDotNetFrameworkSdkRegistryPathForV4ToolsOnManagedToolsSDK46); + // v4.5.2 + ObjectModelHelpers.AssertThrows(typeof(ArgumentException), delegate { ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.Version451, VisualStudioVersion.Version100); }); + ObjectModelHelpers.AssertThrows(typeof(ArgumentException), delegate { ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.Version451, VisualStudioVersion.Version110); }); + Assert.Equal(ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.Version452, VisualStudioVersion.Version120), fullDotNetFrameworkSdkRegistryPathForV4ToolsOnManagedToolsSDK81A); + Assert.Equal(ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.Version452, VisualStudioVersion.Version140), fullDotNetFrameworkSdkRegistryPathForV4ToolsOnManagedToolsSDK46); + // v4.6 ObjectModelHelpers.AssertThrows(typeof(ArgumentException), delegate { ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.Version46, VisualStudioVersion.Version100); }); ObjectModelHelpers.AssertThrows(typeof(ArgumentException), delegate { ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.Version46, VisualStudioVersion.Version110); }); diff --git a/src/XMakeTasks/GetFrameworkPath.cs b/src/XMakeTasks/GetFrameworkPath.cs index 30ba73ef59a..4dc03ae3f08 100644 --- a/src/XMakeTasks/GetFrameworkPath.cs +++ b/src/XMakeTasks/GetFrameworkPath.cs @@ -2,10 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; -using System.IO; -using System.Diagnostics; -using System.Resources; -using System.Reflection; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; @@ -16,6 +12,33 @@ namespace Microsoft.Build.Tasks /// public class GetFrameworkPath : TaskExtension { + static GetFrameworkPath() + { + s_path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.VersionLatest)); + s_version11Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version11)); + s_version20Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version20)); + s_version30Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version30)); + s_version35Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version35)); + s_version40Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version40)); + s_version45Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version45)); + s_version451Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version451)); + s_version452Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version452)); + s_version46Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version46)); + s_version461Path = new Lazy(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version461)); + } + + #region ITask Members + + /// + /// Does nothing: getters do all the work + /// + public override bool Execute() + { + return true; + } + + #endregion + #region Properties // PERF NOTE: We cache these values in statics -- although the code we call does this too, @@ -23,204 +46,83 @@ public class GetFrameworkPath : TaskExtension // In a large build, this adds up. // PERF NOTE: We also only find paths we are actually asked for (via tags) - private static string s_path; - private static string s_version11Path; - private static string s_version20Path; - private static string s_version30Path; - private static string s_version35Path; - private static string s_version40Path; - private static string s_version45Path; - private static string s_version451Path; - private static string s_version46Path; - private static string s_version461Path; + private static Lazy s_path; + private static Lazy s_version11Path; + private static Lazy s_version20Path; + private static Lazy s_version30Path; + private static Lazy s_version35Path; + private static Lazy s_version40Path; + private static Lazy s_version45Path; + private static Lazy s_version451Path; + private static Lazy s_version452Path; + private static Lazy s_version46Path; + private static Lazy s_version461Path; /// /// Path to the latest framework, whatever version it happens to be /// [Output] - public string Path - { - get - { - if (s_path == null) - { - s_path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.VersionLatest); - } - - return s_path; - } - - set - { - // Does nothing: backward compat - s_path = value; - } - } + public string Path => s_path.Value; /// /// Path to the v1.1 framework, if available /// [Output] - public string FrameworkVersion11Path - { - get - { - if (s_version11Path == null) - { - s_version11Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version11); - } - - return s_version11Path; - } - } + public string FrameworkVersion11Path => s_version11Path.Value; /// /// Path to the v2.0 framework, if available /// [Output] - public string FrameworkVersion20Path - { - get - { - if (s_version20Path == null) - { - s_version20Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version20); - } - - return s_version20Path; - } - } + public string FrameworkVersion20Path => s_version20Path.Value; /// /// Path to the v3.0 framework, if available /// [Output] - public string FrameworkVersion30Path - { - get - { - if (s_version30Path == null) - { - s_version30Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version30); - } - - return s_version30Path; - } - } + public string FrameworkVersion30Path => s_version30Path.Value; /// /// Path to the v3.5 framework, if available /// [Output] - public string FrameworkVersion35Path - { - get - { - if (s_version35Path == null) - { - s_version35Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version35); - } - - return s_version35Path; - } - } + public string FrameworkVersion35Path => s_version35Path.Value; /// /// Path to the v4.0 framework, if available /// [Output] - public string FrameworkVersion40Path - { - get - { - if (s_version40Path == null) - { - s_version40Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version40); - } - - return s_version40Path; - } - } + public string FrameworkVersion40Path => s_version40Path.Value; /// /// Path to the v4.5 framework, if available /// [Output] - public string FrameworkVersion45Path - { - get - { - if (s_version45Path == null) - { - s_version45Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version45); - } - - return s_version45Path; - } - } + public string FrameworkVersion45Path => s_version45Path.Value; /// /// Path to the v4.5.1 framework, if available /// [Output] - public string FrameworkVersion451Path - { - get - { - if (s_version451Path == null) - { - s_version451Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version451); - } - - return s_version451Path; - } - } + public string FrameworkVersion451Path => s_version451Path.Value; /// - /// Path to the v4.6 framework, if available + /// Path to the v4.5.2 framework, if available /// [Output] - public string FrameworkVersion46Path - { - get - { - if (s_version46Path == null) - { - s_version46Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version46); - } - - return s_version46Path; - } - } + public string FrameworkVersion452Path => s_version452Path.Value; /// - /// Path to the v4.6.1 framework, if available + /// Path to the v4.6 framework, if available /// [Output] - public string FrameworkVersion461Path - { - get - { - if (s_version461Path == null) - { - s_version461Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version461); - } - - return s_version461Path; - } - } - - #endregion - - #region ITask Members + public string FrameworkVersion46Path => s_version46Path.Value; /// - /// Does nothing: getters do all the work + /// Path to the v4.6.1 framework, if available /// - public override bool Execute() - { - return true; - } + [Output] + public string FrameworkVersion461Path => s_version461Path.Value; #endregion }