From 3972b6828ed7a178b0bffba175cd6ecc1017fa5e Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Wed, 19 Apr 2017 11:44:58 -0700 Subject: [PATCH 1/5] Adding a first test and net461 as a implicit package target fallback. --- .../Microsoft.NET.Sdk.BeforeCommon.targets | 4 + .../DeleteNuGetArtifactsFixture.cs | 58 ++++++++++++++ ...t461ToBeAnImplicitPackageTargetFallback.cs | 77 +++++++++++++++++++ ...nThatWeWantToVerifyNuGetReferenceCompat.cs | 55 +------------ 4 files changed, 143 insertions(+), 51 deletions(-) create mode 100644 test/Microsoft.NET.Build.Tests/DeleteNuGetArtifactsFixture.cs create mode 100644 test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets index d5b80ee95220..1755b11b6508 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets @@ -108,6 +108,10 @@ Copyright (c) .NET Foundation. All rights reserved. + + $(PackageTargetFallback);net461 + + <_FrameworkIdentifierForImplicitDefine>$(TargetFrameworkIdentifier.Replace('.', '').ToUpperInvariant()) diff --git a/test/Microsoft.NET.Build.Tests/DeleteNuGetArtifactsFixture.cs b/test/Microsoft.NET.Build.Tests/DeleteNuGetArtifactsFixture.cs new file mode 100644 index 000000000000..20ac71c1f0fa --- /dev/null +++ b/test/Microsoft.NET.Build.Tests/DeleteNuGetArtifactsFixture.cs @@ -0,0 +1,58 @@ +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.ProjectConstruction; +using System; +using System.IO; + +namespace Microsoft.NET.Build.Tests +{ + public class ConstantStringValues + { + public static string TestDirectoriesNamePrefix = "Nuget_reference_compat"; + public static string ReferencerDirectoryName = "Reference"; + public static string NuGetSharedDirectoryNamePostfix = "_NuGetDependencies"; + public static string NetstandardToken = "netstandard"; + public static string DependencyDirectoryNamePrefix = "D_"; + public static string NuGetPackageBaseDirectory = Path.Combine( + RepoInfo.GetBaseDirectory(), + TestDirectoriesNamePrefix + NuGetSharedDirectoryNamePostfix); + + public static string ConstructNuGetPackageReferencePath(TestProject dependencyProject) + { + return Path.Combine(NuGetPackageBaseDirectory, dependencyProject.Name, dependencyProject.Name, "bin", "Debug"); + } + } + + public class DeleteNuGetArtifactsFixture : IDisposable + { + public DeleteNuGetArtifactsFixture() + { + DeleteNuGetArtifacts(); + } + + public void Dispose() + { + DeleteNuGetArtifacts(); + } + + private void DeleteNuGetArtifacts() + { + try + { + // Delete the shared NuGet package directory before running all the tests. + if (Directory.Exists(ConstantStringValues.NuGetPackageBaseDirectory)) + { + Directory.Delete(ConstantStringValues.NuGetPackageBaseDirectory, true); + } + // Delete the generated NuGet packages in the cache. + foreach (string dir in Directory.EnumerateDirectories(RepoInfo.NuGetCachePath, ConstantStringValues.DependencyDirectoryNamePrefix + "*")) + { + Directory.Delete(dir, true); + } + } + catch + { + // No-Op; as this is a precaution - do not throw an exception. + } + } + } +} \ No newline at end of file diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs new file mode 100644 index 000000000000..5f28731b403a --- /dev/null +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs @@ -0,0 +1,77 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Runtime.InteropServices; +using Microsoft.NET.TestFramework; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.NET.TestFramework.Commands; +using Microsoft.NET.TestFramework.ProjectConstruction; +using Xunit; +using static Microsoft.NET.TestFramework.Commands.MSBuildTest; +using Microsoft.DotNet.Cli.Utils; +using System.Xml.Linq; +using System.Runtime.CompilerServices; + +namespace Microsoft.NET.Build.Tests +{ + public class GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback : SdkTest + { + [Fact] + public void Net461_is_implicit_for_Netstandard20() + { + var netstandard20Project = + new TestProject + { + Name = "netstandard20", + TargetFrameworks = "netstandard2.0", + IsSdkProject = true + }; + + var net461Project = + new TestProject + { + Name = "net461_package", + TargetFrameworks = "net461", + IsSdkProject = true + }; + + var net461PackageReference = + new TestPackageReference( + net461Project.Name, + "1.0.0", + ConstantStringValues.ConstructNuGetPackageReferencePath(net461Project)); + + netstandard20Project.PackageReferences.Add(net461PackageReference); + + var net461PackageTestAsset = _testAssetsManager.CreateTestProject( + net461Project, + ConstantStringValues.TestDirectoriesNamePrefix, + ConstantStringValues.NuGetSharedDirectoryNamePostfix); + var packageRestoreCommand = + net461PackageTestAsset.GetRestoreCommand(relativePath: net461Project.Name).Execute().Should().Pass(); + var dependencyProjectDirectory = Path.Combine(net461PackageTestAsset.TestRoot, net461Project.Name); + var packagePackCommand = new PackCommand(Stage0MSBuild, dependencyProjectDirectory).Execute().Should().Pass(); + + var netstandard20TestAsset = _testAssetsManager.CreateTestProject( + netstandard20Project, + ConstantStringValues.TestDirectoriesNamePrefix, "_netstandard20_net461"); + var restoreCommand = netstandard20TestAsset.GetRestoreCommand(relativePath: netstandard20Project.Name); + + foreach (TestPackageReference packageReference in netstandard20Project.PackageReferences) + { + restoreCommand.AddSource(Path.GetDirectoryName(packageReference.NupkgPath)); + } + + restoreCommand.Execute().Should().Pass(); + + var buildCommand = new BuildCommand( + Stage0MSBuild, + Path.Combine(netstandard20TestAsset.TestRoot, netstandard20Project.Name)); + + buildCommand.Execute().Should().Pass(); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs index 621d226d87e6..e7d671675e93 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs @@ -14,50 +14,6 @@ namespace Microsoft.NET.Build.Tests { - public class ConstantStringValues - { - public static string TestDirectoriesNamePrefix = "Nuget_reference_compat"; - public static string ReferencerDirectoryName = "Reference"; - public static string NuGetSharedDirectoryNamePostfix = "_NuGetDependencies"; - public static string NetstandardToken = "netstandard"; - public static string DependencyDirectoryNamePrefix = "D_"; - public static string NuGetPackageBaseDirectory = Path.Combine(RepoInfo.GetBaseDirectory(), ConstantStringValues.TestDirectoriesNamePrefix + ConstantStringValues.NuGetSharedDirectoryNamePostfix); - } - - public class DeleteNuGetArtifactsFixture : IDisposable - { - public DeleteNuGetArtifactsFixture() - { - DeleteNuGetArtifacts(); - } - - public void Dispose() - { - DeleteNuGetArtifacts(); - } - - private void DeleteNuGetArtifacts() - { - try - { - // Delete the shared NuGet package directory before running all the tests. - if (Directory.Exists(ConstantStringValues.NuGetPackageBaseDirectory)) - { - Directory.Delete(ConstantStringValues.NuGetPackageBaseDirectory, true); - } - // Delete the generated NuGet packages in the cache. - foreach (string dir in Directory.EnumerateDirectories(RepoInfo.NuGetCachePath, ConstantStringValues.DependencyDirectoryNamePrefix + "*")) - { - Directory.Delete(dir, true); - } - } - catch - { - // No-Op; as this is a precaution - do not throw an exception. - } - } - } - public class GivenThatWeWantToVerifyNuGetReferenceCompat : SdkTest, IClassFixture { [Theory] @@ -117,7 +73,10 @@ public void Nuget_reference_compat(string referencerTarget, string testDescripti foreach (string dependencyTarget in rawDependencyTargets.Split(',', ';', ' ').ToList()) { TestProject dependencyProject = GetTestProject(ConstantStringValues.DependencyDirectoryNamePrefix + dependencyTarget.Replace('.', '_'), dependencyTarget, true); - TestPackageReference dependencyPackageReference = new TestPackageReference(dependencyProject.Name, "1.0.0", ConstructNuGetPackageReferencePath(dependencyProject)); + TestPackageReference dependencyPackageReference = new TestPackageReference( + dependencyProject.Name, + "1.0.0", + ConstantStringValues.ConstructNuGetPackageReferencePath(dependencyProject)); // Skip creating the NuGet package if not running on Windows; or if the NuGet package already exists // https://github.com/dotnet/sdk/issues/335 @@ -199,11 +158,5 @@ TestProject GetTestProject(string name, string target, bool isSdkProject) return ret; } - - string ConstructNuGetPackageReferencePath(TestProject dependencyProject) - { - return Path.Combine(ConstantStringValues.NuGetPackageBaseDirectory, dependencyProject.Name, dependencyProject.Name, "bin", "Debug"); - } - } } From 27d0dc735dae8778bc5c74233d65f05ca45dddaf Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Wed, 19 Apr 2017 14:11:19 -0700 Subject: [PATCH 2/5] Adding more tests and an option to disable the implicit package target fallback. --- .../Microsoft.NET.Sdk.BeforeCommon.targets | 2 +- ...t461ToBeAnImplicitPackageTargetFallback.cs | 108 +++++++++++++----- .../Microsoft.NET.TestFramework.csproj | 3 + .../ProjectConstruction/TestProject.cs | 7 ++ .../WindowsOnlyFactAttribute.cs | 19 +++ .../WindowsOnlyTheoryAttribute.cs | 19 +++ 6 files changed, 131 insertions(+), 27 deletions(-) create mode 100644 test/Microsoft.NET.TestFramework/WindowsOnlyFactAttribute.cs create mode 100644 test/Microsoft.NET.TestFramework/WindowsOnlyTheoryAttribute.cs diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets index 1755b11b6508..a32237d7e09b 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets @@ -108,7 +108,7 @@ Copyright (c) .NET Foundation. All rights reserved. - + $(PackageTargetFallback);net461 diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs index 5f28731b403a..f219a08e1f6c 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs @@ -17,19 +17,92 @@ namespace Microsoft.NET.Build.Tests { - public class GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback : SdkTest + public class GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback : SdkTest, IClassFixture { - [Fact] - public void Net461_is_implicit_for_Netstandard20() + private TestPackageReference _net461PackageReference; + + [WindowsOnlyTheoryAttribute] + [InlineData("netstandard2.0")] + [InlineData("netcoreapp2.0")] + public void Net461_is_implicit_for_Netstandard_and_Netcore_20(string targetFramework) + { + var testProjectName = targetFramework.Replace(".", "_"); + + var testProjectTestAsset = CreateTestAsset(testProjectName, targetFramework); + + var restoreCommand = testProjectTestAsset.GetRestoreCommand(relativePath: testProjectName); + restoreCommand.AddSource(Path.GetDirectoryName(_net461PackageReference.NupkgPath)); + restoreCommand.Execute().Should().Pass(); + + var buildCommand = new BuildCommand( + Stage0MSBuild, + Path.Combine(testProjectTestAsset.TestRoot, testProjectName)); + buildCommand.Execute().Should().Pass(); + } + + [WindowsOnlyTheoryAttribute] + [InlineData("netstandard1.6")] + [InlineData("netcoreapp1.1")] + public void Net461_is_not_implicit_for_Netstandard_and_Netcore_less_than_20(string targetFramework) + { + var testProjectName = targetFramework.Replace(".", "_"); + + var testProjectTestAsset = CreateTestAsset(testProjectName, targetFramework); + + var restoreCommand = testProjectTestAsset.GetRestoreCommand(relativePath: testProjectName); + restoreCommand.AddSource(Path.GetDirectoryName(_net461PackageReference.NupkgPath)); + restoreCommand.Execute().Should().Fail(); + } + + [WindowsOnlyFact] + public void It_is_possible_to_disabled_net461_implicit_package_target_fallback() + { + const string testProjectName = "netstandard20"; + + var testProjectTestAsset = CreateTestAsset( + testProjectName, + "netstandard2.0", + new Dictionary { {"DisableImplicitPackageTargetFallback", "true" } }); + + var restoreCommand = testProjectTestAsset.GetRestoreCommand(relativePath: testProjectName); + restoreCommand.AddSource(Path.GetDirectoryName(_net461PackageReference.NupkgPath)); + restoreCommand.Execute().Should().Fail(); + } + + private TestAsset CreateTestAsset( + string testProjectName, + string targetFramework, + Dictionary additionalProperties = null) { - var netstandard20Project = + _net461PackageReference = CreateNet461Package(); + + var testProject = new TestProject { - Name = "netstandard20", - TargetFrameworks = "netstandard2.0", + Name = testProjectName, + TargetFrameworks = targetFramework, IsSdkProject = true }; + if (additionalProperties != null) + { + foreach (var additionalProperty in additionalProperties) + { + testProject.AdditionalProperties.Add(additionalProperty.Key, additionalProperty.Value); + } + } + + testProject.PackageReferences.Add(_net461PackageReference); + + var testProjectTestAsset = _testAssetsManager.CreateTestProject( + testProject, + ConstantStringValues.TestDirectoriesNamePrefix, $"_{testProjectName}_net461"); + + return testProjectTestAsset; + } + + private TestPackageReference CreateNet461Package() + { var net461Project = new TestProject { @@ -44,8 +117,6 @@ public void Net461_is_implicit_for_Netstandard20() "1.0.0", ConstantStringValues.ConstructNuGetPackageReferencePath(net461Project)); - netstandard20Project.PackageReferences.Add(net461PackageReference); - var net461PackageTestAsset = _testAssetsManager.CreateTestProject( net461Project, ConstantStringValues.TestDirectoriesNamePrefix, @@ -53,25 +124,10 @@ public void Net461_is_implicit_for_Netstandard20() var packageRestoreCommand = net461PackageTestAsset.GetRestoreCommand(relativePath: net461Project.Name).Execute().Should().Pass(); var dependencyProjectDirectory = Path.Combine(net461PackageTestAsset.TestRoot, net461Project.Name); - var packagePackCommand = new PackCommand(Stage0MSBuild, dependencyProjectDirectory).Execute().Should().Pass(); + var packagePackCommand = + new PackCommand(Stage0MSBuild, dependencyProjectDirectory).Execute().Should().Pass(); - var netstandard20TestAsset = _testAssetsManager.CreateTestProject( - netstandard20Project, - ConstantStringValues.TestDirectoriesNamePrefix, "_netstandard20_net461"); - var restoreCommand = netstandard20TestAsset.GetRestoreCommand(relativePath: netstandard20Project.Name); - - foreach (TestPackageReference packageReference in netstandard20Project.PackageReferences) - { - restoreCommand.AddSource(Path.GetDirectoryName(packageReference.NupkgPath)); - } - - restoreCommand.Execute().Should().Pass(); - - var buildCommand = new BuildCommand( - Stage0MSBuild, - Path.Combine(netstandard20TestAsset.TestRoot, netstandard20Project.Name)); - - buildCommand.Execute().Should().Pass(); + return net461PackageReference; } } } \ No newline at end of file diff --git a/test/Microsoft.NET.TestFramework/Microsoft.NET.TestFramework.csproj b/test/Microsoft.NET.TestFramework/Microsoft.NET.TestFramework.csproj index 4e76b9736bb7..62f9f5bc5677 100644 --- a/test/Microsoft.NET.TestFramework/Microsoft.NET.TestFramework.csproj +++ b/test/Microsoft.NET.TestFramework/Microsoft.NET.TestFramework.csproj @@ -30,6 +30,9 @@ 1.3.0 + + $(xunitVersion) + diff --git a/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs b/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs index eebe90d7f954..e46135a9f35e 100644 --- a/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs +++ b/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs @@ -33,6 +33,8 @@ public class TestProject public Dictionary SourceFiles { get; } = new Dictionary(); + public Dictionary AdditionalProperties { get; } = new Dictionary(); + private static string GetShortTargetFrameworkIdentifier(string targetFramework) { int identifierLength = 0; @@ -168,6 +170,11 @@ internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder) targetFrameworkVersionElement.SetValue(this.TargetFrameworkVersion); } + foreach (var additionalProperty in AdditionalProperties) + { + propertyGroup.Add(new XElement($"{ns}{additionalProperty.Key}", additionalProperty.Value)); + } + if (this.IsExe) { propertyGroup.Element(ns + "OutputType").SetValue("Exe"); diff --git a/test/Microsoft.NET.TestFramework/WindowsOnlyFactAttribute.cs b/test/Microsoft.NET.TestFramework/WindowsOnlyFactAttribute.cs new file mode 100644 index 000000000000..c017b43652c1 --- /dev/null +++ b/test/Microsoft.NET.TestFramework/WindowsOnlyFactAttribute.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.PlatformAbstractions; +using Xunit; + +namespace Microsoft.NET.TestFramework +{ + public class WindowsOnlyFactAttribute : FactAttribute + { + public WindowsOnlyFactAttribute() + { + if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) + { + this.Skip = "This test requires Windows to run"; + } + } + } +} diff --git a/test/Microsoft.NET.TestFramework/WindowsOnlyTheoryAttribute.cs b/test/Microsoft.NET.TestFramework/WindowsOnlyTheoryAttribute.cs new file mode 100644 index 000000000000..288f708b6a0c --- /dev/null +++ b/test/Microsoft.NET.TestFramework/WindowsOnlyTheoryAttribute.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Microsoft.DotNet.PlatformAbstractions; +using Xunit; + +namespace Microsoft.NET.TestFramework +{ + public class WindowsOnlyTheoryAttribute : TheoryAttribute + { + public WindowsOnlyTheoryAttribute() + { + if (RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) + { + this.Skip = "This test requires Windows to run"; + } + } + } +} From 5d4c9cd46639215df083c18004635354296780f3 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Wed, 19 Apr 2017 17:18:11 -0700 Subject: [PATCH 3/5] Modifying build.proj to not error on xunit execution returning not 0. It returns not zero when tests are skipped as well. Instead, let's rely on Jenkins validating the xml file. Fixing the test that I implicit set to fail to test Jenkins xml test parsing. Also changing the name of the test projects to avoid conflict when using the files. --- build/build.proj | 7 +- ...t461ToBeAnImplicitPackageTargetFallback.cs | 133 ------------------ ...nThatWeWantToVerifyNuGetReferenceCompat.cs | 111 +++++++++++++++ 3 files changed, 112 insertions(+), 139 deletions(-) delete mode 100644 test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs diff --git a/build/build.proj b/build/build.proj index bab56be1cd0f..d31995b7729a 100644 --- a/build/build.proj +++ b/build/build.proj @@ -170,12 +170,7 @@ LogStandardErrorAsError="true" WorkingDirectory="$(TestsDirectory)" IgnoreExitCode="true" - > - - - - - + /> diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs deleted file mode 100644 index f219a08e1f6c..000000000000 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback.cs +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (c) .NET Foundation and contributors. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Runtime.InteropServices; -using Microsoft.NET.TestFramework; -using Microsoft.NET.TestFramework.Assertions; -using Microsoft.NET.TestFramework.Commands; -using Microsoft.NET.TestFramework.ProjectConstruction; -using Xunit; -using static Microsoft.NET.TestFramework.Commands.MSBuildTest; -using Microsoft.DotNet.Cli.Utils; -using System.Xml.Linq; -using System.Runtime.CompilerServices; - -namespace Microsoft.NET.Build.Tests -{ - public class GivenThatWeWantNet461ToBeAnImplicitPackageTargetFallback : SdkTest, IClassFixture - { - private TestPackageReference _net461PackageReference; - - [WindowsOnlyTheoryAttribute] - [InlineData("netstandard2.0")] - [InlineData("netcoreapp2.0")] - public void Net461_is_implicit_for_Netstandard_and_Netcore_20(string targetFramework) - { - var testProjectName = targetFramework.Replace(".", "_"); - - var testProjectTestAsset = CreateTestAsset(testProjectName, targetFramework); - - var restoreCommand = testProjectTestAsset.GetRestoreCommand(relativePath: testProjectName); - restoreCommand.AddSource(Path.GetDirectoryName(_net461PackageReference.NupkgPath)); - restoreCommand.Execute().Should().Pass(); - - var buildCommand = new BuildCommand( - Stage0MSBuild, - Path.Combine(testProjectTestAsset.TestRoot, testProjectName)); - buildCommand.Execute().Should().Pass(); - } - - [WindowsOnlyTheoryAttribute] - [InlineData("netstandard1.6")] - [InlineData("netcoreapp1.1")] - public void Net461_is_not_implicit_for_Netstandard_and_Netcore_less_than_20(string targetFramework) - { - var testProjectName = targetFramework.Replace(".", "_"); - - var testProjectTestAsset = CreateTestAsset(testProjectName, targetFramework); - - var restoreCommand = testProjectTestAsset.GetRestoreCommand(relativePath: testProjectName); - restoreCommand.AddSource(Path.GetDirectoryName(_net461PackageReference.NupkgPath)); - restoreCommand.Execute().Should().Fail(); - } - - [WindowsOnlyFact] - public void It_is_possible_to_disabled_net461_implicit_package_target_fallback() - { - const string testProjectName = "netstandard20"; - - var testProjectTestAsset = CreateTestAsset( - testProjectName, - "netstandard2.0", - new Dictionary { {"DisableImplicitPackageTargetFallback", "true" } }); - - var restoreCommand = testProjectTestAsset.GetRestoreCommand(relativePath: testProjectName); - restoreCommand.AddSource(Path.GetDirectoryName(_net461PackageReference.NupkgPath)); - restoreCommand.Execute().Should().Fail(); - } - - private TestAsset CreateTestAsset( - string testProjectName, - string targetFramework, - Dictionary additionalProperties = null) - { - _net461PackageReference = CreateNet461Package(); - - var testProject = - new TestProject - { - Name = testProjectName, - TargetFrameworks = targetFramework, - IsSdkProject = true - }; - - if (additionalProperties != null) - { - foreach (var additionalProperty in additionalProperties) - { - testProject.AdditionalProperties.Add(additionalProperty.Key, additionalProperty.Value); - } - } - - testProject.PackageReferences.Add(_net461PackageReference); - - var testProjectTestAsset = _testAssetsManager.CreateTestProject( - testProject, - ConstantStringValues.TestDirectoriesNamePrefix, $"_{testProjectName}_net461"); - - return testProjectTestAsset; - } - - private TestPackageReference CreateNet461Package() - { - var net461Project = - new TestProject - { - Name = "net461_package", - TargetFrameworks = "net461", - IsSdkProject = true - }; - - var net461PackageReference = - new TestPackageReference( - net461Project.Name, - "1.0.0", - ConstantStringValues.ConstructNuGetPackageReferencePath(net461Project)); - - var net461PackageTestAsset = _testAssetsManager.CreateTestProject( - net461Project, - ConstantStringValues.TestDirectoriesNamePrefix, - ConstantStringValues.NuGetSharedDirectoryNamePostfix); - var packageRestoreCommand = - net461PackageTestAsset.GetRestoreCommand(relativePath: net461Project.Name).Execute().Should().Pass(); - var dependencyProjectDirectory = Path.Combine(net461PackageTestAsset.TestRoot, net461Project.Name); - var packagePackCommand = - new PackCommand(Stage0MSBuild, dependencyProjectDirectory).Execute().Should().Pass(); - - return net461PackageReference; - } - } -} \ No newline at end of file diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs index e7d671675e93..66891e5f9413 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs @@ -16,6 +16,8 @@ namespace Microsoft.NET.Build.Tests { public class GivenThatWeWantToVerifyNuGetReferenceCompat : SdkTest, IClassFixture { + private TestPackageReference _net461PackageReference; + [Theory] [InlineData("net45", "Full", "netstandard1.0 netstandard1.1 net45", true, true)] [InlineData("net451", "Full", "netstandard1.0 netstandard1.1 netstandard1.2 net45 net451", true, true)] @@ -139,6 +141,115 @@ public void Nuget_reference_compat(string referencerTarget, string testDescripti } } + [WindowsOnlyTheoryAttribute] + [InlineData("netstandard2.0")] + [InlineData("netcoreapp2.0")] + public void Net461_is_implicit_for_Netstandard_and_Netcore_20(string targetFramework) + { + var testProjectName = targetFramework.Replace(".", "_") + "implicit_ptf"; + + var testProjectTestAsset = CreateTestAsset(testProjectName, targetFramework); + + var restoreCommand = testProjectTestAsset.GetRestoreCommand(relativePath: testProjectName); + restoreCommand.AddSource(Path.GetDirectoryName(_net461PackageReference.NupkgPath)); + restoreCommand.Execute().Should().Pass(); + + var buildCommand = new BuildCommand( + Stage0MSBuild, + Path.Combine(testProjectTestAsset.TestRoot, testProjectName)); + buildCommand.Execute().Should().Pass(); + } + + [WindowsOnlyTheoryAttribute] + [InlineData("netstandard1.6")] + [InlineData("netcoreapp1.1")] + public void Net461_is_not_implicit_for_Netstandard_and_Netcore_less_than_20(string targetFramework) + { + var testProjectName = targetFramework.Replace(".", "_") + "non_implicit_ptf"; + + var testProjectTestAsset = CreateTestAsset(testProjectName, targetFramework); + + var restoreCommand = testProjectTestAsset.GetRestoreCommand(relativePath: testProjectName); + restoreCommand.AddSource(Path.GetDirectoryName(_net461PackageReference.NupkgPath)); + restoreCommand.Execute().Should().Fail(); + } + + [WindowsOnlyFact] + public void It_is_possible_to_disabled_net461_implicit_package_target_fallback() + { + const string testProjectName = "netstandard20_disabled_ptf"; + + var testProjectTestAsset = CreateTestAsset( + testProjectName, + "netstandard2.0", + new Dictionary { {"DisableImplicitPackageTargetFallback", "true" } }); + + var restoreCommand = testProjectTestAsset.GetRestoreCommand(relativePath: testProjectName); + restoreCommand.AddSource(Path.GetDirectoryName(_net461PackageReference.NupkgPath)); + restoreCommand.Execute().Should().Fail(); + } + + private TestAsset CreateTestAsset( + string testProjectName, + string targetFramework, + Dictionary additionalProperties = null) + { + _net461PackageReference = CreateNet461Package(testProjectName); + + var testProject = + new TestProject + { + Name = testProjectName, + TargetFrameworks = targetFramework, + IsSdkProject = true + }; + + if (additionalProperties != null) + { + foreach (var additionalProperty in additionalProperties) + { + testProject.AdditionalProperties.Add(additionalProperty.Key, additionalProperty.Value); + } + } + + testProject.PackageReferences.Add(_net461PackageReference); + + var testProjectTestAsset = _testAssetsManager.CreateTestProject( + testProject, + ConstantStringValues.TestDirectoriesNamePrefix, $"_{testProjectName}_net461"); + + return testProjectTestAsset; + } + + private TestPackageReference CreateNet461Package(string testProjectName) + { + var net461Project = + new TestProject + { + Name = $"net461_{testProjectName}", + TargetFrameworks = "net461", + IsSdkProject = true + }; + + var net461PackageReference = + new TestPackageReference( + net461Project.Name, + "1.0.0", + ConstantStringValues.ConstructNuGetPackageReferencePath(net461Project)); + + var net461PackageTestAsset = _testAssetsManager.CreateTestProject( + net461Project, + ConstantStringValues.TestDirectoriesNamePrefix, + ConstantStringValues.NuGetSharedDirectoryNamePostfix); + var packageRestoreCommand = + net461PackageTestAsset.GetRestoreCommand(relativePath: net461Project.Name).Execute().Should().Pass(); + var dependencyProjectDirectory = Path.Combine(net461PackageTestAsset.TestRoot, net461Project.Name); + var packagePackCommand = + new PackCommand(Stage0MSBuild, dependencyProjectDirectory).Execute().Should().Pass(); + + return net461PackageReference; + } + TestProject GetTestProject(string name, string target, bool isSdkProject) { TestProject ret = new TestProject() From aa416d0c6bbdb00e1c382e9f769b394904076859 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Thu, 20 Apr 2017 10:16:37 -0700 Subject: [PATCH 4/5] Reducing the path length of the net 461 package project. --- ...nThatWeWantToVerifyNuGetReferenceCompat.cs | 51 ++++++++++++++----- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs index 66891e5f9413..d0b1686c1ae6 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs @@ -146,6 +146,16 @@ public void Nuget_reference_compat(string referencerTarget, string testDescripti [InlineData("netcoreapp2.0")] public void Net461_is_implicit_for_Netstandard_and_Netcore_20(string targetFramework) { + if (UsingFullFrameworkMSBuild) + { + // Fullframework NuGet versioning on Jenkins infrastructure issue + // https://github.com/dotnet/sdk/issues/1041 + + // Disabled on full framework MSBuild until CI machines have VS with bundled .NET Core / .NET Standard versions + // See https://github.com/dotnet/sdk/issues/1077 + return; + } + var testProjectName = targetFramework.Replace(".", "_") + "implicit_ptf"; var testProjectTestAsset = CreateTestAsset(testProjectName, targetFramework); @@ -177,6 +187,16 @@ public void Net461_is_not_implicit_for_Netstandard_and_Netcore_less_than_20(stri [WindowsOnlyFact] public void It_is_possible_to_disabled_net461_implicit_package_target_fallback() { + if (UsingFullFrameworkMSBuild) + { + // Fullframework NuGet versioning on Jenkins infrastructure issue + // https://github.com/dotnet/sdk/issues/1041 + + // Disabled on full framework MSBuild until CI machines have VS with bundled .NET Core / .NET Standard versions + // See https://github.com/dotnet/sdk/issues/1077 + return; + } + const string testProjectName = "netstandard20_disabled_ptf"; var testProjectTestAsset = CreateTestAsset( @@ -194,7 +214,7 @@ private TestAsset CreateTestAsset( string targetFramework, Dictionary additionalProperties = null) { - _net461PackageReference = CreateNet461Package(testProjectName); + _net461PackageReference = CreateNet461Package(); var testProject = new TestProject @@ -216,17 +236,18 @@ private TestAsset CreateTestAsset( var testProjectTestAsset = _testAssetsManager.CreateTestProject( testProject, - ConstantStringValues.TestDirectoriesNamePrefix, $"_{testProjectName}_net461"); + string.Empty, + $"{testProjectName}_net461"); return testProjectTestAsset; } - private TestPackageReference CreateNet461Package(string testProjectName) + private TestPackageReference CreateNet461Package() { var net461Project = new TestProject { - Name = $"net461_{testProjectName}", + Name = $"net461_pkg", TargetFrameworks = "net461", IsSdkProject = true }; @@ -237,15 +258,19 @@ private TestPackageReference CreateNet461Package(string testProjectName) "1.0.0", ConstantStringValues.ConstructNuGetPackageReferencePath(net461Project)); - var net461PackageTestAsset = _testAssetsManager.CreateTestProject( - net461Project, - ConstantStringValues.TestDirectoriesNamePrefix, - ConstantStringValues.NuGetSharedDirectoryNamePostfix); - var packageRestoreCommand = - net461PackageTestAsset.GetRestoreCommand(relativePath: net461Project.Name).Execute().Should().Pass(); - var dependencyProjectDirectory = Path.Combine(net461PackageTestAsset.TestRoot, net461Project.Name); - var packagePackCommand = - new PackCommand(Stage0MSBuild, dependencyProjectDirectory).Execute().Should().Pass(); + if (!net461PackageReference.NuGetPackageExists()) + { + var net461PackageTestAsset = + _testAssetsManager.CreateTestProject( + net461Project, + ConstantStringValues.TestDirectoriesNamePrefix, + ConstantStringValues.NuGetSharedDirectoryNamePostfix); + var packageRestoreCommand = + net461PackageTestAsset.GetRestoreCommand(relativePath: net461Project.Name).Execute().Should().Pass(); + var dependencyProjectDirectory = Path.Combine(net461PackageTestAsset.TestRoot, net461Project.Name); + var packagePackCommand = + new PackCommand(Stage0MSBuild, dependencyProjectDirectory).Execute().Should().Pass(); + } return net461PackageReference; } From dc11535462302803e9cc1bfed2cf0e59de462a68 Mon Sep 17 00:00:00 2001 From: Livar Cunha Date: Fri, 21 Apr 2017 10:23:57 -0700 Subject: [PATCH 5/5] Addressing review feedback and adding new attributes so that our tests can be more xunity. --- ...nThatWeWantToVerifyNuGetReferenceCompat.cs | 26 +++---------------- .../CoreMSBuildAndWindowsOnlyFactAttribute.cs | 22 ++++++++++++++++ ...oreMSBuildAndWindowsOnlyTheoryAttribute.cs | 22 ++++++++++++++++ .../CoreMSBuildOnlyFactAttribute.cs | 22 ++++++++++++++++ .../CoreMSBuildOnlyTheoryAttribute.cs | 22 ++++++++++++++++ .../ProjectConstruction/TestProject.cs | 2 +- 6 files changed, 92 insertions(+), 24 deletions(-) create mode 100644 test/Microsoft.NET.TestFramework/CoreMSBuildAndWindowsOnlyFactAttribute.cs create mode 100644 test/Microsoft.NET.TestFramework/CoreMSBuildAndWindowsOnlyTheoryAttribute.cs create mode 100644 test/Microsoft.NET.TestFramework/CoreMSBuildOnlyFactAttribute.cs create mode 100644 test/Microsoft.NET.TestFramework/CoreMSBuildOnlyTheoryAttribute.cs diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs index d0b1686c1ae6..816e33b79806 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToVerifyNuGetReferenceCompat.cs @@ -141,21 +141,11 @@ public void Nuget_reference_compat(string referencerTarget, string testDescripti } } - [WindowsOnlyTheoryAttribute] + [CoreMSBuildAndWindowsOnlyTheory] [InlineData("netstandard2.0")] [InlineData("netcoreapp2.0")] public void Net461_is_implicit_for_Netstandard_and_Netcore_20(string targetFramework) { - if (UsingFullFrameworkMSBuild) - { - // Fullframework NuGet versioning on Jenkins infrastructure issue - // https://github.com/dotnet/sdk/issues/1041 - - // Disabled on full framework MSBuild until CI machines have VS with bundled .NET Core / .NET Standard versions - // See https://github.com/dotnet/sdk/issues/1077 - return; - } - var testProjectName = targetFramework.Replace(".", "_") + "implicit_ptf"; var testProjectTestAsset = CreateTestAsset(testProjectName, targetFramework); @@ -170,7 +160,7 @@ public void Net461_is_implicit_for_Netstandard_and_Netcore_20(string targetFrame buildCommand.Execute().Should().Pass(); } - [WindowsOnlyTheoryAttribute] + [WindowsOnlyTheory] [InlineData("netstandard1.6")] [InlineData("netcoreapp1.1")] public void Net461_is_not_implicit_for_Netstandard_and_Netcore_less_than_20(string targetFramework) @@ -184,19 +174,9 @@ public void Net461_is_not_implicit_for_Netstandard_and_Netcore_less_than_20(stri restoreCommand.Execute().Should().Fail(); } - [WindowsOnlyFact] + [CoreMSBuildAndWindowsOnlyTheory] public void It_is_possible_to_disabled_net461_implicit_package_target_fallback() { - if (UsingFullFrameworkMSBuild) - { - // Fullframework NuGet versioning on Jenkins infrastructure issue - // https://github.com/dotnet/sdk/issues/1041 - - // Disabled on full framework MSBuild until CI machines have VS with bundled .NET Core / .NET Standard versions - // See https://github.com/dotnet/sdk/issues/1077 - return; - } - const string testProjectName = "netstandard20_disabled_ptf"; var testProjectTestAsset = CreateTestAsset( diff --git a/test/Microsoft.NET.TestFramework/CoreMSBuildAndWindowsOnlyFactAttribute.cs b/test/Microsoft.NET.TestFramework/CoreMSBuildAndWindowsOnlyFactAttribute.cs new file mode 100644 index 000000000000..724d96c969d3 --- /dev/null +++ b/test/Microsoft.NET.TestFramework/CoreMSBuildAndWindowsOnlyFactAttribute.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.DotNet.PlatformAbstractions; +using Xunit; + +namespace Microsoft.NET.TestFramework +{ + public class CoreMSBuildAndWindowsOnlyFactAttribute : TheoryAttribute + { + public CoreMSBuildAndWindowsOnlyFactAttribute() + { + string msbuildPath = Environment.GetEnvironmentVariable("DOTNET_SDK_TEST_MSBUILD_PATH"); + bool usingFullFrameworkMSBuild = !string.IsNullOrEmpty(msbuildPath); + if (usingFullFrameworkMSBuild || RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) + { + this.Skip = "This test requires Core MSBuild and Windows to run"; + } + } + } +} diff --git a/test/Microsoft.NET.TestFramework/CoreMSBuildAndWindowsOnlyTheoryAttribute.cs b/test/Microsoft.NET.TestFramework/CoreMSBuildAndWindowsOnlyTheoryAttribute.cs new file mode 100644 index 000000000000..52cf22046f99 --- /dev/null +++ b/test/Microsoft.NET.TestFramework/CoreMSBuildAndWindowsOnlyTheoryAttribute.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.DotNet.PlatformAbstractions; +using Xunit; + +namespace Microsoft.NET.TestFramework +{ + public class CoreMSBuildAndWindowsOnlyTheoryAttribute : TheoryAttribute + { + public CoreMSBuildAndWindowsOnlyTheoryAttribute() + { + string msbuildPath = Environment.GetEnvironmentVariable("DOTNET_SDK_TEST_MSBUILD_PATH"); + bool usingFullFrameworkMSBuild = !string.IsNullOrEmpty(msbuildPath); + if (usingFullFrameworkMSBuild || RuntimeEnvironment.OperatingSystemPlatform != Platform.Windows) + { + this.Skip = "This test requires Core MSBuild and Windows to run"; + } + } + } +} diff --git a/test/Microsoft.NET.TestFramework/CoreMSBuildOnlyFactAttribute.cs b/test/Microsoft.NET.TestFramework/CoreMSBuildOnlyFactAttribute.cs new file mode 100644 index 000000000000..26ac04780a7d --- /dev/null +++ b/test/Microsoft.NET.TestFramework/CoreMSBuildOnlyFactAttribute.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.DotNet.PlatformAbstractions; +using Xunit; + +namespace Microsoft.NET.TestFramework +{ + public class CoreMSBuildOnlyFactAttribute : FactAttribute + { + public CoreMSBuildOnlyFactAttribute() + { + string msbuildPath = Environment.GetEnvironmentVariable("DOTNET_SDK_TEST_MSBUILD_PATH"); + bool usingFullFrameworkMSBuild = !string.IsNullOrEmpty(msbuildPath); + if (usingFullFrameworkMSBuild) + { + this.Skip = "This test requires Core MSBuild to run"; + } + } + } +} diff --git a/test/Microsoft.NET.TestFramework/CoreMSBuildOnlyTheoryAttribute.cs b/test/Microsoft.NET.TestFramework/CoreMSBuildOnlyTheoryAttribute.cs new file mode 100644 index 000000000000..f2502aee7e24 --- /dev/null +++ b/test/Microsoft.NET.TestFramework/CoreMSBuildOnlyTheoryAttribute.cs @@ -0,0 +1,22 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.DotNet.PlatformAbstractions; +using Xunit; + +namespace Microsoft.NET.TestFramework +{ + public class CoreMSBuildOnlyTheoryAttribute : TheoryAttribute + { + public CoreMSBuildOnlyTheoryAttribute() + { + string msbuildPath = Environment.GetEnvironmentVariable("DOTNET_SDK_TEST_MSBUILD_PATH"); + bool usingFullFrameworkMSBuild = !string.IsNullOrEmpty(msbuildPath); + if (usingFullFrameworkMSBuild) + { + this.Skip = "This test requires Core MSBuild to run"; + } + } + } +} diff --git a/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs b/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs index e46135a9f35e..2cc184bf5e40 100644 --- a/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs +++ b/test/Microsoft.NET.TestFramework/ProjectConstruction/TestProject.cs @@ -172,7 +172,7 @@ internal void Create(TestAsset targetTestAsset, string testProjectsSourceFolder) foreach (var additionalProperty in AdditionalProperties) { - propertyGroup.Add(new XElement($"{ns}{additionalProperty.Key}", additionalProperty.Value)); + propertyGroup.Add(new XElement(ns + additionalProperty.Key, additionalProperty.Value)); } if (this.IsExe)