-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: MSBuild target with multiple projects, Console.Out suppressed from second project #10756
Comments
You should 100% be using ILogger - I think what you're seeing is the fact that MSBuild is a multi-process architecture, and only one build process actually has a StdOut that can be written to (without doing gymnastics). The purpose of the ILogger mechanism is to provide a safe way for nodes without a StdOut to communicate with the node that does (in addition to all output that goes over the ILogger interface being included in diagnostic tooling like binlogs, etc). This is not a bug, and is the intended design of MSBuild - it would even be the case if MSBuild was a single-process, multi-threaded process. |
Ok, thanks - that makes sense. Crazy that this was working for so long. Not sure what broke it, but clear I was depending on something I should not. Separately, there is basically no bridge to Microsoft DI, which makes writing MSBuild tasks that reference transitive projects difficult - so it's hard to modularize MSBuild. It turns out Coverlet uses Serilog MSBuildSink, but nothing exists for Microsoft.Extensions.Logging. I wrote a dumb one here : https://github.com/fluentmigrator/fluentmigrator/blob/main/src/FluentMigrator.MSBuild/MicrosoftBuildLogger.cs |
We have one in the SDK as well. I agree that this is a thing that would be useful to ship, at some point - @rainersigwald do you think a contribution to MSBuild Utils would be appropriate, or would we need a new package to not drag in the Microsoft.Extensions.Logging.Abstractions dependency? |
@jzabroski there's also a longer-term discussion here because the MEL logging might lack some of the abilities of the MSBuild logging (specifically knowledge of MSBuild Codes (which are used to toggle warning levels, etc) and knowledge of file/line/range markers) - we haven't spec'd out what those interactions should be so we haven't codified them in an MSBuild-shipped MEL.ILogger. |
Issue Description
This is something I noticed at least six months ago, but it's not bad enough to report a bug typically. It's also very possible the way we are doing this is simpler incorrect, and instead of relying on Console.Out, we should be using the ILogger in the MSBuild framework - which I have started prototyping.
This problem happens on both net48 MSBuild (Visual Studio latest) and dotnet.exe (net8.0 latest sdk), but has been happening for awhile, so something likely changed over the last 1-2 years to break this.
Steps to Reproduce
I have a target in a custom .targets file like this:
I then have Directory.Package.props like this:
and then a build.targets like this:
Expected Behavior
Output per project
Actual Behavior
Output for the first project, but not the second project
Analysis
No clue. It is possible it is a bug in my custom task, but I am not sure how to figure that out. Are custom tasks thread safe / isolated in the context of MSBuild task?
Versions & Configurations
msbuild -version
MSBuild version 17.11.9+a69bbaaf5 for .NET Framework
17.11.9.46202
dotnet.exe --list-sdks
6.0.321 [C:\Program Files\dotnet\sdk]
8.0.400 [C:\Program Files\dotnet\sdk]
dotnet.exe --version
8.0.400
dotnet.exe --list-runtimes
Microsoft.AspNetCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.33 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
The text was updated successfully, but these errors were encountered: