abort build when an unresolved dependency is found (#2696)

This commit is contained in:
Andrew Stanton-Nurse 2016-04-28 10:02:05 -07:00
parent f8300f8747
commit b98bc1289d
13 changed files with 122 additions and 8 deletions

View file

@ -0,0 +1,12 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -0,0 +1,18 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-*"
},
"ThisIsNotARealDependencyAndIfSomeoneGoesAndAddsAProjectWithThisNameIWillFindThemAndPunishThem": { "target": "project" }
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -0,0 +1,18 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002498"
},
"LibraryWithBuildDependency": { "target": "project" }
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}

View file

@ -0,0 +1,12 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -0,0 +1,18 @@
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002498"
},
"Microsoft.Net.Compilers": {
"type": "build",
"version": "1.1.1"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}

View file

@ -19,6 +19,7 @@ namespace Microsoft.DotNet.TestFramework
internal TestInstance(string testAssetRoot, string testDestination)
{
Console.WriteLine($"Copying {testAssetRoot} to {testDestination}");
if (string.IsNullOrEmpty(testAssetRoot))
{
throw new ArgumentException("testScenario");

View file

@ -138,7 +138,10 @@ namespace Microsoft.DotNet.Tools.Build
var success = managedCompiler.Compile(projectNode.ProjectContext, _args);
if (projectNode.IsRoot)
{
MakeRunnable(projectNode);
if (success)
{
MakeRunnable(projectNode);
}
PrintSummary(projectNode, success);
}

View file

@ -45,7 +45,7 @@ namespace Microsoft.DotNet.Tools.Build
LibraryDescription libraryDescription;
if (lookup.TryGetValue(dependency.Name, out libraryDescription))
{
if (libraryDescription.Identity.Type.Equals(LibraryType.Project))
if (libraryDescription.Resolved && libraryDescription.Identity.Type.Equals(LibraryType.Project))
{
deps.Add(TraverseProject((ProjectDescription)libraryDescription, lookup));
}

View file

@ -63,11 +63,10 @@ namespace Microsoft.DotNet.Tools.Compiler
diagnostics.Add(diag);
}
if (missingFrameworkDiagnostics.Count > 0)
if(diagnostics.Any(d => d.Severity == DiagnosticMessageSeverity.Error))
{
// The framework isn't installed so we should short circuit the rest of the compilation
// so we don't get flooded with errors
PrintSummary(missingFrameworkDiagnostics, sw);
// We got an unresolved dependency or missing framework. Don't continue the compilation.
PrintSummary(diagnostics, sw);
return false;
}

View file

@ -214,6 +214,27 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
}
}
[Fact]
public void UnresolvedReferenceCausesBuildToFailAndNotProduceOutput()
{
var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects");
var testInstance = testAssetsManager.CreateTestInstance("TestProjectWithUnresolvedDependency")
.WithLockFiles();
var restoreResult = new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute();
restoreResult.Should().Fail();
new DirectoryInfo(testInstance.TestRoot).Should().HaveFile("project.lock.json");
var buildCmd = new BuildCommand(testInstance.TestRoot);
var buildResult = buildCmd.ExecuteWithCapturedOutput();
buildResult.Should().Fail();
buildResult.StdErr.Should().Contain("The dependency ThisIsNotARealDependencyAndIfSomeoneGoesAndAddsAProjectWithThisNameIWillFindThemAndPunishThem could not be resolved.");
var outputDir = new DirectoryInfo(Path.Combine(testInstance.TestRoot, "bin", "Debug", "netcoreapp1.0"));
outputDir.GetFiles().Length.Should().Be(0);
}
[Fact]
public void PackageReferenceWithResourcesTest()
{