diff --git a/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedDependency/.noautobuild b/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedDependency/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedDependency/Program.cs b/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedDependency/Program.cs new file mode 100644 index 000000000..51233cffa --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedDependency/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedDependency/project.json b/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedDependency/project.json new file mode 100644 index 000000000..1a52c75c9 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/TestProjectWithUnresolvedDependency/project.json @@ -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" + } + } +} diff --git a/TestAssets/TestProjects/TestAppWithBuildDependency/App/Program.cs b/TestAssets/TestProjects/TestAppWithBuildDependency/App/Program.cs new file mode 100644 index 000000000..51233cffa --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithBuildDependency/App/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/TestAssets/TestProjects/TestAppWithBuildDependency/App/project.json b/TestAssets/TestProjects/TestAppWithBuildDependency/App/project.json new file mode 100644 index 000000000..515ad24c6 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithBuildDependency/App/project.json @@ -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" + } + } +} diff --git a/TestAssets/TestProjects/TestAppWithBuildDependency/LibraryWithBuildDependency/Program.cs b/TestAssets/TestProjects/TestAppWithBuildDependency/LibraryWithBuildDependency/Program.cs new file mode 100644 index 000000000..51233cffa --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithBuildDependency/LibraryWithBuildDependency/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/TestAssets/TestProjects/TestAppWithBuildDependency/LibraryWithBuildDependency/project.json b/TestAssets/TestProjects/TestAppWithBuildDependency/LibraryWithBuildDependency/project.json new file mode 100644 index 000000000..7014ce342 --- /dev/null +++ b/TestAssets/TestProjects/TestAppWithBuildDependency/LibraryWithBuildDependency/project.json @@ -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" + } + } +} diff --git a/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestInstance.cs b/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestInstance.cs index 4e479d48a..f9903bdb5 100644 --- a/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestInstance.cs +++ b/src/Microsoft.DotNet.TestFramework/Microsoft.DotNet.TestFramework.TestInstance.cs @@ -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"); diff --git a/src/dotnet/commands/dotnet-build/DotnetProjectBuilder.cs b/src/dotnet/commands/dotnet-build/DotnetProjectBuilder.cs index c56af82f1..7b27d2a92 100644 --- a/src/dotnet/commands/dotnet-build/DotnetProjectBuilder.cs +++ b/src/dotnet/commands/dotnet-build/DotnetProjectBuilder.cs @@ -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); } diff --git a/src/dotnet/commands/dotnet-build/ProjectGraphCollector.cs b/src/dotnet/commands/dotnet-build/ProjectGraphCollector.cs index c0cd7be12..7fe7d88d2 100644 --- a/src/dotnet/commands/dotnet-build/ProjectGraphCollector.cs +++ b/src/dotnet/commands/dotnet-build/ProjectGraphCollector.cs @@ -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)); } diff --git a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs index 5ff5c31a5..332ea231e 100644 --- a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs +++ b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs @@ -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; } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs index da89f3f96..dce3e7e54 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/TestBase.cs @@ -66,12 +66,12 @@ namespace Microsoft.DotNet.Tools.Test.Utilities return s_testsAssetsMgr; } } - + protected static TestAssetsManager GetTestGroupTestAssetsManager(string testGroup) { string assetsRoot = Path.Combine(RepoRoot, "TestAssets", testGroup); var testAssetsMgr = new TestAssetsManager(assetsRoot); - + return testAssetsMgr; } diff --git a/test/dotnet-build.Tests/BuildOutputTests.cs b/test/dotnet-build.Tests/BuildOutputTests.cs index 74b081374..34f83edcb 100644 --- a/test/dotnet-build.Tests/BuildOutputTests.cs +++ b/test/dotnet-build.Tests/BuildOutputTests.cs @@ -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() {