From 8952139ae0d63e565a316698bf40089baa7e834d Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Thu, 25 May 2017 18:18:01 -0700 Subject: [PATCH 1/2] Don't generate deps or runtimeconfig files when build has failed but _CleanRecordFileWrites is being run Fixes #1234 --- .../build/Microsoft.NET.Sdk.targets | 4 +-- .../GivenThatWeWantToBuildADesktopExe.cs | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.targets index 0019baf1cf2d..1d87448fd3f7 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.targets @@ -82,7 +82,7 @@ Copyright (c) .NET Foundation. All rights reserved. @@ -126,7 +126,7 @@ Copyright (c) .NET Foundation. All rights reserved. diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs index cb1c1fc5709a..d0990faeda0c 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs @@ -18,6 +18,7 @@ using static Microsoft.NET.TestFramework.Commands.MSBuildTest; using Xunit.Abstractions; +using System.Text.RegularExpressions; namespace Microsoft.NET.Build.Tests { @@ -312,6 +313,41 @@ public static void Main(string [] args) } + [Fact] + public void It_reports_a_single_failure_if_reference_assemblies_are_not_found() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return; + } + + var testProject = new TestProject() + { + Name = "MissingReferenceAssemblies", + // A version of .NET we don't expect to exist + TargetFrameworks = "net469", + IsSdkProject = true, + IsExe = true + }; + + var testAsset = _testAssetsManager.CreateTestProject(testProject, testProject.Name) + .Restore(Log, testProject.Name); + + var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); + + var result = buildCommand.Execute(); + + result.Should().Fail(); + + // Error code for reference assemblies not found + result.StdOut.Should().Contain("MSB3644"); + + // Error code for exception generated from task + result.StdOut.Should().NotContain("MSB4018"); + + Regex.Matches(result.StdOut, "error").Count.Should().Be(1); + } + [Fact] public void It_does_not_report_conflicts_if_the_same_framework_assembly_is_referenced_multiple_times() { From 90612fd2a387f76b26c0f3e5677b012bdc1d1dfa Mon Sep 17 00:00:00 2001 From: Daniel Plaisted Date: Fri, 26 May 2017 12:14:57 -0700 Subject: [PATCH 2/2] Switch to better check that there's only one error when reference assemblies aren't found --- .../GivenThatWeWantToBuildADesktopExe.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs index d0990faeda0c..b3799db12a36 100644 --- a/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs +++ b/test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildADesktopExe.cs @@ -335,7 +335,8 @@ public void It_reports_a_single_failure_if_reference_assemblies_are_not_found() var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); - var result = buildCommand.Execute(); + // Pass "/clp:summary" so that we can check output for string "1 Error(s)" + var result = buildCommand.Execute("/clp:summary"); result.Should().Fail(); @@ -345,7 +346,8 @@ public void It_reports_a_single_failure_if_reference_assemblies_are_not_found() // Error code for exception generated from task result.StdOut.Should().NotContain("MSB4018"); - Regex.Matches(result.StdOut, "error").Count.Should().Be(1); + // Ensure no other errors are generated + result.StdOut.Should().Contain("1 Error(s)"); } [Fact]