![]() |
VOOZH | about |
dotnet add package MScottFord.Forks.Buildalyzer.Logger --version 9.0.0-alpha
NuGet\Install-Package MScottFord.Forks.Buildalyzer.Logger -Version 9.0.0-alpha
<PackageReference Include="MScottFord.Forks.Buildalyzer.Logger" Version="9.0.0-alpha" />
<PackageVersion Include="MScottFord.Forks.Buildalyzer.Logger" Version="9.0.0-alpha" />Directory.Packages.props
<PackageReference Include="MScottFord.Forks.Buildalyzer.Logger" />Project file
paket add MScottFord.Forks.Buildalyzer.Logger --version 9.0.0-alpha
#r "nuget: MScottFord.Forks.Buildalyzer.Logger, 9.0.0-alpha"
#:package MScottFord.Forks.Buildalyzer.Logger@9.0.0-alpha
#addin nuget:?package=MScottFord.Forks.Buildalyzer.Logger&version=9.0.0-alpha&prereleaseInstall as a Cake Addin
#tool nuget:?package=MScottFord.Forks.Buildalyzer.Logger&version=9.0.0-alpha&prereleaseInstall as a Cake Tool
A utility to perform design-time builds of .NET projects without having to think too hard about it.
NuGet
GitHub
Donations
If you found this library useful, consider sponsoring more of it on GitHub. I promise to use it on something totally frivolous and unrelated.
Sponsors
Amazon Web Services (AWS) generously sponsors this project. Go check out what they have to offer for .NET developers (it's probably more than you think).
Buildalyzer lets you run MSBuild from your own code and returns information about the project. By default, it runs a design-time build which is higher performance than a normal build because it doesn't actually try to compile the project. You can use it to perform analysis of MSBuild projects, get project properties, or create a Roslyn Workspace using Buildalyzer.Workspaces. It runs MSBuild out-of-process and therefore should work anywhere, anytime, and on any platform you can build the project yourself manually on the command line.
AnalyzerManager manager = new AnalyzerManager();
IProjectAnalyzer analyzer = manager.GetProject(@"C:\MyCode\MyProject.csproj");
IAnalyzerResults results = analyzer.Build();
string[] sourceFiles = results.First().SourceFiles;
These blog posts might also help explain the motivation behind the project and how it works:
Buildalyzer is available on NuGet and can be installed via the commands below:
$ Install-Package Buildalyzer
or via the .NET Core CLI:
$ dotnet add package Buildalyzer
Buildalyzer.Workspaces is available on NuGet and can be installed via the commands below:
$ Install-Package Buildalyzer.Workspaces
or via the .NET Core CLI:
$ dotnet add package Buildalyzer.Workspaces
Both packages target .NET Standard 2.0.
There are two main classes in Buildalyzer: AnalyzerManager and ProjectAnalyzer.
The AnalyzerManager class coordinates loading each individual project and consolidates information from a solution file if provided.
The ProjectAnalyzer class figures out how to configure MSBuild and uses it to load and compile the project in design-time mode. Using a design-time build lets us get information about the project such as resolved references and source files without actually having to call the compiler.
To get a ProjectAnalyzer you first create an AnalyzerManager and then call GetProject():
AnalyzerManager manager = new AnalyzerManager();
IProjectAnalyzer analyzer = manager.GetProject(@"C:\MyCode\MyProject.csproj");
You can add all projects in a solution to the AnalyzerManager by passing the solution path as the first argument of the AnalyzerManager constructor. This will parse the solution file and execute GetProject() for each of the projects that it finds.
Calling GetProject() again for the same project path will return the existing ProjectAnalyzer. You can iterate all the existing project analyzers with the IReadOnlyDictionary<string, ProjectAnalyzer> property AnalyzerManager.Projects.
To build the project, which triggers evaluation of the specified MSBuild tasks and targets but stops short of invoking the compiler by default in Buildalyzer, call Build(). This method has a number of overloads that lets you customize the build process by specifying target frameworks, build targets, and more.
Calling ProjectAnalyzer.Build() (or an overload) will return an AnalyzerResults object, which is a collection of AnalyzerResult objects for each of the target frameworks that were built. It will usually only contain a single AnalyzerResult unless the project is multi-targeted.
AnalyzerResult contains several properties and methods with the results from the build:
AnalyzerResult.TargetFramework - The target framework of this particular result (each result consists of data from a particular target framework build).
AnalyzerResult.SourceFiles - The full path of all resolved source files in the project.
AnalyzerResult.References - The full path of all resolved references in the project.
AnalyzerResult.ProjectReferences - The full path of the project file for all resolved project references in the project.
AnalyzerResult.Properties - A IReadOnlyDictionary<string, string> containing all MSBuild properties from the project.
AnalyzerResult.GetProperty(string) - Gets the value of the specified MSBuild property.
AnalyzerResult.Items - A IReadOnlyDictionary<string, ProjectItem[]> containing all MSBuild items from the project (the ProjectItem class contains the item name/specification as ProjectItem.ItemSpec and all it's metadata in a IReadOnlyDictionary<string, string> as ProjectItem.Metadata).
Buildalyzer sets some MSBuild properties to make loading and compilation work the way it needs to (for example, to trigger a design-time build). You can view these properties with the IReadOnlyDictionary<string, string> property ProjectAnalyzer.GlobalProperties.
If you want to change the configured properties before loading or compiling the project, there are two options:
AnalyzerManager.SetGlobalProperty(string key, string value) and AnalyzerManager.RemoveGlobalProperty(string key). This will set the global properties for all projects loaded by this AnalyzerManager.
ProjectAnalyzer.SetGlobalProperty(string key, string value) and ProjectAnalyzer.RemoveGlobalProperty(string key). This will set the global properties for just this project.
Be careful though, you may break the ability to load, compile, or interpret the project if you change the MSBuild properties.
If your application's output is a single file, you will need to provide the path to the following DLLs:
-MsBuildPipeLogger.Logger.dll -Buildalyzer.logger.dll
Variable name: LoggerPathDll
See related issue 224 msbuild needs the physical address of the logger, for this reason it is not possible to use single file publish without informing this route.
Remembering that if the files are in the root where the project is running, it is not necessary to inform the path.
Buildalyzer can also read MSBuild binary log files:
AnalyzerManager manager = new AnalyzerManager();
IAnalyzerResults results = manager.Analyze(@"C:\MyCode\MyProject.binlog");
string[] sourceFiles = results.First().SourceFiles;
This is useful if you already have a binary log file and want to analyze it with Buildalyzer the same way you would build results.
Buildalyzer uses the Microsoft.Extensions.Logging framework for logging MSBuild output. When you create an AnayzerManager you can specify an ILoggerFactory that Buildalyzer should use to create loggers. By default, the ProjectAnalyzer will log MSBuild output to the provided logger.
You can also log to a StringWriter using AnalyzerManagerOptions:
StringWriter log = new StringWriter();
AnalyzerManagerOptions options = new AnalyzerManagerOptions
{
LogWriter = log
};
AnalyzerManager manager = new AnalyzerManager(path, options);
// ...
// check log.ToString() after build for any error messages
The extension library Buildalyzer.Workspaces adds extension methods to the Buildalyzer ProjectAnalyzer that make it easier to take Buildalyzer output and create a Roslyn AdhocWorkspace from it:
using Buildalyzer.Workspaces;
using Microsoft.CodeAnalysis;
// ...
AnalyzerManager manager = new AnalyzerManager();
IProjectAnalyzer analyzer = manager.GetProject(@"C:\MyCode\MyProject.csproj");
AdhocWorkspace workspace = analyzer.GetWorkspace();
You can also create your own workspace and add Buildalyzer projects to it:
using Buildalyzer.Workspaces;
using Microsoft.CodeAnalysis;
// ...
AnalyzerManager manager = new AnalyzerManager();
IProjectAnalyzer analyzer = manager.GetProject(@"C:\MyCode\MyProject.csproj");
AdhocWorkspace workspace = new AdhocWorkspace();
Project roslynProject = analyzer.AddToWorkspace(workspace);
In both cases, Buildalyzer will attempt to resolve project references within the Roslyn workspace so the Roslyn projects will correctly reference each other.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 1 NuGet packages that depend on MScottFord.Forks.Buildalyzer.Logger:
| Package | Downloads |
|---|---|
|
MScottFord.Forks.Buildalyzer
A little utility to perform design-time builds of .NET projects without having to think too hard about it. Should work with any project type on any .NET runtime. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 9.0.0-alpha | 101 | 4/17/2026 |
ToBeReleased
- Publish SBOM.