Skip to content
This repository was archived by the owner on Dec 18, 2017. It is now read-only.

Added support for the new ASP.NET target framework names #575

Merged
merged 2 commits into from
Aug 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions samples/HelloShared/project.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
{
"version": "0.1-beta-*",
"dependencies": {},
"dependencies": { },
"shared": "*.cs",
"frameworks": {
"net45": {},
"net45": { },
"k10": {
"dependencies": {
"System.Linq": "4.0.0.0",
"System.Runtime": "4.0.20.0"
}
},
"aspnet50": { },
"aspnetcore50": {
"dependencies": {
"System.Linq": "4.0.0.0",
"System.Runtime": "4.0.20.0"
}
}
}
}
26 changes: 23 additions & 3 deletions samples/HelloWorld/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
},
"frameworks": {
"net45": {
"dependencies": {
"System.Collections" : "",
"dependencies": {
"System.Collections": "",
"System.IO": "",
"System.Runtime" : "",
"System.Runtime": "",
"System.Xml": "",
"System.Xml.Linq": "",
"System.Threading.Tasks": "",
Expand All @@ -30,6 +30,26 @@
"System.Threading.Tasks": "4.0.10.0",
"System.ComponentModel": "4.0.0.0"
}
},
"aspnet50": {
"dependencies": {
"System.Collections" : "",
"System.IO": "",
"System.Runtime" : "",
"System.Xml": "",
"System.Xml.Linq": "",
"System.Threading.Tasks": "",
"System.Text.Encoding": ""
}
},
"aspnetcore50": {
"dependencies": {
"System.Console": "4.0.0.0",
"System.Linq": "4.0.0.0",
"System.Reflection": "4.0.10.0",
"System.Runtime": "4.0.20.0",
"System.Threading.Tasks": "4.0.10.0"
}
}
}
}
11 changes: 2 additions & 9 deletions src/Microsoft.Framework.DesignTimeHost/ApplicationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private void Calculate()
{
RootDependency = state.Project.Name,
LongFrameworkName = state.TargetFramework.ToString(),
FriendlyFrameworkName = GetFriendlyFrameworkName(state.FrameworkResolver, state.TargetFramework),
FriendlyFrameworkName = state.FrameworkResolver.GetFriendlyFrameworkName(state.TargetFramework),
ProjectReferences = metadata.ProjectReferences,
FileReferences = metadata.References,
RawReferences = metadata.RawReferences,
Expand Down Expand Up @@ -348,14 +348,7 @@ private void Calculate()

private string GetFriendlyFrameworkName(FrameworkReferenceResolver frameworkResolver, FrameworkName targetFramework)
{
// We don't have a friendly name for this anywhere on the machine so hard code it
if (targetFramework.Identifier.Equals("K", StringComparison.OrdinalIgnoreCase))
{
// REVIEW: 4.5?
return ".NET Core Framework 4.5";
}

return frameworkResolver.GetFriendlyFrameworkName(targetFramework) ?? targetFramework.ToString();
return frameworkResolver.GetFriendlyFrameworkName(targetFramework);
}

private void Reconcile()
Expand Down
41 changes: 39 additions & 2 deletions src/Microsoft.Framework.Runtime/FrameworkReferenceResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ public class FrameworkReferenceResolver : IFrameworkReferenceResolver
{
private readonly IDictionary<FrameworkName, FrameworkInformation> _cache = new Dictionary<FrameworkName, FrameworkInformation>();

private static readonly IDictionary<FrameworkName, FrameworkName> _aliases = new Dictionary<FrameworkName, FrameworkName>
{
{ new FrameworkName(VersionUtility.AspNetFrameworkIdentifier, new Version(5, 0)), new FrameworkName(VersionUtility.NetFrameworkIdentifier, new Version(4, 5, 3)) }
};

private static readonly IDictionary<FrameworkName, FrameworkName> _monoAliases = new Dictionary<FrameworkName, FrameworkName>
{
{ new FrameworkName(VersionUtility.NetFrameworkIdentifier, new Version(4, 5, 3)), new FrameworkName(VersionUtility.AspNetFrameworkIdentifier, new Version(5, 0)) }
};

public FrameworkReferenceResolver()
{
PopulateCache();
Expand Down Expand Up @@ -46,11 +56,25 @@ public bool TryGetAssembly(string name, FrameworkName targetFramework, out strin

public string GetFriendlyFrameworkName(FrameworkName targetFramework)
{
// We don't have a friendly name for this anywhere on the machine so hard code it
if (string.Equals(targetFramework.Identifier, "K", StringComparison.OrdinalIgnoreCase))
{
return ".NET Core Framework 4.5";
}
else if (string.Equals(targetFramework.Identifier, VersionUtility.AspNetCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
{
return "ASP.NET Core 5.0";
}
else if (string.Equals(targetFramework.Identifier, VersionUtility.AspNetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
{
return "ASP.NET 5.0";
}

var information = _cache.GetOrAdd(targetFramework, GetFrameworkInformation);

if (information == null)
{
return null;
return targetFramework.ToString();
}

return information.Name;
Expand Down Expand Up @@ -103,6 +127,7 @@ private void PopulateCache()
// Mono is a bit inconsistent as .NET 4.5 and .NET 4.5.1 are the
// same folder
var supportedVersions = new Dictionary<string, string> {
{ "4.5.3", "4.5" },
{ "4.5.1", "4.5" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should 4.5.2 be listed here as well?

{ "4.5", "4.5" },
{ "4.0", "4.0" }
Expand Down Expand Up @@ -139,8 +164,14 @@ private void PopulateCache()
pathCache[targetFrameworkPath] = frameworkInfo;
}

var frameworkName = new FrameworkName(VersionUtility.DefaultTargetFramework.Identifier, new Version(versionFolderPair.Key));
var frameworkName = new FrameworkName(VersionUtility.NetFrameworkIdentifier, new Version(versionFolderPair.Key));
_cache[frameworkName] = frameworkInfo;

FrameworkName aliasFrameworkName;
if (_monoAliases.TryGetValue(frameworkName, out aliasFrameworkName))
{
_cache[aliasFrameworkName] = frameworkInfo;
}
}

// Not needed anymore
Expand All @@ -151,6 +182,12 @@ private void PopulateCache()

private static FrameworkInformation GetFrameworkInformation(FrameworkName targetFramework)
{
FrameworkName aliasFramework;
if (_aliases.TryGetValue(targetFramework, out aliasFramework))
{
targetFramework = aliasFramework;
}

string referenceAssembliesPath = GetReferenceAssembliesPath();

if (string.IsNullOrEmpty(referenceAssembliesPath))
Expand Down
63 changes: 54 additions & 9 deletions src/Microsoft.Framework.Runtime/NuGet/Utility/VersionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ namespace NuGet
{
public static class VersionUtility
{
private const string NetFrameworkIdentifier = ".NETFramework";
internal const string NetFrameworkIdentifier = ".NETFramework";
private const string NetCoreFrameworkIdentifier = ".NETCore";
private const string PortableFrameworkIdentifier = ".NETPortable";
internal const string AspNetFrameworkIdentifier = "Asp.Net";
internal const string AspNetCoreFrameworkIdentifier = "Asp.NetCore";
private const string LessThanOrEqualTo = "\u2264";
private const string GreaterThanOrEqualTo = "\u2265";

Expand All @@ -42,6 +44,8 @@ public static class VersionUtility
private static readonly Dictionary<string, string> _identifierToFrameworkFolder = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
{ NetFrameworkIdentifier, "net" },
{ ".NETMicroFramework", "netmf" },
{ AspNetFrameworkIdentifier, "aspnet" },
{ AspNetCoreFrameworkIdentifier, "aspnetcore" },
{ "Silverlight", "sl" },
{ ".NETCore", "win"},
{ "Windows", "win"},
Expand Down Expand Up @@ -82,10 +86,17 @@ public static class VersionUtility

{ new FrameworkName("Windows, Version=v0.0"), new FrameworkName(".NETCore, Version=v4.5") },
{ new FrameworkName("Windows, Version=v8.0"), new FrameworkName(".NETCore, Version=v4.5") },
{ new FrameworkName("Windows, Version=v8.1"), new FrameworkName(".NETCore, Version=v4.5.1") },
{ new FrameworkName("Windows, Version=v8.1"), new FrameworkName(".NETCore, Version=v4.5.1") }
};

private static readonly Version MaxVersion = new Version(Int32.MaxValue, Int32.MaxValue, Int32.MaxValue, Int32.MaxValue);
private static readonly Dictionary<string, FrameworkName> _equivalentProjectFrameworks = new Dictionary<string, FrameworkName>()
{
{ AspNetFrameworkIdentifier, new FrameworkName(NetFrameworkIdentifier, MaxVersion) },

// HACK: Temporary hack to make K 1.0 is compatible with NetCore 4.5.1
{ new FrameworkName("K, Version=v1.0"), new FrameworkName(".NETCore, Version=v4.5.1") }
// Temporary backwards compatiblity, eventually this will point directly to ".NETCore"
{ AspNetCoreFrameworkIdentifier, new FrameworkName("K", MaxVersion) },
{ "K", new FrameworkName(NetCoreFrameworkIdentifier, MaxVersion) },
};

public static Version DefaultTargetFrameworkVersion
Expand All @@ -106,9 +117,21 @@ public static FrameworkName DefaultTargetFramework
}
}

internal static FrameworkName GetEquivalentFramework(FrameworkName targetFramework)
{
FrameworkName equivalentFramework;
if (_equivalentProjectFrameworks.TryGetValue(targetFramework.Identifier, out equivalentFramework))
{
return equivalentFramework;
}

return null;
}

public static bool IsDesktop(FrameworkName frameworkName)
{
return frameworkName.Identifier == DefaultTargetFramework.Identifier;
return frameworkName.Identifier == NetFrameworkIdentifier ||
frameworkName.Identifier == AspNetFrameworkIdentifier;
}

/// <summary>
Expand Down Expand Up @@ -540,8 +563,8 @@ public static string GetShortFrameworkName(FrameworkName frameworkName)

public static FrameworkName ParseFrameworkNameFromFilePath(string filePath, out string effectivePath)
{
var knownFolders = new string[]
{
var knownFolders = new string[]
{
Constants.ContentDirectory,
Constants.LibDirectory,
Constants.ToolsDirectory,
Expand Down Expand Up @@ -745,9 +768,27 @@ internal static bool IsCompatible(FrameworkName frameworkName, FrameworkName tar
targetFrameworkName = NormalizeFrameworkName(targetFrameworkName);
frameworkName = NormalizeFrameworkName(frameworkName);

check:

if (!frameworkName.Identifier.Equals(targetFrameworkName.Identifier, StringComparison.OrdinalIgnoreCase))
{
return false;
// Try to convert the project framework into an equivalent target framework
// If the identifiers didn't match, we need to see if this framework has an equivalent framework that DOES match.
// If it does, we use that from here on.
// Example:
// If the Project Targets ASP.Net, Version=5.0. It can accept Packages targetting .NETFramework, Version=4.5.1
// so since the identifiers don't match, we need to "translate" the project target framework to .NETFramework
// however, we still want direct ASP.Net == ASP.Net matches, so we do this ONLY if the identifiers don't already match

if (_equivalentProjectFrameworks.TryGetValue(frameworkName.Identifier, out frameworkName))
{
// Goto might be evil but it's so nice to use here
goto check;
}
else
{
return false;
}
}

if (NormalizeVersion(frameworkName.Version) <
Expand Down Expand Up @@ -1046,7 +1087,7 @@ public static bool ShouldUseConsidering(
}

internal static SemanticVersion GetAssemblyVersion(string path)
{
{
#if NET45
return new SemanticVersion(AssemblyName.GetAssemblyName(path).Version);
#else
Expand All @@ -1057,6 +1098,10 @@ internal static SemanticVersion GetAssemblyVersion(string path)
private static IDictionary<string, string> PopulateKnownFrameworks()
{
var frameworks = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) {
{ "aspnet", AspNetFrameworkIdentifier },
{ "aspnetcore", AspNetCoreFrameworkIdentifier },
{ "asp.net", AspNetFrameworkIdentifier },
{ "asp.netcore", AspNetCoreFrameworkIdentifier },
{ "NET", NetFrameworkIdentifier },
{ ".NET", NetFrameworkIdentifier },
{ "NETFramework", NetFrameworkIdentifier },
Expand Down
2 changes: 1 addition & 1 deletion src/klr.host/Bootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Task<int> Main(string[] args)
var configuration = Environment.GetEnvironmentVariable("TARGET_CONFIGURATION") ?? Environment.GetEnvironmentVariable("KRE_CONFIGURATION") ?? "Debug";

// TODO: Support the highest installed version
var targetFramework = FrameworkNameUtility.ParseFrameworkName(framework ?? "net451");
var targetFramework = FrameworkNameUtility.ParseFrameworkName(framework ?? "aspnet50");

var applicationEnvironment = new ApplicationEnvironment(applicationBaseDirectory,
targetFramework,
Expand Down
10 changes: 7 additions & 3 deletions src/klr.host/FrameworkNameUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ internal static FrameworkName ParseFrameworkName(string frameworkName)

if (!String.IsNullOrEmpty(identifierPart))
{
if (identifierPart.Equals("net", StringComparison.OrdinalIgnoreCase))
if (identifierPart.Equals("aspnet", StringComparison.OrdinalIgnoreCase))
{
identifierPart = ".NETFramework";
identifierPart = "Asp.Net";
}
else if (identifierPart.Equals("aspnetcore", StringComparison.OrdinalIgnoreCase))
{
identifierPart = "Asp.NetCore";
}
else if (identifierPart.Equals("k", StringComparison.OrdinalIgnoreCase))
{
identifierPart = "K";
identifierPart = "Asp.NetCore";
}
}

Expand Down