KirillOsenkov / MSBuildStructuredLog

A logger for MSBuild that records a structured representation of executed targets, tasks, property and item values.
MIT License
1.41k stars 188 forks source link

Consider removing the `Microsoft.Build` package dependency, and the `TargetGraph` class. #649

Closed teo-tsirpanis closed 1 year ago

teo-tsirpanis commented 1 year ago

The StructuredLogger.MSBuild package depends on Microsoft.Build which is incompatible with .NET Standard 2.0 ("works" via the compatibility shim), weighs almost 4MB and brings quite many dependencies. It would be nice if we stopped depending on it.

Fortunately the only place where it is used is in TargetGraph, a class with relatively simple logic that is nowhere else used in this repro. Depending on your assessment of its importance and your appetite for breaking changes, we can:

(and thank you very much for this project, it has allowed me to pierce inside dotnet build's inner workings and helped me do lots of stuff with MSBuild!)

KirillOsenkov commented 1 year ago

Unfortunately we have more real dependencies on Microsoft.Build:

C:\MSBuildStructuredLog>refdump C:\MSBuildStructuredLog\bin\StructuredLogger\Debug\netstandard2.0\StructuredLogger.dll -a:Microsoft -t
References containing "Microsoft":
StructuredLogger, Version=2.1.0.0, Culture=neutral, PublicKeyToken=d4c7181801cb6448
Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a:
    Microsoft.Build.Execution.ProjectInstance
    Microsoft.Build.Execution.ProjectTargetInstance

Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a:
    Microsoft.Build.Framework.AnyEventHandler
    Microsoft.Build.Framework.BuildErrorEventArgs
    Microsoft.Build.Framework.BuildErrorEventHandler
    Microsoft.Build.Framework.BuildEventArgs
    Microsoft.Build.Framework.BuildEventContext
    Microsoft.Build.Framework.BuildFinishedEventArgs
    Microsoft.Build.Framework.BuildFinishedEventHandler
    Microsoft.Build.Framework.BuildMessageEventArgs
    Microsoft.Build.Framework.BuildMessageEventHandler
    Microsoft.Build.Framework.BuildStartedEventArgs
    Microsoft.Build.Framework.BuildStartedEventHandler
    Microsoft.Build.Framework.BuildStatusEventArgs
    Microsoft.Build.Framework.BuildStatusEventHandler
    Microsoft.Build.Framework.BuildWarningEventArgs
    Microsoft.Build.Framework.BuildWarningEventHandler
    Microsoft.Build.Framework.CriticalBuildMessageEventArgs
    Microsoft.Build.Framework.CustomBuildEventArgs
    Microsoft.Build.Framework.CustomBuildEventHandler
    Microsoft.Build.Framework.EnvironmentVariableReadEventArgs
    Microsoft.Build.Framework.IEventSource
    Microsoft.Build.Framework.IEventSource3
    Microsoft.Build.Framework.IEventSource4
    Microsoft.Build.Framework.ILogger
    Microsoft.Build.Framework.ITaskItem
    Microsoft.Build.Framework.ITaskItem2
    Microsoft.Build.Framework.LazyFormattedBuildEventArgs
    Microsoft.Build.Framework.LoggerException
    Microsoft.Build.Framework.LoggerVerbosity
    Microsoft.Build.Framework.MessageImportance
    Microsoft.Build.Framework.MetaprojectGeneratedEventArgs
    Microsoft.Build.Framework.Profiler.EvaluationLocation
    Microsoft.Build.Framework.Profiler.EvaluationLocationKind
    Microsoft.Build.Framework.Profiler.EvaluationPass
    Microsoft.Build.Framework.Profiler.ProfiledLocation
    Microsoft.Build.Framework.Profiler.ProfilerResult
    Microsoft.Build.Framework.ProjectEvaluationFinishedEventArgs
    Microsoft.Build.Framework.ProjectEvaluationStartedEventArgs
    Microsoft.Build.Framework.ProjectFinishedEventArgs
    Microsoft.Build.Framework.ProjectFinishedEventHandler
    Microsoft.Build.Framework.ProjectImportedEventArgs
    Microsoft.Build.Framework.ProjectStartedEventArgs
    Microsoft.Build.Framework.ProjectStartedEventHandler
    Microsoft.Build.Framework.PropertyInitialValueSetEventArgs
    Microsoft.Build.Framework.PropertyReassignmentEventArgs
    Microsoft.Build.Framework.TargetBuiltReason
    Microsoft.Build.Framework.TargetFinishedEventArgs
    Microsoft.Build.Framework.TargetFinishedEventHandler
    Microsoft.Build.Framework.TargetSkippedEventArgs
    Microsoft.Build.Framework.TargetStartedEventArgs
    Microsoft.Build.Framework.TargetStartedEventHandler
    Microsoft.Build.Framework.TaskCommandLineEventArgs
    Microsoft.Build.Framework.TaskFinishedEventArgs
    Microsoft.Build.Framework.TaskFinishedEventHandler
    Microsoft.Build.Framework.TaskParameterEventArgs
    Microsoft.Build.Framework.TaskParameterMessageKind
    Microsoft.Build.Framework.TaskStartedEventArgs
    Microsoft.Build.Framework.TaskStartedEventHandler
    Microsoft.Build.Framework.UninitializedPropertyReadEventArgs

Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a:
    Microsoft.Build.Utilities.Logger
teo-tsirpanis commented 1 year ago

That's a nice tool, didn't know about it, thanks.

Only Microsoft.Build poses the problem; Microsoft.Build.Framework and Micrsofot.Build.Utilities.Core are fine.

And I noticed that Microsoft.Build.Tasks.Core is entirely unused; opened #650 to remove it.

KirillOsenkov commented 1 year ago

Cool, I have disabled TargetGraph.cs in this commit: https://github.com/KirillOsenkov/MSBuildStructuredLog/commit/f1a8e8b5fdaa8170a8818e47984ca01e2f06401a

Now you can remove Microsoft.Build too: image

teo-tsirpanis commented 1 year ago

OK, I will continue on #650.

KirillOsenkov commented 1 year ago

@teo-tsirpanis thanks!

Published https://www.nuget.org/packages/MSBuild.StructuredLogger/2.1.768