From ecdb10591c40cfcd404c523971cd7f8c3da81b8b Mon Sep 17 00:00:00 2001 From: Eric Erhardt Date: Fri, 13 May 2016 13:10:39 -0500 Subject: [PATCH] Project.json schema warnings don't get displayed When building a project.json that has schema warnings (and other warnings), we are not writing the warnings to the console. This is a regression. The fix is to add all diagnostic messages to the LibraryManager, which is responsible to hold all the diagnostic messages. Fix 3021 --- .../.noautobuild | 0 .../Helper.cs | 15 +++++++++++ .../project.json | 13 +++++++++ .../ProjectContextBuilder.cs | 10 +++++-- test/dotnet-build.Tests/BuildWarningsTests.cs | 27 +++++++++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/.noautobuild create mode 100644 TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/Helper.cs create mode 100644 TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/project.json create mode 100644 test/dotnet-build.Tests/BuildWarningsTests.cs diff --git a/TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/.noautobuild b/TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/Helper.cs b/TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/Helper.cs new file mode 100644 index 000000000..bd9a33ffe --- /dev/null +++ b/TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/Helper.cs @@ -0,0 +1,15 @@ +// 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; + +namespace TestLibrary +{ + public static class Helper + { + public static void SayHi() + { + Console.WriteLine("Hello there!"); + } + } +} diff --git a/TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/project.json b/TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/project.json new file mode 100644 index 000000000..47c6ffafa --- /dev/null +++ b/TestAssets/TestProjects/TestLibraryWithDeprecatedProjectFile/project.json @@ -0,0 +1,13 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "xmlDoc": true + }, + "packInclude": {}, + "dependencies": { + "NETStandard.Library": "1.5.0-rc2-24027" + }, + "frameworks": { + "netstandard1.5": {} + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs index 581bf0825..3a182eb03 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs @@ -355,8 +355,14 @@ namespace Microsoft.DotNet.ProjectModel } } + List allDiagnostics = new List(diagnostics); + if (Project != null) + { + allDiagnostics.AddRange(Project.Diagnostics); + } + // Create a library manager - var libraryManager = new LibraryManager(libraries.Values.ToList(), diagnostics, Project?.ProjectFilePath); + var libraryManager = new LibraryManager(libraries.Values.ToList(), allDiagnostics, Project?.ProjectFilePath); return new ProjectContext( globalSettings, @@ -445,7 +451,7 @@ namespace Microsoft.DotNet.ProjectModel var dependency = new LibraryRange(library.Identity.Name, LibraryType.ReferenceAssembly); var replacement = referenceAssemblyDependencyResolver.GetDescription(dependency, TargetFramework); - + // If the reference is unresolved, just skip it. Don't replace the package dependency if (replacement == null) { diff --git a/test/dotnet-build.Tests/BuildWarningsTests.cs b/test/dotnet-build.Tests/BuildWarningsTests.cs new file mode 100644 index 000000000..e4f50f10e --- /dev/null +++ b/test/dotnet-build.Tests/BuildWarningsTests.cs @@ -0,0 +1,27 @@ +// 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 FluentAssertions; +using Microsoft.DotNet.Tools.Test.Utilities; +using Xunit; + +namespace Microsoft.DotNet.Tools.Builder.Tests +{ + public class BuildWarningsTests : TestBase + { + [Fact] + public void HavingDeprecatedProjectFileProducesWarning() + { + var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithDeprecatedProjectFile").WithLockFiles(); + + new BuildCommand(testInstance.TestRoot) + .ExecuteWithCapturedOutput() + .Should() + .Pass() + .And + .HaveStdErrContaining("DOTNET1015: The 'compilationOptions' option is deprecated. Use 'buildOptions' instead.") + .And + .HaveStdErrContaining("DOTNET1015: The 'packInclude' option is deprecated. Use 'files' in 'packOptions' instead."); + } + } +}