From 6a77d3a885604b59e093a84e85c9c98ebe360b1d Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Mon, 18 May 2020 13:49:50 -0700 Subject: [PATCH 1/3] Adding RequiresMSBuildVersion test attributes --- .../RequiresMSBuildVersionFactAttribute.cs | 29 +++++++++++++++++ .../RequiresMSBuildVersionTheoryAttribute.cs | 29 +++++++++++++++++ .../ToolsetInfo.cs | 32 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionFactAttribute.cs create mode 100644 src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionTheoryAttribute.cs diff --git a/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionFactAttribute.cs b/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionFactAttribute.cs new file mode 100644 index 000000000000..5d23c97da7b8 --- /dev/null +++ b/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionFactAttribute.cs @@ -0,0 +1,29 @@ +// 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 Xunit; + +namespace Microsoft.NET.TestFramework +{ + public class RequiresMSBuildVersionFactAttribute : FactAttribute + { + public RequiresMSBuildVersionFactAttribute(string version) + { + if (!Version.TryParse(TestContext.Current.ToolsetUnderTest.MSBuildVersion, out Version msbuildVersion)) + { + this.Skip = $"Failed to determine the version of MSBuild ({ TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + return; + } + if (!Version.TryParse(version, out Version requiredVersion)) + { + this.Skip = $"Failed to determine the version required by this test ({ version })."; + return; + } + if (requiredVersion > msbuildVersion) + { + this.Skip = $"This test requires MSBuild version { version } to run (using { TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + } + } + } +} diff --git a/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionTheoryAttribute.cs b/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionTheoryAttribute.cs new file mode 100644 index 000000000000..862eb7daa001 --- /dev/null +++ b/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionTheoryAttribute.cs @@ -0,0 +1,29 @@ +// 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 Xunit; + +namespace Microsoft.NET.TestFramework +{ + public class RequiresMSBuildVersionTheoryAttribute : TheoryAttribute + { + public RequiresMSBuildVersionTheoryAttribute(string version) + { + if (!Version.TryParse(TestContext.Current.ToolsetUnderTest.MSBuildVersion, out Version msbuildVersion)) + { + this.Skip = $"Failed to determine the version of MSBuild ({ TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + return; + } + if (!Version.TryParse(version, out Version requiredVersion)) + { + this.Skip = $"Failed to determine the version required by this test ({ version })."; + return; + } + if (requiredVersion > msbuildVersion) + { + this.Skip = $"This test requires MSBuild version { version } to run (using { TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + } + } + } +} diff --git a/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs b/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs index 2326ab805b64..4fb6751b032b 100644 --- a/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs +++ b/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs @@ -35,6 +35,21 @@ public string SdkVersion } } + private string _msbuildVersion; + public string MSBuildVersion + { + get + { + if (_msbuildVersion == null) + { + // Initialize MSBuildVersion lazily, as we call `dotnet msbuild -version` to get it, so we need to wait + // for the TestContext to finish being initialize + InitMSBuildVersion(); + } + return _msbuildVersion; + } + } + Lazy _sdkFolderUnderTest; public string SdkFolderUnderTest => _sdkFolderUnderTest.Value; @@ -89,6 +104,23 @@ private void InitSdkVersion() } } + private void InitMSBuildVersion() + { + var logger = new StringTestLogger(); + var command = new DotnetCommand(logger, "msbuild", "-version"); + + command.WorkingDirectory = TestContext.Current.TestExecutionDirectory; + + var result = command.Execute(); + + if (result.ExitCode != 0) + { + throw new Exception("Failed to get msbuild version" + Environment.NewLine + logger.ToString()); + } + + _msbuildVersion = result.StdOut.Split().Last(); + } + public string GetMicrosoftNETBuildExtensionsPath() { if (!string.IsNullOrEmpty(MicrosoftNETBuildExtensionsPathOverride)) From a5d7b36b9ca738d4b5896509e717e952f9736047 Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Tue, 19 May 2020 14:02:02 -0700 Subject: [PATCH 2/3] Converting CoreMEBuildOnly tests to vanilla --- .../DepsFileSkipTests.cs | 3 +- .../GivenFrameworkReferences.cs | 40 +++++++++---------- .../GivenThatWeWantAllResourcesInSatellite.cs | 4 +- ...tSatelliteAssembliesHaveassemblyVersion.cs | 6 +-- .../GivenThatWeWantToCopyLocalDependencies.cs | 6 +-- .../GivenThatWeWantToReferenceAProject.cs | 2 +- .../GivenThereAreDefaultItems.cs | 4 +- .../Net50Targeting.cs | 3 +- ...enThatWeWantToPublishAHelloWorldProject.cs | 2 +- .../GivenThatWeWantToPublishASingleFileApp.cs | 36 ++++++----------- .../GivenThatWeWantToPublishIncrementally.cs | 21 ++++------ .../GivenThatWeWantToRunILLink.cs | 3 +- ...atWeWantToStoreAProjectWithDependencies.cs | 16 ++++---- ...storeProjectsUsingNuGetConfigProperties.cs | 3 +- ...tToRestoreProjectsWithPackageDowngrades.cs | 2 +- 15 files changed, 59 insertions(+), 92 deletions(-) diff --git a/src/Tests/Microsoft.NET.Build.Tests/DepsFileSkipTests.cs b/src/Tests/Microsoft.NET.Build.Tests/DepsFileSkipTests.cs index 5340de07b2e2..3ccc9011ee84 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/DepsFileSkipTests.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/DepsFileSkipTests.cs @@ -61,8 +61,7 @@ public void RuntimeAssemblyFromRuntimePackCanBeSkipped() TestSkippingFile(testProject, filenameToSkip, "runtime"); } - // Core MSBuild only because CI machines don't have updated VS (with support for RuntimeIdentifierGraphPath) - [CoreMSBuildOnlyFact] + [Fact] public void NativeAssetFromPackageCanBeSkipped() { var testProject = new TestProject() diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenFrameworkReferences.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenFrameworkReferences.cs index ee877eee58b1..206aafefb101 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenFrameworkReferences.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenFrameworkReferences.cs @@ -34,9 +34,7 @@ public static void Main(string [] args) } }"; - // Tests in this class are currently Core MSBuild only, as they check for PackageDownload items, - // which are currently only used in Core MSBuild - [CoreMSBuildAndWindowsOnlyFact] + [WindowsOnlyFact] public void Multiple_frameworks_are_written_to_runtimeconfig_when_there_are_multiple_FrameworkReferences() { var testProject = new TestProject() @@ -71,7 +69,7 @@ public void Multiple_frameworks_are_written_to_runtimeconfig_when_there_are_mult runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.AspNetCore.App", "Microsoft.WindowsDesktop.App"); } - [CoreMSBuildOnlyTheory] + [Theory] [InlineData("netcoreapp3.0", false)] [InlineData("netcoreapp3.1", true)] public void Multiple_frameworks_are_written_to_runtimeconfig_for_self_contained_apps(string tfm, bool shouldHaveIncludedFrameworks) @@ -118,7 +116,7 @@ public void Multiple_frameworks_are_written_to_runtimeconfig_for_self_contained_ } } - [CoreMSBuildOnlyFact] + [Fact] public void ForceGenerateRuntimeConfigurationFiles_works_even_on_netFramework_tfm() { var testProject = new TestProject() @@ -147,7 +145,7 @@ public void ForceGenerateRuntimeConfigurationFiles_works_even_on_netFramework_tf Assert.True(File.Exists(runtimeConfigFile), $"Expected to generate runtime config file '{runtimeConfigFile}'"); } - [CoreMSBuildAndWindowsOnlyFact] + [WindowsOnlyFact] public void DuplicateFrameworksAreNotWrittenToRuntimeConfigWhenThereAreDifferentProfiles() { var testProject = new TestProject() @@ -182,7 +180,7 @@ public void DuplicateFrameworksAreNotWrittenToRuntimeConfigWhenThereAreDifferent runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.WindowsDesktop.App"); } - [CoreMSBuildOnlyFact] + [Fact] public void The_build_fails_when_there_is_an_unknown_FrameworkReference() { var testProject = new TestProject() @@ -220,7 +218,7 @@ public void The_build_fails_when_there_is_an_unknown_FrameworkReference() ; } - [CoreMSBuildOnlyTheory] + [Theory] [InlineData("netcoreapp2.1", false)] [InlineData("netcoreapp3.0", true)] public void KnownFrameworkReferencesOnlyApplyToCorrectTargetFramework(string targetFramework, bool shouldPass) @@ -263,7 +261,7 @@ public void KnownFrameworkReferencesOnlyApplyToCorrectTargetFramework(string tar } } - [CoreMSBuildOnlyFact] + [Fact] public void TargetingPackDownloadCanBeDisabled() { var testProject = new TestProject() @@ -389,7 +387,7 @@ public void RollForwardIsNotSupportedOn22(string rollForwardValue, bool valid) } } - [CoreMSBuildAndWindowsOnlyFact] + [WindowsOnlyFact] public void BuildFailsIfRuntimePackIsNotAvailableForRuntimeIdentifier() { var testProject = new TestProject() @@ -427,7 +425,7 @@ public void BuildFailsIfRuntimePackIsNotAvailableForRuntimeIdentifier() .HaveStdOutContaining("1 Error(s)"); } - [CoreMSBuildOnlyFact] + [Fact] public void BuildFailsIfInvalidRuntimeIdentifierIsSpecified() { var testProject = new TestProject() @@ -454,7 +452,7 @@ public void BuildFailsIfInvalidRuntimeIdentifierIsSpecified() .HaveStdOutContaining("1 Error(s)"); } - [CoreMSBuildOnlyFact] + [Fact] public void BuildFailsIfRuntimePackHasNotBeenRestored() { var testProject = new TestProject() @@ -495,7 +493,7 @@ public void BuildFailsIfRuntimePackHasNotBeenRestored() } - [CoreMSBuildOnlyFact] + [Fact] public void RuntimeFrameworkVersionCanBeSpecifiedOnFrameworkReference() { var testProject = new TestProject(); @@ -527,7 +525,7 @@ public void RuntimeFrameworkVersionCanBeSpecifiedOnFrameworkReference() resolvedVersions.AppHostPack["AppHost"].Should().Be("3.0.0-runtimeframeworkversion-property"); } - [CoreMSBuildOnlyFact] + [Fact] public void RuntimeFrameworkVersionCanBeSpecifiedViaProperty() { var testProject = new TestProject(); @@ -550,7 +548,7 @@ public void RuntimeFrameworkVersionCanBeSpecifiedViaProperty() resolvedVersions.AppHostPack["AppHost"].Should().Be(runtimeFrameworkVersion); } - [CoreMSBuildOnlyTheory] + [Theory] [InlineData(true)] [InlineData(false)] public void TargetLatestPatchCanBeSpecifiedOnFrameworkReference(bool attributeValue) @@ -586,7 +584,7 @@ public void TargetLatestPatchCanBeSpecifiedOnFrameworkReference(bool attributeVa resolvedVersions.AppHostPack["AppHost"].Should().Be("3.0.0-apphostversion"); } - [CoreMSBuildOnlyTheory] + [Theory] [InlineData(true)] [InlineData(false)] public void TargetLatestPatchCanBeSpecifiedViaProperty(bool propertyValue) @@ -612,7 +610,7 @@ public void TargetLatestPatchCanBeSpecifiedViaProperty(bool propertyValue) resolvedVersions.AppHostPack["AppHost"].Should().Be("3.0.0-apphostversion"); } - [CoreMSBuildOnlyFact] + [Fact] public void TargetingPackVersionCanBeSpecifiedOnFrameworkReference() { var testProject = new TestProject(); @@ -646,7 +644,7 @@ public void TargetingPackVersionCanBeSpecifiedOnFrameworkReference() // Transitive framework references require NuGet support, which isn't currently // in the full Framework MSBuild we use in CI, so only run these tests for // core MSBuild for now - [CoreMSBuildOnlyFact] + [Fact] public void TransitiveFrameworkReferenceFromProjectReference() { var testProject = new TestProject() @@ -687,7 +685,7 @@ public void TransitiveFrameworkReferenceFromProjectReference() runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.AspNetCore.App"); } - [CoreMSBuildOnlyFact] + [Fact] public void TransitiveFrameworkReferenceFromPackageReference() { var referencedPackage = new TestProject() @@ -742,7 +740,7 @@ public void TransitiveFrameworkReferenceFromPackageReference() runtimeFrameworkNames.Should().BeEquivalentTo("Microsoft.AspNetCore.App"); } - [CoreMSBuildOnlyFact] + [Fact] public void IsTrimmableDefaultsComeFromKnownFrameworkReference() { var testProject = new TestProject(); @@ -759,7 +757,7 @@ public void IsTrimmableDefaultsComeFromKnownFrameworkReference() } } - [CoreMSBuildOnlyFact] + [Fact] public void IsTrimmableCanBeSpecifiedOnFrameworkReference() { var testProject = new TestProject(); diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantAllResourcesInSatellite.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantAllResourcesInSatellite.cs index b6f5b2a99051..da391233159b 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantAllResourcesInSatellite.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantAllResourcesInSatellite.cs @@ -22,9 +22,7 @@ public GivenThatWeWantAllResourcesInSatellite(ITestOutputHelper log) : base(log) { } - // Disable this test on full framework, as generating strong named satellite assemblies with AL.exe requires Admin permissions - // See https://github.com/dotnet/sdk/issues/732 - [CoreMSBuildOnlyFact] + [Fact] public void It_retrieves_strings_successfully() { TestSatelliteResources(Log, _testAssetsManager); diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantSatelliteAssembliesHaveassemblyVersion.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantSatelliteAssembliesHaveassemblyVersion.cs index bdc53b0389bf..2e084318d813 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantSatelliteAssembliesHaveassemblyVersion.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantSatelliteAssembliesHaveassemblyVersion.cs @@ -38,9 +38,7 @@ private void RestoreAndBuildTestAssets() _satelliteAssemblyPath = Path.Combine(outputDirectory.FullName, "en", "AllResourcesInSatellite.resources.dll"); } - // Disable this test on full framework, as generating strong named satellite assemblies with AL.exe requires Admin permissions - // See https://github.com/dotnet/sdk/issues/732 - [CoreMSBuildOnlyFact] + [Fact] public void It_should_produce_same_satelliteAssembly_FileVersionInfo_as_main() { RestoreAndBuildTestAssets(); @@ -57,7 +55,7 @@ public void It_should_produce_same_satelliteAssembly_FileVersionInfo_as_main() satelliteAssemblyFileVersioninfo.FileDescription.Should().Be(mainAssemblyFileVersioninfo.FileDescription); } - [CoreMSBuildOnlyFact] + [Fact] public void It_should_produce_same_satelliteAssembly_AssemblyVersions_as_main() { RestoreAndBuildTestAssets(); diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToCopyLocalDependencies.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToCopyLocalDependencies.cs index f04b6b873bd1..7d46fb141ca1 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToCopyLocalDependencies.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToCopyLocalDependencies.cs @@ -105,8 +105,7 @@ public void It_does_not_copy_local_package_dependencies_when_requested_not_to() })); } - // Core MSBuild only because CI machines don't have updated VS (with support for RuntimeIdentifierGraphPath) - [CoreMSBuildOnlyFact] + [Fact] public void It_copies_local_specific_runtime_package_dependencies_on_build() { const string ProjectName = "TestProjWithPackageDependencies"; @@ -325,8 +324,7 @@ public void It_does_not_copy_local_runtime_dependencies_for_netframework_project }); } - // Core MSBuild only because CI machines don't have updated VS (with support for RuntimeIdentifierGraphPath) - [CoreMSBuildOnlyFact] + [Fact] public void It_copies_local_all_assets_on_self_contained_build() { const string ProjectName = "TestProjWithPackageDependencies"; diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToReferenceAProject.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToReferenceAProject.cs index 04a6a6d5c89c..c649543009a7 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToReferenceAProject.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToReferenceAProject.cs @@ -154,7 +154,7 @@ TestProject GetTestProject(string name, string target, bool isSdkProject) return ret; } - [CoreMSBuildOnlyTheory] + [RequiresMSBuildVersionTheory("16.7.0-preview-20228-01")] [InlineData(true, true)] [InlineData(false, true)] [InlineData(false, false)] diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThereAreDefaultItems.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThereAreDefaultItems.cs index bc6a290ba5a7..e291708455bb 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThereAreDefaultItems.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThereAreDefaultItems.cs @@ -469,9 +469,7 @@ public void Default_items_have_the_correct_relative_paths() }); } - // Disable this test on full framework, as generating strong named satellite assemblies with AL.exe requires Admin permissions - // See https://github.com/dotnet/sdk/issues/732 - [CoreMSBuildOnlyFact] + [Fact] public void Compile_items_can_be_explicitly_specified_while_default_EmbeddedResource_items_are_used() { Action projectChanges = project => diff --git a/src/Tests/Microsoft.NET.Build.Tests/Net50Targeting.cs b/src/Tests/Microsoft.NET.Build.Tests/Net50Targeting.cs index 4cf405b8bb4c..e168ebbba6fa 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/Net50Targeting.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/Net50Targeting.cs @@ -20,8 +20,7 @@ public Net50Targeting(ITestOutputHelper log) : base(log) { } - // Core MSBuild only until VS build we use has NuGet changes for net5.0 - [CoreMSBuildOnlyFact] + [Fact] public void Net50TargetFrameworkParsesAsNetCoreAppTargetFrameworkIdentifier() { var testProject = new TestProject() diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs index 6ecaebc1d04f..7ad989e57397 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs @@ -159,7 +159,7 @@ public static void Main() publishDirectory.Should().HaveFile($"Hello.World{Constants.ExeSuffix}"); } - [CoreMSBuildOnlyTheory] + [Theory] [InlineData("win-arm")] [InlineData("win8-arm")] [InlineData("win81-arm")] diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs index 480bd97ef4e2..8d2babcf84db 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishASingleFileApp.cs @@ -165,8 +165,7 @@ public void It_errors_when_targetting_netcoreapp_2_x() .HaveStdOutContaining(Strings.PublishSingleFileRequiresVersion30); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_generates_a_single_file_for_framework_dependent_apps() { var publishCommand = GetPublishCommand(); @@ -181,8 +180,7 @@ public void It_generates_a_single_file_for_framework_dependent_apps() .OnlyHaveFiles(expectedFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_generates_a_single_file_for_self_contained_apps() { var publishCommand = GetPublishCommand(); @@ -197,8 +195,7 @@ public void It_generates_a_single_file_for_self_contained_apps() .OnlyHaveFiles(expectedFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_generates_a_single_file_including_pdbs() { var publishCommand = GetPublishCommand(); @@ -213,8 +210,7 @@ public void It_generates_a_single_file_including_pdbs() .OnlyHaveFiles(expectedFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildAndWindowsOnlyFact] + [WindowsOnlyFact] public void It_excludes_ni_pdbs_from_single_file() { var publishCommand = GetPublishCommand(); @@ -230,8 +226,7 @@ public void It_excludes_ni_pdbs_from_single_file() .HaveFiles(expectedFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildAndWindowsOnlyFact] + [WindowsOnlyFact] public void It_can_include_ni_pdbs_in_single_file() { var publishCommand = GetPublishCommand(); @@ -246,8 +241,7 @@ public void It_can_include_ni_pdbs_in_single_file() .OnlyHaveFiles(expectedFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyTheory] + [Theory] [InlineData(ExcludeNewest, NewestContent)] [InlineData(ExcludeAlways, AlwaysContent)] public void It_generates_a_single_file_excluding_content(string exclusion, string content) @@ -264,8 +258,7 @@ public void It_generates_a_single_file_excluding_content(string exclusion, strin .OnlyHaveFiles(expectedFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_generates_a_single_file_for_R2R_compiled_Apps() { var publishCommand = GetPublishCommand(); @@ -280,8 +273,7 @@ public void It_generates_a_single_file_for_R2R_compiled_Apps() .OnlyHaveFiles(expectedFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_does_not_rewrite_the_single_file_unnecessarily() { var publishCommand = GetPublishCommand(); @@ -304,8 +296,7 @@ public void It_does_not_rewrite_the_single_file_unnecessarily() fileWriteTimeAfterSecondRun.Should().Be(fileWriteTimeAfterFirstRun); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_rewrites_the_apphost_for_single_file_publish() { var publishCommand = GetPublishCommand(); @@ -329,8 +320,7 @@ public void It_rewrites_the_apphost_for_single_file_publish() singleFileSize.Should().BeGreaterThan(appHostSize); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_rewrites_the_apphost_for_non_single_file_publish() { var publishCommand = GetPublishCommand(); @@ -354,8 +344,7 @@ public void It_rewrites_the_apphost_for_non_single_file_publish() appHostSize.Should().BeLessThan(singleFileSize); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_leaves_host_components_unbundled_when_necessary() { // In.net 5, Single-file bundles are processed in the framework. @@ -392,8 +381,7 @@ public void It_leaves_host_components_unbundled_when_necessary() .OnlyHaveFiles(expectedFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyTheory] + [Theory] [InlineData("netcoreapp3.0", false)] [InlineData("netcoreapp3.0", true)] [InlineData("netcoreapp3.1", false)] diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs index 545fdc478d37..ebbf637b71ef 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishIncrementally.cs @@ -20,8 +20,7 @@ public GivenThatWeWantToPublishIncrementally(ITestOutputHelper log) : base(log) { } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_cleans_before_single_file_publish() { var testProject = new TestProject() @@ -56,8 +55,7 @@ public void It_cleans_before_single_file_publish() CheckPublishOutput(publishDir, expectedSingleExeFiles.Append("UserData.txt"), expectedNonSingleExeFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_cleans_between_renames() { var testProject = new TestProject() @@ -97,8 +95,7 @@ public void It_cleans_between_renames() expectedSingleExeFileExtensions.Select(ending => testProject.Name + ending)); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_cleans_between_single_file_publishes() { var testProject = new TestProject() @@ -132,8 +129,7 @@ public void It_cleans_between_single_file_publishes() CheckPublishOutput(publishDir, expectedSingleExeFiles.Append(testProject.Name + ".dll"), null); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_cleans_before_trimmed_single_file_publish() { var testProject = new TestProject() @@ -169,8 +165,7 @@ public void It_cleans_before_trimmed_single_file_publish() CheckPublishOutput(publishDir, expectedSingleExeFiles.Append("UserData.txt"), expectedNonSingleExeFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_cleans_for_mvc_projects() { // Create new mvc app from template @@ -206,8 +201,7 @@ public void It_cleans_for_mvc_projects() Directory.Exists(Path.Combine(publishDir, "wwwroot")); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_cleans_with_custom_output_dir() { var testProject = new TestProject() @@ -243,8 +237,7 @@ public void It_cleans_with_custom_output_dir() CheckPublishOutput(publishDir, expectedSingleExeFiles.Append("UserData.txt"), expectedNonSingleExeFiles); } - // Core MSBuild only due to https://github.com/dotnet/sdk/issues/4244 - [CoreMSBuildOnlyFact] + [Fact] public void It_cleans_with_multiple_output_dirs() { var testProject = new TestProject() diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs index 95c41e69736c..8bcf68a9df3a 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToRunILLink.cs @@ -134,8 +134,7 @@ public void ILLink_accepts_root_descriptor(string targetFramework) DoesImageHaveMethod(unusedDll, "UnusedMethodToRoot").Should().BeTrue(); } - // Core MSBuild only until VS build we use has NuGet changes for net5.0 - [CoreMSBuildOnlyTheory] + [Theory] [InlineData("_TrimmerBeforeFieldInit")] [InlineData("_TrimmerOverrideRemoval")] [InlineData("_TrimmerUnreachableBodies")] diff --git a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToStoreAProjectWithDependencies.cs b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToStoreAProjectWithDependencies.cs index 7231bf83cd61..60e07f2784fe 100644 --- a/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToStoreAProjectWithDependencies.cs +++ b/src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToStoreAProjectWithDependencies.cs @@ -61,7 +61,7 @@ public GivenThatWeWantToStoreAProjectWithDependencies(ITestOutputHelper log) : b { } - [CoreMSBuildOnlyFact] + [Fact] public void compose_dependencies() { TestAsset simpleDependenciesAsset = _testAssetsManager @@ -96,7 +96,7 @@ public void compose_dependencies() storeDirectory.Should().OnlyHaveFiles(files_on_disk); } - [CoreMSBuildOnlyFact] + [Fact] public void compose_dependencies_noopt() { TestAsset simpleDependenciesAsset = _testAssetsManager @@ -131,7 +131,7 @@ public void compose_dependencies_noopt() storeDirectory.Should().OnlyHaveFiles(files_on_disk); } - [CoreMSBuildOnlyFact] + [Fact] public void store_nativeonlyassets() { TestAsset simpleDependenciesAsset = _testAssetsManager @@ -161,7 +161,7 @@ public void store_nativeonlyassets() storeDirectory.Should().OnlyHaveFiles(files_on_disk); } - [CoreMSBuildOnlyFact] + [Fact] public void compose_multifile() { TestAsset simpleDependenciesAsset = _testAssetsManager @@ -217,7 +217,7 @@ public void compose_multifile() } } - [CoreMSBuildOnlyFact] + [Fact] public void It_uses_star_versions_correctly() { TestAsset targetManifestsAsset = _testAssetsManager @@ -251,7 +251,7 @@ public void It_uses_star_versions_correctly() nugetPackage.Version.Should().BeGreaterThan(NuGetVersion.Parse("4.0.0-rc2")); } - [CoreMSBuildOnlyFact] + [Fact] public void It_creates_profiling_symbols() { TestAsset targetManifestsAsset = _testAssetsManager @@ -300,7 +300,7 @@ public void It_creates_profiling_symbols() } } - [CoreMSBuildOnlyTheory] + [Theory] [InlineData(true)] [InlineData(false)] public void It_stores_when_targeting_netcoreapp3(bool isExe) @@ -340,7 +340,7 @@ public void It_stores_when_targeting_netcoreapp3(bool isExe) }); } - [CoreMSBuildOnlyFact] + [Fact] public void DotnetStoreWithPrunedPackages() { const string TargetFramework = "netcoreapp3.1"; diff --git a/src/Tests/Microsoft.NET.Restore.Tests/GivenThatWeWantToRestoreProjectsUsingNuGetConfigProperties.cs b/src/Tests/Microsoft.NET.Restore.Tests/GivenThatWeWantToRestoreProjectsUsingNuGetConfigProperties.cs index b48e3936f731..fc293a9bc7e9 100644 --- a/src/Tests/Microsoft.NET.Restore.Tests/GivenThatWeWantToRestoreProjectsUsingNuGetConfigProperties.cs +++ b/src/Tests/Microsoft.NET.Restore.Tests/GivenThatWeWantToRestoreProjectsUsingNuGetConfigProperties.cs @@ -25,8 +25,7 @@ public GivenThatWeWantToRestoreProjectsUsingNuGetConfigProperties(ITestOutputHel { } - // https://github.com/dotnet/sdk/issues/1327 - [CoreMSBuildOnlyTheory] + [Theory] [InlineData("netstandard1.3", "1.3", false)] [InlineData("netcoreapp1.0", "1.0", true)] [InlineData("netcoreapp1.1", "1.1", true)] diff --git a/src/Tests/Microsoft.NET.Restore.Tests/GivenThatWeWantToRestoreProjectsWithPackageDowngrades.cs b/src/Tests/Microsoft.NET.Restore.Tests/GivenThatWeWantToRestoreProjectsWithPackageDowngrades.cs index df59250156b9..2b1bd557c951 100644 --- a/src/Tests/Microsoft.NET.Restore.Tests/GivenThatWeWantToRestoreProjectsWithPackageDowngrades.cs +++ b/src/Tests/Microsoft.NET.Restore.Tests/GivenThatWeWantToRestoreProjectsWithPackageDowngrades.cs @@ -53,7 +53,7 @@ public void DowngradeWarningsAreErrorsByDefault() .And.HaveStdOutContaining("NU1605"); } - [CoreMSBuildOnlyFact] + [Fact] public void ItIsPossibleToTurnOffDowngradeWarningsAsErrors() { const string testProjectName = "ProjectWithDowngradeWarning"; From 40256fc6a2a6006a32b653eebd9a351ff635a987 Mon Sep 17 00:00:00 2001 From: Sarah Oslund Date: Tue, 26 May 2020 14:45:59 -0700 Subject: [PATCH 3/3] Add MSBuildVersionCommand, update RequiresMSBuildVersion test attributes --- .../GivenThatWeWantToReferenceAProject.cs | 2 +- .../RequiresMSBuildVersionFactAttribute.cs | 27 +++++++------- .../RequiresMSBuildVersionTheoryAttribute.cs | 27 +++++++------- .../Commands/MSBuildVersionCommand.cs | 35 +++++++++++++++++++ .../ToolsetInfo.cs | 2 +- 5 files changed, 67 insertions(+), 26 deletions(-) create mode 100644 src/Tests/Microsoft.NET.TestFramework/Commands/MSBuildVersionCommand.cs diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToReferenceAProject.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToReferenceAProject.cs index c649543009a7..60dda19d7e12 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToReferenceAProject.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToReferenceAProject.cs @@ -154,7 +154,7 @@ TestProject GetTestProject(string name, string target, bool isSdkProject) return ret; } - [RequiresMSBuildVersionTheory("16.7.0-preview-20228-01")] + [RequiresMSBuildVersionTheory("16.7.1")] [InlineData(true, true)] [InlineData(false, true)] [InlineData(false, false)] diff --git a/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionFactAttribute.cs b/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionFactAttribute.cs index 5d23c97da7b8..b07de809567c 100644 --- a/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionFactAttribute.cs +++ b/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionFactAttribute.cs @@ -10,19 +10,22 @@ public class RequiresMSBuildVersionFactAttribute : FactAttribute { public RequiresMSBuildVersionFactAttribute(string version) { - if (!Version.TryParse(TestContext.Current.ToolsetUnderTest.MSBuildVersion, out Version msbuildVersion)) + if (TestContext.Current.ToolsetUnderTest.ShouldUseFullFrameworkMSBuild) { - this.Skip = $"Failed to determine the version of MSBuild ({ TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; - return; - } - if (!Version.TryParse(version, out Version requiredVersion)) - { - this.Skip = $"Failed to determine the version required by this test ({ version })."; - return; - } - if (requiredVersion > msbuildVersion) - { - this.Skip = $"This test requires MSBuild version { version } to run (using { TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + if (!Version.TryParse(TestContext.Current.ToolsetUnderTest.MSBuildVersion, out Version msbuildVersion)) + { + this.Skip = $"Failed to determine the version of MSBuild ({ TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + return; + } + if (!Version.TryParse(version, out Version requiredVersion)) + { + this.Skip = $"Failed to determine the version required by this test ({ version })."; + return; + } + if (requiredVersion > msbuildVersion) + { + this.Skip = $"This test requires MSBuild version { version } to run (using { TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + } } } } diff --git a/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionTheoryAttribute.cs b/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionTheoryAttribute.cs index 862eb7daa001..09bca5f17035 100644 --- a/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionTheoryAttribute.cs +++ b/src/Tests/Microsoft.NET.TestFramework/Attributes/RequiresMSBuildVersionTheoryAttribute.cs @@ -10,19 +10,22 @@ public class RequiresMSBuildVersionTheoryAttribute : TheoryAttribute { public RequiresMSBuildVersionTheoryAttribute(string version) { - if (!Version.TryParse(TestContext.Current.ToolsetUnderTest.MSBuildVersion, out Version msbuildVersion)) + if (TestContext.Current.ToolsetUnderTest.ShouldUseFullFrameworkMSBuild) { - this.Skip = $"Failed to determine the version of MSBuild ({ TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; - return; - } - if (!Version.TryParse(version, out Version requiredVersion)) - { - this.Skip = $"Failed to determine the version required by this test ({ version })."; - return; - } - if (requiredVersion > msbuildVersion) - { - this.Skip = $"This test requires MSBuild version { version } to run (using { TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + if (!Version.TryParse(TestContext.Current.ToolsetUnderTest.MSBuildVersion, out Version msbuildVersion)) + { + this.Skip = $"Failed to determine the version of MSBuild ({ TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + return; + } + if (!Version.TryParse(version, out Version requiredVersion)) + { + this.Skip = $"Failed to determine the version required by this test ({ version })."; + return; + } + if (requiredVersion > msbuildVersion) + { + this.Skip = $"This test requires MSBuild version { version } to run (using { TestContext.Current.ToolsetUnderTest.MSBuildVersion })."; + } } } } diff --git a/src/Tests/Microsoft.NET.TestFramework/Commands/MSBuildVersionCommand.cs b/src/Tests/Microsoft.NET.TestFramework/Commands/MSBuildVersionCommand.cs new file mode 100644 index 000000000000..e5eea2ae1237 --- /dev/null +++ b/src/Tests/Microsoft.NET.TestFramework/Commands/MSBuildVersionCommand.cs @@ -0,0 +1,35 @@ +// 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.Collections.Generic; +using Xunit.Abstractions; + +namespace Microsoft.NET.TestFramework.Commands +{ + public class MSBuildVersionCommand : TestCommand + { + public MSBuildVersionCommand(ITestOutputHelper log) : base(log) {} + + protected override SdkCommandSpec CreateCommand(IEnumerable args) + { + if (TestContext.Current.ToolsetUnderTest.ShouldUseFullFrameworkMSBuild) + { + return new SdkCommandSpec() + { + FileName = TestContext.Current.ToolsetUnderTest.FullFrameworkMSBuildPath, + Arguments = { "-version" }, + WorkingDirectory = WorkingDirectory + }; + } + else + { + return new SdkCommandSpec() + { + FileName = TestContext.Current.ToolsetUnderTest.DotNetHostPath, + Arguments = { "msbuild", "-version" }, + WorkingDirectory = WorkingDirectory + }; + } + } + } +} diff --git a/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs b/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs index 4fb6751b032b..d4e71814bb2e 100644 --- a/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs +++ b/src/Tests/Microsoft.NET.TestFramework/ToolsetInfo.cs @@ -107,7 +107,7 @@ private void InitSdkVersion() private void InitMSBuildVersion() { var logger = new StringTestLogger(); - var command = new DotnetCommand(logger, "msbuild", "-version"); + var command = new MSBuildVersionCommand(logger); command.WorkingDirectory = TestContext.Current.TestExecutionDirectory;