Skip to content

Commit

Permalink
Merge pull request #602 from AndyGerlicher/AddFramework452
Browse files Browse the repository at this point in the history
Adding support for 4.5.2 target framework
  • Loading branch information
AndyGerlicher committed May 4, 2016
2 parents e4a55ee + 7f97231 commit 061183a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 151 deletions.
8 changes: 8 additions & 0 deletions src/Shared/FrameworkLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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),

Expand Down Expand Up @@ -236,6 +240,7 @@ internal static class FrameworkLocationHelper
dotNetFrameworkVersion40,
dotNetFrameworkVersion45,
dotNetFrameworkVersion451,
dotNetFrameworkVersion452
}),

// VS14
Expand All @@ -247,6 +252,7 @@ internal static class FrameworkLocationHelper
dotNetFrameworkVersion40,
dotNetFrameworkVersion45,
dotNetFrameworkVersion451,
dotNetFrameworkVersion452,
dotNetFrameworkVersion46,
dotNetFrameworkVersion461
}),
Expand All @@ -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) },
};
Expand Down
9 changes: 9 additions & 0 deletions src/Utilities/ToolLocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public enum TargetDotNetFrameworkVersion
/// </summary>
Version461 = 8,

/// <summary>
/// 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.
/// </summary>
Version452 = 9,

// keep this up to date, this should always point to the last entry
/// <summary>
/// the latest version available at the time of release
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions src/Utilities/UnitTests/ToolLocationHelper_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
Expand Down
204 changes: 53 additions & 151 deletions src/XMakeTasks/GetFrameworkPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,211 +12,117 @@ namespace Microsoft.Build.Tasks
/// </summary>
public class GetFrameworkPath : TaskExtension
{
static GetFrameworkPath()
{
s_path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.VersionLatest));
s_version11Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version11));
s_version20Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version20));
s_version30Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version30));
s_version35Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version35));
s_version40Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version40));
s_version45Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version45));
s_version451Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version451));
s_version452Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version452));
s_version46Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version46));
s_version461Path = new Lazy<string>(() => ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version461));
}

#region ITask Members

/// <summary>
/// Does nothing: getters do all the work
/// </summary>
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,
// it still seems to give an advantage perhaps because there is one less string copy.
// In a large build, this adds up.
// PERF NOTE: We also only find paths we are actually asked for (via <Output> 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<string> s_path;
private static Lazy<string> s_version11Path;
private static Lazy<string> s_version20Path;
private static Lazy<string> s_version30Path;
private static Lazy<string> s_version35Path;
private static Lazy<string> s_version40Path;
private static Lazy<string> s_version45Path;
private static Lazy<string> s_version451Path;
private static Lazy<string> s_version452Path;
private static Lazy<string> s_version46Path;
private static Lazy<string> s_version461Path;

/// <summary>
/// Path to the latest framework, whatever version it happens to be
/// </summary>
[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;

/// <summary>
/// Path to the v1.1 framework, if available
/// </summary>
[Output]
public string FrameworkVersion11Path
{
get
{
if (s_version11Path == null)
{
s_version11Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version11);
}

return s_version11Path;
}
}
public string FrameworkVersion11Path => s_version11Path.Value;

/// <summary>
/// Path to the v2.0 framework, if available
/// </summary>
[Output]
public string FrameworkVersion20Path
{
get
{
if (s_version20Path == null)
{
s_version20Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version20);
}

return s_version20Path;
}
}
public string FrameworkVersion20Path => s_version20Path.Value;

/// <summary>
/// Path to the v3.0 framework, if available
/// </summary>
[Output]
public string FrameworkVersion30Path
{
get
{
if (s_version30Path == null)
{
s_version30Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version30);
}

return s_version30Path;
}
}
public string FrameworkVersion30Path => s_version30Path.Value;

/// <summary>
/// Path to the v3.5 framework, if available
/// </summary>
[Output]
public string FrameworkVersion35Path
{
get
{
if (s_version35Path == null)
{
s_version35Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version35);
}

return s_version35Path;
}
}
public string FrameworkVersion35Path => s_version35Path.Value;

/// <summary>
/// Path to the v4.0 framework, if available
/// </summary>
[Output]
public string FrameworkVersion40Path
{
get
{
if (s_version40Path == null)
{
s_version40Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version40);
}

return s_version40Path;
}
}
public string FrameworkVersion40Path => s_version40Path.Value;

/// <summary>
/// Path to the v4.5 framework, if available
/// </summary>
[Output]
public string FrameworkVersion45Path
{
get
{
if (s_version45Path == null)
{
s_version45Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version45);
}

return s_version45Path;
}
}
public string FrameworkVersion45Path => s_version45Path.Value;

/// <summary>
/// Path to the v4.5.1 framework, if available
/// </summary>
[Output]
public string FrameworkVersion451Path
{
get
{
if (s_version451Path == null)
{
s_version451Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version451);
}

return s_version451Path;
}
}
public string FrameworkVersion451Path => s_version451Path.Value;

/// <summary>
/// Path to the v4.6 framework, if available
/// Path to the v4.5.2 framework, if available
/// </summary>
[Output]
public string FrameworkVersion46Path
{
get
{
if (s_version46Path == null)
{
s_version46Path = ToolLocationHelper.GetPathToDotNetFramework(TargetDotNetFrameworkVersion.Version46);
}

return s_version46Path;
}
}
public string FrameworkVersion452Path => s_version452Path.Value;

/// <summary>
/// Path to the v4.6.1 framework, if available
/// Path to the v4.6 framework, if available
/// </summary>
[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;

/// <summary>
/// Does nothing: getters do all the work
/// Path to the v4.6.1 framework, if available
/// </summary>
public override bool Execute()
{
return true;
}
[Output]
public string FrameworkVersion461Path => s_version461Path.Value;

#endregion
}
Expand Down

0 comments on commit 061183a

Please sign in to comment.