Broslyn 1.2.0
dotnet add package Broslyn --version 1.2.0
NuGet\Install-Package Broslyn -Version 1.2.0
<PackageReference Include="Broslyn" Version="1.2.0" />
paket add Broslyn --version 1.2.0
#r "nuget: Broslyn, 1.2.0"
// Install Broslyn as a Cake Addin #addin nuget:?package=Broslyn&version=1.2.0 // Install Broslyn as a Cake Tool #tool nuget:?package=Broslyn&version=1.2.0
Broslyn
<img align="right" width="160px" height="160px" src="https://raw.githubusercontent.com/xoofx/Broslyn/master/img/logo.png">
A lightweight utility library to create a Roslyn AdhocWorkspace
from an existing solution
/csproj
, by capturing the CSharp compiler emited command while rebuilding the project.
This can be used primarily for syntax tree inspection/code generation.
This library requires a
dotnet
SDK to be installed
Usage
// Rebuild the specified project in Release and capture
var result = CSharpCompilationCapture.Build(@"C:\Path\To\A\Sln\Or\project.csproj", "Release");
var workspace = result.Workspace;
var project = workspace.CurrentSolution.Projects.FirstOrDefault();
var compilation = await project.GetCompilationAsync();
// ...
Why?
If you have been using MSBuildWorkdspace
to get an access to CSharp projects, you will find sometimes that it is actually impossible to work with if you are expecting your Roslyn application to run on a different runtime than the one currently installed through the dotnet
SDK.
This is a known issue Use more permissive load context for MSBuildWorkspace by default and I hope that it will be fix in the future.
To workaround this problem and allow to load a CSharp Project with Roslyn no matter which SDK is installed, Broslyn is working like this:
- It runs a
dotnet msbuild /t:rebuild
on the project or solution passed to it with an output to a binlog file. - By running the re-build, we are able to capture the exact
csc
command issued by the build system and we can extract them with by reading compiler invocations using the fantastic MSBuildStruturedLog library. - We then extract the csc arguments and transform them back to
CSharpCompilationArguments
. - From this we can create for each
csc
invocation and equivalent RoslynProject
that will guarantee the exact same compilation settings.
This was a nice suggestion from Kirill Osenkov (the author of MSBuildStruturedLog) and it turns out that it was very easy to implement.
License
This software is released under the BSD-Clause 2 license.
Related projects
- Buildalizer: A more featured library if you are looking for a better introspection on project references and dependencies
- In Broslyn, a Project will only contain assembly references in order to compile to CSharp but will not provide full introspection on the original project references.
Author
Alexandre Mutel aka xoofx.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.7.0)
- MSBuild.StructuredLogger (>= 2.1.858)
-
net7.0
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.7.0)
- MSBuild.StructuredLogger (>= 2.1.858)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Broslyn:
Repository | Stars |
---|---|
xoofx/kalk
kalk is a powerful command line calculator app for developers.
|