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

Commit

Permalink
Restore fix for #2546
Browse files Browse the repository at this point in the history
This reverts commit 4bfa875.
  • Loading branch information
analogrelay committed Sep 17, 2015
1 parent 5c9e1ac commit fc9dc7b
Show file tree
Hide file tree
Showing 7 changed files with 719 additions and 585 deletions.
34 changes: 29 additions & 5 deletions src/Microsoft.Dnx.Runtime/Internal/FrameworkNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Runtime.Versioning;
using NuGet;

Expand All @@ -13,10 +14,17 @@ public static FrameworkName ParseFrameworkName(string targetFramework)
{
if (targetFramework.Contains("+"))
{
var portableProfile = NetPortableProfile.Parse(targetFramework);
var profile = targetFramework;
if (targetFramework.StartsWith("portable-"))
{
// Strip the "portable-" prefix before passing to the profile parser
profile = profile.Substring(9);
}
var portableProfile = NetPortableProfile.Parse(profile);

// Only support it if it parsed to a real PCL number
if (portableProfile != null &&
portableProfile.FrameworkName.Profile != targetFramework)
portableProfile.FrameworkName.Profile != profile)
{
return portableProfile.FrameworkName;
}
Expand All @@ -36,15 +44,31 @@ public static FrameworkName ParseFrameworkName(string targetFramework)

public static string MakeDefaultTargetFrameworkDefine(Tuple<string, FrameworkName> frameworkDefinition)
{
var shortName = frameworkDefinition.Item1;
var shortName = VersionUtility.GetShortFrameworkName(frameworkDefinition.Item2);
var targetFramework = frameworkDefinition.Item2;

if (VersionUtility.IsPortableFramework(targetFramework))
if (targetFramework.IsPortableFramework())
{
return null;
}

return shortName.ToUpperInvariant();
var candidateName = shortName.ToUpperInvariant();

// Replace '-', '.', and '+' in the candidate name with '_' because TFMs with profiles use those (like "net40-client")
// and we want them representable as defines (i.e. "NET40_CLIENT")
candidateName = candidateName.Replace('-', '_').Replace('+', '_').Replace('.', '_');

// We require the following from our Target Framework Define names
// Starts with A-Z or _
// Contains only A-Z, 0-9 and _
if (!string.IsNullOrEmpty(candidateName) &&
(char.IsLetter(candidateName[0]) || candidateName[0] == '_') &&
candidateName.All(c => Char.IsLetterOrDigit(c) || c == '_'))
{
return candidateName;
}

return null;
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.Dnx.Runtime/NuGet/Utility/VersionUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static class VersionUtility
{ UapFrameworkIdentifier, UapFrameworkIdentifier },

{ SilverlightFrameworkIdentifier, "sl" },
{ NetCoreFrameworkIdentifier, "win"},
{ NetCoreFrameworkIdentifier, "netcore"},
{ WindowsFrameworkIdentifier, "win"},
{ PortableFrameworkIdentifier, "portable" },
{ WindowsPhoneFrameworkIdentifier, "wp"},
Expand Down
33 changes: 17 additions & 16 deletions test/Microsoft.Dnx.CommonTestUtils/project.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
{
"dependencies": {
"Microsoft.Dnx.Runtime": "1.0.0-*",
"Microsoft.Dnx.Runtime.Sources": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"dependencies": {
"Microsoft.Dnx.Runtime": "1.0.0-*",
"Microsoft.Dnx.Runtime.Sources": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*",
"Newtonsoft.Json": "6.0.6"
},

"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.IO.Compression.FileSystem": ""
}
"frameworks": {
"dnx451": {
"frameworkAssemblies": {
"System.IO.Compression.FileSystem": ""
}
},
"dnxcore50": {
"dependencies": {
"System.IO.Compression.ZipFile": "4.0.0-*"
}
}
},
"dnxcore50": {
"dependencies": {
"System.IO.Compression.ZipFile": "4.0.0-*"
}
}
},

"commands": {
"test": "xunit.runner.aspnet"
Expand Down
41 changes: 41 additions & 0 deletions test/Microsoft.Dnx.Runtime.Tests/FrameworkNameHelperFacts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using Microsoft.Dnx.Runtime.Helpers;
using Xunit;

namespace Microsoft.Dnx.Runtime.Tests
{
public class FrameworkNameHelperFacts
{
[Theory]

// Short names
[InlineData("dnx451", "DNX,Version=v4.5.1")]
[InlineData("dnxcore50", "DNXCore,Version=v5.0")]
[InlineData("net451", ".NETFramework,Version=v4.5.1")]

// With profiles
[InlineData("net40-client", ".NETFramework,Version=v4.0,Profile=Client")]

// Full names
[InlineData(".NETFramework,Version=v4.5.1", ".NETFramework,Version=v4.5.1")]
[InlineData(".NETPortable,Version=v4.5,Profile=Profile123", ".NETPortable,Version=v4.5,Profile=Profile123")]

// Portable names
[InlineData("portable-Profile123", ".NETPortable,Version=v0.0,Profile=Profile123")]
[InlineData("portable-Profile49", ".NETPortable,Version=v0.0,Profile=Profile49")]
[InlineData("portable45-Profile49", ".NETPortable,Version=v4.5,Profile=Profile49")]

// We only support full profile names.
[InlineData("portable-net45+wp8", "Unsupported,Version=v0.0")]
public void CorrectlyParsesFrameworkNames(string input, string fullName)
{
Assert.Equal(
new FrameworkName(fullName),
FrameworkNameHelper.ParseFrameworkName(input));
}
}
}
22 changes: 22 additions & 0 deletions test/Microsoft.Dnx.Runtime.Tests/ProjectExtensionsFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@ public void GetCompilerOptionsCombinesTargetFrameworkIfNotNull()
Assert.Equal("x86", options.Platform);
}

[Theory]
[InlineData("net40", "NET40")]
[InlineData(".NETFramework,Version=v4.0", "NET40")]
[InlineData(".NETFramework,Version=v4.0,Profile=Client", "NET40_CLIENT")]
[InlineData("DOTNET5.1", "DOTNET5_1")]
[InlineData(".NETPortable,Version=v4.5,Profile=Profile123", null)]
[InlineData("portable-net45+win81", null)]
public void GetCompilerOptionsGeneratesTFMDefineForShortName(string tfm, string define)
{
// Arrange
var projectContent = @"{ ""frameworks"": { """ + tfm + @""": {} } }";
var project = ProjectUtilities.GetProject(projectContent, "TestProj", "project.json");
var targetFramework = FrameworkNameHelper.ParseFrameworkName(tfm);

// Act
var options = project.GetCompilerOptions(targetFramework, configurationName: "Debug");

// Assert
var expectedDefines = define == null ? new[] { "DEBUG", "TRACE" } : new[] { "DEBUG", "TRACE", define };
Assert.Equal(expectedDefines, options.Defines);
}

[Fact]
public void GetCompilerOptionsCombinesConfigurationAndTargetFrameworkfNotNull()
{
Expand Down

0 comments on commit fc9dc7b

Please sign in to comment.