diff --git a/src/XMakeTasks/GetFrameworkPath.cs b/src/XMakeTasks/GetFrameworkPath.cs index d426d323a07..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,222 +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_version452Path; - 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.5.2 framework, if available /// [Output] - public string FrameworkVersion452Path - { - get - { - if (s_version452Path == null) - { - s_version452Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version452); - } - - return s_version452Path; - } - } + public string FrameworkVersion452Path => s_version452Path.Value; /// /// Path to the v4.6 framework, if available /// [Output] - public string FrameworkVersion46Path - { - get - { - if (s_version46Path == null) - { - s_version46Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version46); - } - - return s_version46Path; - } - } + public string FrameworkVersion46Path => s_version46Path.Value; /// /// Path to the v4.6.1 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 - - /// - /// Does nothing: getters do all the work - /// - public override bool Execute() - { - return true; - } + public string FrameworkVersion461Path => s_version461Path.Value; #endregion }