Skip to content

Commit

Permalink
Merge pull request #2073 from david-driscoll/tfi-hierarchy
Browse files Browse the repository at this point in the history
Implicitly define compilation constant for target framework without version
  • Loading branch information
dsplaisted authored Mar 21, 2018
2 parents b570ca1 + 043e7ea commit 75d4e57
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- Add conditional compilation symbols for the target framework (for example NET461, NETSTANDARD2_0, NETCOREAPP1_0) -->
<PropertyGroup Condition=" '$(DisableImplicitFrameworkDefines)' != 'true' and '$(TargetFrameworkIdentifier)' != '.NETPortable' and '$(TargetFrameworkIdentifier)' != ''">
<_FrameworkIdentifierForImplicitDefine>$(TargetFrameworkIdentifier.Replace('.', '').ToUpperInvariant())</_FrameworkIdentifierForImplicitDefine>
<VersionlessImplicitFrameworkDefine>$(_FrameworkIdentifierForImplicitDefine)</VersionlessImplicitFrameworkDefine>
<_FrameworkIdentifierForImplicitDefine Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework'">NET</_FrameworkIdentifierForImplicitDefine>

<_FrameworkVersionForImplicitDefine Condition="$(TargetFrameworkVersion.StartsWith('v'))">$(TargetFrameworkVersion.Substring(1))</_FrameworkVersionForImplicitDefine>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ Copyright (c) .NET Foundation. All rights reserved.
<DefineConstants>$(DefineConstants);$(ImplicitConfigurationDefine)</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants);$(ImplicitFrameworkDefine)</DefineConstants>
<DefineConstants>$(DefineConstants);$(VersionlessImplicitFrameworkDefine);$(ImplicitFrameworkDefine)</DefineConstants>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<DefineConstants>$(DefineConstants);$(ImplicitConfigurationDefine)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(UseBundledFSharpTargets)' == 'true' ">
<DefineConstants>$(DefineConstants);$(ImplicitFrameworkDefine)</DefineConstants>
<DefineConstants>$(DefineConstants);$(VersionlessImplicitFrameworkDefine);$(ImplicitFrameworkDefine)</DefineConstants>
</PropertyGroup>

<!-- ***************************************************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<AppDesignerFolder Condition="'$(AppDesignerFolder)' == ''">My Project</AppDesignerFolder>
</PropertyGroup>
<PropertyGroup>
<DefineConstants>$(DefineConstants),$(ImplicitFrameworkDefine)</DefineConstants>
<DefineConstants>$(DefineConstants),$(VersionlessImplicitFrameworkDefine),$(ImplicitFrameworkDefine)</DefineConstants>
<DisableImplicitNamespaceImports Condition="'$(DisableImplicitNamespaceImports)'==''">$(DisableImplicitFrameworkReferences)</DisableImplicitNamespaceImports>
</PropertyGroup>
<ItemGroup Condition=" '$(DisableImplicitNamespaceImports)' != 'true' and '$(TargetFrameworkIdentifier)' == '.NETFramework'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,20 +456,20 @@ public void It_implicitly_defines_compilation_constants_for_the_configuration(st

var definedConstants = getValuesCommand.GetValues();

definedConstants.Should().BeEquivalentTo(new[] { expectedDefine, "TRACE", "NETSTANDARD1_5" });
definedConstants.Should().BeEquivalentTo(new[] { expectedDefine, "TRACE", "NETSTANDARD", "NETSTANDARD1_5" });
}

[Theory]
[InlineData(".NETStandard,Version=v1.0", new[] { "NETSTANDARD1_0" }, false)]
[InlineData("netstandard1.3", new[] { "NETSTANDARD1_3" }, false)]
[InlineData("netstandard1.6", new[] { "NETSTANDARD1_6" }, false)]
[InlineData("net45", new[] { "NET45" }, true)]
[InlineData("net461", new[] { "NET461" }, true)]
[InlineData("netcoreapp1.0", new[] { "NETCOREAPP1_0" }, false)]
[InlineData(".NETStandard,Version=v1.0", new[] { "NETSTANDARD", "NETSTANDARD1_0" }, false)]
[InlineData("netstandard1.3", new[] { "NETSTANDARD", "NETSTANDARD1_3" }, false)]
[InlineData("netstandard1.6", new[] { "NETSTANDARD", "NETSTANDARD1_6" }, false)]
[InlineData("net45", new[] { "NETFRAMEWORK", "NET45" }, true)]
[InlineData("net461", new[] { "NETFRAMEWORK", "NET461" }, true)]
[InlineData("netcoreapp1.0", new[] { "NETCOREAPP", "NETCOREAPP1_0" }, false)]
[InlineData(".NETPortable,Version=v4.5,Profile=Profile78", new string[] { }, false)]
[InlineData(".NETFramework,Version=v4.0,Profile=Client", new string[] { "NET40" }, false)]
[InlineData("Xamarin.iOS,Version=v1.0", new string[] { "XAMARINIOS1_0" }, false)]
[InlineData("UnknownFramework,Version=v3.14", new string[] { "UNKNOWNFRAMEWORK3_14" }, false)]
[InlineData(".NETFramework,Version=v4.0,Profile=Client", new string[] { "NETFRAMEWORK", "NET40" }, false)]
[InlineData("Xamarin.iOS,Version=v1.0", new string[] { "XAMARINIOS", "XAMARINIOS1_0" }, false)]
[InlineData("UnknownFramework,Version=v3.14", new string[] { "UNKNOWNFRAMEWORK", "UNKNOWNFRAMEWORK3_14" }, false)]
public void It_implicitly_defines_compilation_constants_for_the_target_framework(string targetFramework, string[] expectedDefines, bool buildOnlyOnWindows)
{
bool shouldCompile = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ public void It_publishes_the_project_with_a_refs_folder_and_correct_deps_file()
string[] expectedDefines;
if (targetFramework == "net46")
{
expectedDefines = new[] { "DEBUG", "TRACE", "NET46" };
expectedDefines = new[] { "DEBUG", "TRACE", "NETFRAMEWORK", "NET46" };
}
else
{
expectedDefines = new[] { "DEBUG", "TRACE", "NETCOREAPP1_1" };
expectedDefines = new[] { "DEBUG", "TRACE", "NETCOREAPP", "NETCOREAPP1_1" };
}

dependencyContext.CompilationOptions.Defines.Should().BeEquivalentTo(expectedDefines);
Expand Down

0 comments on commit 75d4e57

Please sign in to comment.