dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.22k stars 1.35k forks source link

No command line parsing errors from 5.0 GA dotnet build #8815

Open danmoseley opened 3 years ago

danmoseley commented 3 years ago

I am not getting command line parsing errors from dotnet build :

C:\git>dotnet build  /p:a.b=c \temp\foo.proj
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

C:\git>

I would expect something like this:

C:\git>dotnet exec "C:\Program Files\dotnet\sdk\5.0.100\msbuild.dll" /p:a.b=c \temp\foo.proj
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

MSBUILD : error MSB4177: Invalid property. The name "a.b" contains an invalid character ".".
C:\git>dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.100
 Commit:    5044b93829

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.100\

Host (useful for support):
  Version: 5.0.0
  Commit:  cf258a14b7

.NET SDKs installed:
  2.1.811 [C:\Program Files\dotnet\sdk]
  3.1.404 [C:\Program Files\dotnet\sdk]
  5.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
rainersigwald commented 3 years ago

This is super weird. It appears to be getting through to MSBuild:

❯ dotnet build /p:a.b=c foo.proj -bl
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

Some command line switches were read from the auto-response file "MSBuild.rsp". To disable this file, use the "-noAutoResponse" switch.
C:\Program Files\dotnet\sdk\5.0.100\MSBuild.dll -bl -consoleloggerparameters:Summary -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\5.0.100\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\5.0.100\dotnet.dll -maxcpucount -restore -verbosity:m /p:a.b=c foo.proj

But then we just exit.

rainersigwald commented 3 years ago

The exception gets thrown

>   Microsoft.Build.dll!Microsoft.Build.Exceptions.InvalidProjectFileException.InvalidProjectFileException(string projectFile, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber, string message, string errorSubcategory, string errorCode, string helpKeyword, System.Exception innerException) Line 187   C#
    Microsoft.Build.dll!Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(string errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, string resourceName, object[] args) Line 412 C#
    Microsoft.Build.dll!Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject<System.__Canon>(Microsoft.Build.Shared.IElementLocation elementLocation, string resourceName, System.__Canon arg0) Line 62 C#
    Microsoft.Build.dll!Microsoft.Build.Evaluation.ProjectCollection.ProjectCollection(System.Collections.Generic.IDictionary<string, string> globalProperties, System.Collections.Generic.IEnumerable<Microsoft.Build.Framework.ILogger> loggers, System.Collections.Generic.IEnumerable<Microsoft.Build.Logging.ForwardingLoggerRecord> remoteLoggers, Microsoft.Build.Evaluation.ToolsetDefinitionLocations toolsetDefinitionLocations, int maxNodeCount, bool onlyLogCriticalEvents, bool loadProjectsReadOnly) Line 343    C#
    MSBuild.dll!Microsoft.Build.CommandLine.MSBuildApp.BuildProject(string projectFile, string[] targets, string toolsVersion, System.Collections.Generic.Dictionary<string, string> globalProperties, System.Collections.Generic.Dictionary<string, string> restoreProperties, Microsoft.Build.Framework.ILogger[] loggers, Microsoft.Build.Framework.LoggerVerbosity verbosity, Microsoft.Build.CommandLine.DistributedLoggerRecord[] distributedLoggerRecords, int cpuCount, bool enableNodeReuse, System.IO.TextWriter preprocessWriter, System.IO.TextWriter targetsWriter, bool detailedSummary, System.Collections.Generic.ISet<string> warningsAsErrors, System.Collections.Generic.ISet<string> warningsAsMessages, bool enableRestore, Microsoft.Build.Logging.ProfilerLogger profilerLogger, bool enableProfiler, bool interactive, bool isolateProjects, bool graphBuild, bool lowPriority, string[] inputResultsCaches, string outputResultsCache) Line 1088   C#
    MSBuild.dll!Microsoft.Build.CommandLine.MSBuildApp.Execute(string[] commandLine) Line 661   C#
    MSBuild.dll!Microsoft.Build.CommandLine.MSBuildApp.Main(string[] args) Line 222 C#
rainersigwald commented 3 years ago

Wait, I actually don't see your expected error ever @danmosemsft:

❯ msbuild /p:a.b=c foo.proj
Microsoft (R) Build Engine version 16.9.0-preview-20553-06+841e09174 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

msbuild on whitespace-fix [$!?] •NET v5.0.100
❯ dotnet exec "C:\Program Files\dotnet\sdk\5.0.100\MSBuild.dll" /p:a.b=c foo.proj
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
danmoseley commented 3 years ago

Not sure why you never see it, but I guess that is still broken. Guess -- is the console not correctly being piped through the dotnet host? Build errors would come via loggers, not the console, so they still show up. Maybe try corerun?

danmoseley commented 3 years ago

Or try dotnet exec on some hello world console app.

marcpopMSFT commented 1 year ago

From old bug triage: we tried this out with msbuild.exe and it seems to repro there as well so transferring over.

Forgind commented 1 year ago

I did a little do diligence on this. We first throw the expected exception here, and it throws an invalid project file exception right below. Then we add the exception to the logging queue as expected.

You might notice that that whole exception processing block is wrapped in a catch (Exception) that shuts down the logging service, then throws. Looking at that, the exception is in the queue and processed, meaning it gets here, which should process the event just before it terminates the queue, but I currently suspect it's cancelling a little too fast or possibly disposing of the logger slightly too fast, and that's why the error never appears.

Forgind commented 1 year ago

An alternative is to just not mark it as fully logged. Then it should be thrown. I'm not sure in what cases that would log it twice, but a little over-logging never hurt anyone 😉