{"id":13594860,"url":"https://github.com/phmonte/Buildalyzer","last_synced_at":"2025-04-09T10:32:12.603Z","repository":{"id":37444687,"uuid":"104515013","full_name":"phmonte/Buildalyzer","owner":"phmonte","description":"A utility to perform design-time builds of .NET projects without having to think too hard about it.","archived":false,"fork":false,"pushed_at":"2024-04-30T13:15:18.000Z","size":1992,"stargazers_count":585,"open_issues_count":26,"forks_count":92,"subscribers_count":23,"default_branch":"main","last_synced_at":"2024-05-01T13:35:46.300Z","etag":null,"topics":["hacktoberfest","msbuild","msbuild-properties","roslyn","roslyn-workspace"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phmonte.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"phmonte"}},"created_at":"2017-09-22T20:15:20.000Z","updated_at":"2024-05-07T15:37:12.305Z","dependencies_parsed_at":"2024-01-13T16:25:43.900Z","dependency_job_id":"a53e17b5-c3ed-4c0f-a9bb-d2fa1b18057c","html_url":"https://github.com/phmonte/Buildalyzer","commit_stats":{"total_commits":469,"total_committers":47,"mean_commits":9.97872340425532,"dds":0.2515991471215352,"last_synced_commit":"3f1f7f2e30b8f1767563c70f9cabac8faf5b3e4c"},"previous_names":["daveaglick/buildalyzer"],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phmonte%2FBuildalyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phmonte%2FBuildalyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phmonte%2FBuildalyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phmonte%2FBuildalyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phmonte","download_url":"https://codeload.github.com/phmonte/Buildalyzer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248020592,"owners_count":21034459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","msbuild","msbuild-properties","roslyn","roslyn-workspace"],"created_at":"2024-08-01T16:01:40.114Z","updated_at":"2025-04-09T10:32:07.559Z","avatar_url":"https://github.com/phmonte.png","language":"C#","funding_links":["https://github.com/sponsors/phmonte"],"categories":["hacktoberfest","C#","C\\#"],"sub_categories":[],"readme":"A utility to perform design-time builds of .NET projects without having to think too hard about it.\n\n![Buildalyzer Logo](https://raw.githubusercontent.com/phmonte/Buildalyzer/main/buildalyzer.png)\n\n**NuGet**\n* [Buildalyzer](https://www.nuget.org/packages/Buildalyzer/)\n* [Buildalyzer.Workspaces](https://www.nuget.org/packages/Buildalyzer.Workspaces/)\n\n**GitHub**\n* [Buildalyzer](https://github.com/phmonte/Buildalyzer)\n\n**Donations**\n\nIf you found this library useful, consider [sponsoring more of it on GitHub](https://github.com/sponsors/phmonte). I promise to use it on something totally frivolous and unrelated.\n\n[![Sponsor](https://img.shields.io/github/sponsors/phmonte?style=social\u0026logo=github-sponsors)](https://github.com/sponsors/phmonte)\n\n**Sponsors**\n\n![AWS Logo](https://raw.githubusercontent.com/phmonte/Buildalyzer/main/aws.png)\n\n[Amazon Web Services (AWS)](https://aws.amazon.com/) generously sponsors this project. [Go check out](https://aws.amazon.com/developer/language/net) what they have to offer for .NET developers (it's probably more than you think).\n\n---\n\n## What Is It?\n\nBuildalyzer lets you run MSBuild from your own code and returns information about the project. By default, it runs a [design-time build](https://daveaglick.com/posts/running-a-design-time-build-with-msbuild-apis) 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](https://www.nuget.org/packages/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.\n\n\n```csharp\nAnalyzerManager manager = new AnalyzerManager();\nIProjectAnalyzer analyzer = manager.GetProject(@\"C:\\MyCode\\MyProject.csproj\");\nIAnalyzerResults results = analyzer.Build();\nstring[] sourceFiles = results.First().SourceFiles;\n```\n\nThese blog posts might also help explain the motivation behind the project and how it works:\n* [Running A Design-Time Build With MSBuild APIs](https://daveaglick.com/posts/running-a-design-time-build-with-msbuild-apis)\n* [MSBuild Loggers And Logging Events](https://daveaglick.com/posts/msbuild-loggers-and-logging-events)\n\n\n## Installation\n\nBuildalyzer is [available on NuGet](https://www.nuget.org/packages/Buildalyzer/) and can be installed via the commands below:\n\n```\n$ Install-Package Buildalyzer\n```\nor via the .NET Core CLI:\n\n```\n$ dotnet add package Buildalyzer\n```\n\nBuildalyzer.Workspaces is [available on NuGet](https://www.nuget.org/packages/Buildalyzer.Workspaces/) and can be installed via the commands below:\n\n```\n$ Install-Package Buildalyzer.Workspaces\n```\nor via the .NET Core CLI:\n\n```\n$ dotnet add package Buildalyzer.Workspaces\n```\n\nBoth packages target .NET Standard 2.0.\n\n## Usage\n\nThere are two main classes in Buildalyzer: `AnalyzerManager` and `ProjectAnalyzer`.\n\nThe `AnalyzerManager` class coordinates loading each individual project and consolidates information from a solution file if provided.\n\nThe `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.\n\nTo get a `ProjectAnalyzer` you first create an `AnalyzerManager` and then call `GetProject()`:\n\n```csharp\nAnalyzerManager manager = new AnalyzerManager();\nIProjectAnalyzer analyzer = manager.GetProject(@\"C:\\MyCode\\MyProject.csproj\");\n```\n\nYou 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.\n\nCalling `GetProject()` again for the same project path will return the existing `ProjectAnalyzer`. You can iterate all the existing project analyzers with the `IReadOnlyDictionary\u003cstring, ProjectAnalyzer\u003e` property `AnalyzerManager.Projects`.\n\nTo 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.\n\n## Results\n\nCalling `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.\n\n`AnalyzerResult` contains several properties and methods with the results from the build:\n\n**`AnalyzerResult.TargetFramework`** - The target framework of this particular result (each result consists of data from a particular target framework build).\n\n**`AnalyzerResult.SourceFiles`** - The full path of all resolved source files in the project.\n\n**`AnalyzerResult.References`** - The full path of all resolved references in the project.\n\n**`AnalyzerResult.ProjectReferences`** - The full path of the project file for all resolved project references in the project.\n\n**`AnalyzerResult.Properties`** - A `IReadOnlyDictionary\u003cstring, string\u003e` containing all MSBuild properties from the project.\n\n**`AnalyzerResult.GetProperty(string)`** - Gets the value of the specified MSBuild property.\n\n**`AnalyzerResult.Items`** - A `IReadOnlyDictionary\u003cstring, ProjectItem[]\u003e` 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\u003cstring, string\u003e` as `ProjectItem.Metadata`).\n\n## Adjusting MSBuild Properties\n\nBuildalyzer 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\u003cstring, string\u003e` property `ProjectAnalyzer.GlobalProperties`.\n\nIf you want to change the configured properties before loading or compiling the project, there are two options:\n\n* `AnalyzerManager.SetGlobalProperty(string key, string value)` and `AnalyzerManager.RemoveGlobalProperty(string key)`. This will set the global properties for all projects loaded by this `AnalyzerManager`.\n\n* `ProjectAnalyzer.SetGlobalProperty(string key, string value)` and `ProjectAnalyzer.RemoveGlobalProperty(string key)`. This will set the global properties for just this project.\n\nBe careful though, you may break the ability to load, compile, or interpret the project if you change the MSBuild properties.\n\n\n## Publish SingleFile\nIf your application's output is a single file, you will need to provide the path to the following DLLs:\n\n-MsBuildPipeLogger.Logger.dll\n-Buildalyzer.logger.dll\n\nVariable name: LoggerPathDll\n\nSee related issue [224](https://github.com/phmonte/Buildalyzer/issues/224)\nmsbuild needs the physical address of the logger, for this reason it is not possible to use single file publish without informing this route.\n\nRemembering that if the files are in the root where the project is running, it is not necessary to inform the path.\n## Binary Log Files\n\nBuildalyzer can also read [MSBuild binary log files](http://msbuildlog.com/):\n\n```csharp\nAnalyzerManager manager = new AnalyzerManager();\nIAnalyzerResults results = manager.Analyze(@\"C:\\MyCode\\MyProject.binlog\");\nstring[] sourceFiles = results.First().SourceFiles;\n```\n\nThis is useful if you already have a binary log file and want to analyze it with Buildalyzer the same way you would build results.\n\n## Logging\n\nBuildalyzer 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.\n\nYou can also log to a `StringWriter` using `AnalyzerManagerOptions`:\n\n```csharp\nStringWriter log = new StringWriter();\nAnalyzerManagerOptions options = new AnalyzerManagerOptions\n{\n    LogWriter = log\n};\nAnalyzerManager manager = new AnalyzerManager(path, options);\n// ...\n// check log.ToString() after build for any error messages\n```\n\n## Roslyn Workspaces\n\nThe 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:\n\n```csharp\nusing Buildalyzer.Workspaces;\nusing Microsoft.CodeAnalysis;\n// ...\n\nAnalyzerManager manager = new AnalyzerManager();\nIProjectAnalyzer analyzer = manager.GetProject(@\"C:\\MyCode\\MyProject.csproj\");\nAdhocWorkspace workspace = analyzer.GetWorkspace();\n```\n\nYou can also create your own workspace and add Buildalyzer projects to it:\n\n```csharp\nusing Buildalyzer.Workspaces;\nusing Microsoft.CodeAnalysis;\n// ...\n\nAnalyzerManager manager = new AnalyzerManager();\nIProjectAnalyzer analyzer = manager.GetProject(@\"C:\\MyCode\\MyProject.csproj\");\nAdhocWorkspace workspace = new AdhocWorkspace();\nProject roslynProject = analyzer.AddToWorkspace(workspace);\n```\n\nIn both cases, Buildalyzer will attempt to resolve project references within the Roslyn workspace so the Roslyn projects will correctly reference each other.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphmonte%2FBuildalyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphmonte%2FBuildalyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphmonte%2FBuildalyzer/lists"}