diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets index 245f26ac9ccc..dd5dc6c66000 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommon.targets @@ -184,6 +184,8 @@ Copyright (c) .NET Foundation. All rights reserved. <_FrameworkVersionForImplicitDefine Condition=" '$(TargetFrameworkIdentifier)' == '.NETFramework'">$(_FrameworkVersionForImplicitDefine.Replace('_', '')) $(_FrameworkIdentifierForImplicitDefine)$(_FrameworkVersionForImplicitDefine) + + $(TargetFrameworkIdentifier.Replace('.', '').ToUpperInvariant()) @@ -191,39 +193,16 @@ Copyright (c) .NET Foundation. All rights reserved. Condition=" '$(DisableImplicitFrameworkDefines)' != 'true' and '$(TargetPlatformIdentifier)' != '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0)) " > <_PlatformIdentifierForImplicitDefine>$(TargetPlatformIdentifier.ToUpperInvariant()) - <_PlatformVersionForImplicitDefine>$(TargetPlatformVersion.Replace('.', '_')) <_ImplicitDefineConstant Include="$(_PlatformIdentifierForImplicitDefine)" /> - <_ImplicitDefineConstant Include="$(_PlatformIdentifierForImplicitDefine)$(_PlatformVersionForImplicitDefine)" /> - - - - - - - <_NetCoreAppFrameworkVersions Include="@(SupportedNETCoreAppTargetFramework->'%(Identity)'->TrimStart('.NETCoreApp,Version=v'))" /> - <_NetCoreAppCompatibleVersions Include="@(_NetCoreAppFrameworkVersions)" Condition=" $([MSBuild]::VersionGreaterThan(%(Identity), 3.1)) and $([MSBuild]::VersionLessThan(%(Identity), $(TargetFrameworkVersion))) " /> - <_ImplicitDefineConstant Include="NETCOREAPP" /> - <_ImplicitDefineConstant Include="NETCOREAPP3_1" /> - <_ImplicitDefineConstant Include="@(_NetCoreAppCompatibleVersions->'NET%(Identity)'->Replace('.', '_'))" /> - - - - - - - <_SupportedPlatformCompatibleVersions Include="@(SdkSupportedTargetPlatform)" Condition=" %(Identity) != '' and $([MSBuild]::VersionLessThan(%(Identity), $(TargetPlatformVersion))) " /> - <_ImplicitDefineConstant Include="@(_SupportedPlatformCompatibleVersions->'$(TargetPlatformIdentifier.ToUpper())%(Identity)'->Replace('.', '_'))" /> $(DefineConstants);@(_ImplicitDefineConstant) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CSharp.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CSharp.targets index bb24e8bd8fb3..1e636b63fa99 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CSharp.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.CSharp.targets @@ -31,6 +31,6 @@ Copyright (c) .NET Foundation. All rights reserved. $(DefineConstants);$(ImplicitConfigurationDefine) - $(DefineConstants);$(VersionlessImplicitFrameworkDefine);$(ImplicitFrameworkDefine) + $(DefineConstants);$(VersionlessImplicitFrameworkDefine);$(ImplicitFrameworkDefine);$(BackwardsCompatFrameworkDefine) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FSharp.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FSharp.targets index 0a7ad972fb7e..b9a0efdf785e 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FSharp.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FSharp.targets @@ -25,7 +25,7 @@ Copyright (c) .NET Foundation. All rights reserved. - $(DefineConstants);$(VersionlessImplicitFrameworkDefine);$(ImplicitFrameworkDefine) + $(DefineConstants);$(VersionlessImplicitFrameworkDefine);$(ImplicitFrameworkDefine);$(BackwardsCompatFrameworkDefine) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.VisualBasic.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.VisualBasic.targets index f2caf8d0a68c..789837668b89 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.VisualBasic.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.VisualBasic.targets @@ -58,6 +58,7 @@ Copyright (c) .NET Foundation. All rights reserved. $(FinalDefineConstants),$(VersionlessImplicitFrameworkDefine)=-1 $(FinalDefineConstants),$(ImplicitFrameworkDefine)=-1 + $(FinalDefineConstants),$(BackwardsCompatFrameworkDefine)=-1 $(FinalDefineConstants),$(ImplicitConfigurationDefine)=-1 diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs index 7023057847b6..8135760dbb54 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibrary.cs @@ -16,10 +16,7 @@ using System.Runtime.CompilerServices; using Xunit.Abstractions; using Microsoft.NET.TestFramework.ProjectConstruction; -using NuGet.ProjectModel; -using NuGet.Common; using Newtonsoft.Json.Linq; -using Microsoft.NET.Build.Tasks; namespace Microsoft.NET.Build.Tests { @@ -319,6 +316,7 @@ public void It_implicitly_defines_compilation_constants_for_the_configuration(st [InlineData("net461", new[] { "NETFRAMEWORK", "NET461" }, true)] [InlineData("netcoreapp1.0", new[] { "NETCOREAPP", "NETCOREAPP1_0" }, false)] [InlineData("netcoreapp3.0", new[] { "NETCOREAPP", "NETCOREAPP3_0" }, false)] + [InlineData("net5.0", new[] { "NETCOREAPP", "NET", "NET5_0" }, false)] [InlineData(".NETPortable,Version=v4.5,Profile=Profile78", new string[] { }, 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)] @@ -390,72 +388,11 @@ public void It_implicitly_defines_compilation_constants_for_the_target_framework definedConstants.Should().BeEquivalentTo(new[] { "DEBUG", "TRACE" }.Concat(expectedDefines).ToArray()); } - [RequiresMSBuildVersionTheory("16.7.0-preview-20310-07")] - [InlineData("net5.0", new[] { "NETCOREAPP3_1", "NET5_0" })] - [InlineData("net6.0", new[] { "NETCOREAPP3_1", "NET5_0", "NET6_0" })] - public void It_implicitly_defines_compilation_constants_for_the_target_framework_with_backwards_compatibility(string targetFramework, string[] expectedDefines) - { - var testAsset = _testAssetsManager - .CopyTestAsset("AppWithLibrary", "ImplicitFrameworkConstants", targetFramework) - .WithSource() - .WithTargetFramework(targetFramework) - .WithProjectChanges(project => - { - var ns = project.Root.Name.Namespace; - var propGroup = new XElement(ns + "PropertyGroup"); - project.Root.Add(propGroup); - var maxVersion = new XElement(ns + "NETCoreAppMaximumVersion", "6.0"); - propGroup.Add(maxVersion); - var errorOnMissing = new XElement(ns + "GenerateErrorForMissingTargetingPacks", "false"); - propGroup.Add(errorOnMissing); - - var itemGroup = new XElement(ns + "ItemGroup"); - project.Root.Add(itemGroup); - var supportedFramework = new XElement(ns + "SupportedNETCoreAppTargetFramework", - new XAttribute("Include", ".NETCoreApp,Version=v6.0"), - new XAttribute("DisplayName", ".NET 6.0")); - itemGroup.Add(supportedFramework); - }); - - AssertDefinedConstantsOutput(testAsset, targetFramework, new[] { "NETCOREAPP", "NET"}.Concat(expectedDefines).ToArray()); - } - [Theory] - [InlineData("ios", "1.1", new[] { "IOS", "IOS1_1" })] - [InlineData("android", "2.2", new[] { "ANDROID", "ANDROID2_2" })] - [InlineData("windows", "7.0", new[] { "WINDOWS", "WINDOWS7_0" })] - public void It_implicitly_defines_compilation_constants_for_the_target_platform(string targetPlatformIdentifier, string targetPlatformVersion, string[] expectedDefines) - { - var targetFramework = "net5.0"; - var testAsset = _testAssetsManager - .CopyTestAsset("AppWithLibrary", "ImplicitFrameworkConstants", targetFramework) - .WithSource() - .WithTargetFramework(targetFramework) - .WithProjectChanges(project => - { - // Manually set target plaform properties - var ns = project.Root.Name.Namespace; - var propGroup = new XElement(ns + "PropertyGroup"); - project.Root.Add(propGroup); - - var platformIdentifier = new XElement(ns + "TargetPlatformIdentifier", targetPlatformIdentifier); - propGroup.Add(platformIdentifier); - var platformVersion = new XElement(ns + "TargetPlatformVersion", targetPlatformVersion); - propGroup.Add(platformVersion); - var platformSupported = new XElement(ns + "TargetPlatformSupported", true); - propGroup.Add(platformSupported); - var disableUnnecessaryImplicitFrameworkReferencesForThisTest = new XElement(ns + "DisableImplicitFrameworkReferences", "true"); - propGroup.Add(disableUnnecessaryImplicitFrameworkReferencesForThisTest); - }); - - AssertDefinedConstantsOutput(testAsset, targetFramework, new[] { "NETCOREAPP", "NET", "NET5_0", "NETCOREAPP3_1" }.Concat(expectedDefines).ToArray()); - } - - [Theory] - [InlineData(new[] { "1.0", "1.1" }, "ios", "1.1", new[] { "IOS", "IOS1_1", "IOS1_0" })] - [InlineData(new[] { "11.11", "12.12", "13.13" }, "android", "12.12", new[] { "ANDROID", "ANDROID11_11", "ANDROID12_12" })] - [InlineData(new string[] { /* Use the built in SdkSupportedTargetPlatform items */}, "windows", "10.0.19041.0", new[] { "WINDOWS", "WINDOWS7_0", "WINDOWS8_0", "WINDOWS10_0_17763_0", "WINDOWS10_0_18362_0", "WINDOWS10_0_19041_0" })] - public void It_implicitly_defines_compilation_constants_for_the_target_platform_with_backwards_compatibility(string[] sdkSupportedTargetPlatform, string targetPlatformIdentifier, string targetPlatformVersion, string[] expectedDefines) + [InlineData(new string[] { }, "windows", "10.0.19041.0", new[] { "WINDOWS" })] + [InlineData(new[] { "1.0", "1.1" }, "ios", "1.1", new[] { "IOS" })] + [InlineData(new[] { "11.11", "12.12", "13.13" }, "android", "12.12", new[] { "ANDROID" })] + public void It_implicitly_defines_compilation_constants_for_the_target_platform(string[] sdkSupportedTargetPlatform, string targetPlatformIdentifier, string targetPlatformVersion, string[] expectedDefines) { var targetFramework = "net5.0"; var testAsset = _testAssetsManager @@ -486,7 +423,7 @@ public void It_implicitly_defines_compilation_constants_for_the_target_platform_ } }); - AssertDefinedConstantsOutput(testAsset, targetFramework, new[] { "NETCOREAPP", "NET", "NET5_0", "NETCOREAPP3_1" }.Concat(expectedDefines).ToArray()); + AssertDefinedConstantsOutput(testAsset, targetFramework, new[] { "NETCOREAPP", "NET", "NET5_0" }.Concat(expectedDefines).ToArray()); } private void AssertDefinedConstantsOutput(TestAsset testAsset, string targetFramework, string[] expectedDefines) @@ -512,7 +449,7 @@ private void AssertDefinedConstantsOutput(TestAsset testAsset, string targetFram [WindowsOnlyTheory] [InlineData("netcoreapp3.1", new[] { "NETCOREAPP", "NETCOREAPP3_1" })] - [InlineData("net5.0", new[] { "NETCOREAPP", "NETCOREAPP3_1", "NET", "NET5_0", "WINDOWS", "WINDOWS7_0" }, "windows", "7.0")] + [InlineData("net5.0", new[] { "NETCOREAPP", "NET", "NET5_0", "WINDOWS" }, "windows", "7.0")] public void It_can_use_implicitly_defined_compilation_constants(string targetFramework, string[] expectedOutput, string targetPlatformIdentifier = null, string targetPlatformVersion = null) { var testProj = new TestProject() @@ -552,15 +489,9 @@ static void Main(string[] args) #if WINDOWS Console.WriteLine(""WINDOWS""); #endif - #if WINDOWS7_0 - Console.WriteLine(""WINDOWS7_0""); - #endif #if IOS Console.WriteLine(""IOS""); #endif - #if IOS7_0 - Console.WriteLine(""IOS7_0""); - #endif } }"); diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibraryWithFSharp.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibraryWithFSharp.cs index cbbe1e9e9045..d7c0adedc1a0 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibraryWithFSharp.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibraryWithFSharp.cs @@ -15,10 +15,6 @@ using System; using System.Runtime.CompilerServices; using Xunit.Abstractions; -using Microsoft.NET.TestFramework.ProjectConstruction; -using NuGet.ProjectModel; -using NuGet.Common; -using Newtonsoft.Json.Linq; namespace Microsoft.NET.Build.Tests { @@ -182,6 +178,7 @@ public void It_implicitly_defines_compilation_constants_for_the_configuration(st [InlineData("net45", new[] { "NETFRAMEWORK", "NET45" }, true)] [InlineData("net461", new[] { "NETFRAMEWORK", "NET461" }, true)] [InlineData("netcoreapp2.0", new[] { "NETCOREAPP", "NETCOREAPP2_0" }, false)] + [InlineData("net5.0", new[] { "NETCOREAPP", "NET", "NET5_0" }, false)] public void It_implicitly_defines_compilation_constants_for_the_target_framework(string targetFramework, string[] expectedDefines, bool buildOnlyOnWindows) { bool shouldCompile = true; diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibraryWithVB.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibraryWithVB.cs index def9568c0323..2a8845127219 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibraryWithVB.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildALibraryWithVB.cs @@ -15,10 +15,6 @@ using System; using System.Runtime.CompilerServices; using Xunit.Abstractions; -using Microsoft.NET.TestFramework.ProjectConstruction; -using NuGet.ProjectModel; -using NuGet.Common; -using Newtonsoft.Json.Linq; namespace Microsoft.NET.Build.Tests { @@ -195,7 +191,7 @@ public void It_implicitly_defines_compilation_constants_for_the_configuration(st [InlineData("net45", new[] { "NETFRAMEWORK=-1", "NET45=-1" }, true)] [InlineData("net461", new[] { "NETFRAMEWORK=-1", "NET461=-1" }, true)] [InlineData("netcoreapp1.0", new[] { "NETCOREAPP=-1", "NETCOREAPP1_0=-1", "_MyType=\"Empty\"" }, false)] - [InlineData("net5.0", new[] { "NET=-1", "NET5_0=-1", "NETCOREAPP=-1", "NETCOREAPP3_1=-1", "_MyType=\"Empty\"" }, false)] + [InlineData("net5.0", new[] { "NET=-1", "NET5_0=-1", "NETCOREAPP=-1", "_MyType=\"Empty\"" }, false)] [InlineData(".NETPortable,Version=v4.5,Profile=Profile78", new string[] { "_MyType=\"Empty\"" }, false)] [InlineData(".NETFramework,Version=v4.0,Profile=Client", new string[] { "NETFRAMEWORK=-1", "NET40=-1" }, false)] [InlineData("Xamarin.iOS,Version=v1.0", new string[] { "XAMARINIOS=-1", "XAMARINIOS1_0=-1", "_MyType=\"Empty\"" }, false)]