Basic.Reference.Assemblies
1.7.5
Prefix Reserved
See the version list below for details.
dotnet add package Basic.Reference.Assemblies --version 1.7.5
NuGet\Install-Package Basic.Reference.Assemblies -Version 1.7.5
<PackageReference Include="Basic.Reference.Assemblies" Version="1.7.5" />
paket add Basic.Reference.Assemblies --version 1.7.5
#r "nuget: Basic.Reference.Assemblies, 1.7.5"
// Install Basic.Reference.Assemblies as a Cake Addin #addin nuget:?package=Basic.Reference.Assemblies&version=1.7.5 // Install Basic.Reference.Assemblies as a Cake Tool #tool nuget:?package=Basic.Reference.Assemblies&version=1.7.5
Easy in-memory compilations for Roslyn
Roslyn is a powerful API for C# and Visual Basic compilations. Provide it code, a few options, and a set of references and it will provide an API to inspect the syntax, semantic model, diagnostics and even generate DLLs / EXEs.
Getting reference assemblies to use with a Compilation
is challenging because they are only shipped with development tools. In order to use them in a library, the developer must do the heavy lifting of packaging them up as resources in their library and unpacking them at runtime.
The Basic.Reference.Assemblies library takes care of this heavy lifting and provides reference assemblies for net8.0
, netstandard2.0
and net472
target frameworks. These can be easily integrated into the existing Roslyn APIs.
Usage Examples
using Microsoft.CodeAnalysis.CSharp;
using Basic.Reference.Assemblies;
using System.IO;
using System.Reflection;
var code = @"
using System;
public static class Example
{
public static void Main()
{
var tuple = (Part1: ""hello"", Part2: ""world"");
Console.WriteLine($""{tuple.Part1} {tuple.Part2}"");
}
}
";
var compilation = CSharpCompilation
.Create(
"HelloWorld.dll",
new[] { CSharpSyntaxTree.ParseText(code) },
references: ReferenceAssemblies.Net80);
using var stream = new MemoryStream();
var emitResults = compilation.Emit(stream);
stream.Position = 0;
var assembly = Assembly.Load(stream.ToArray());
var method = assembly.GetType("Example").GetMethod("Main");
method.Invoke(null, null); // Prints "Hello World"
This package also adds extensions methods for easily retargeting Compilation
instances to different target frameworks.
CSharpCompilation compilation = ...;
compilation = compilation.WithReferenceAssemblies(ReferenceAssemblyKind.Net80);
The expectation is that most developers will use Basic.Reference.Assemblies. This package has reference assemblies for the latest supported target frameworks and provides APIs to easily switch between them in Compilation
instances.
FAQ
What if I only need a single target framework?
Developers who only need a single target framework and are extremely size conscious can grab the target framework specific package:
- Basic.Reference.Assemblies.Net80
- Basic.Reference.Assemblies.NetStandard20
- Basic.Reference.Assemblies.Net472
Packages for older target frameworks are also available:
- Basic.Reference.Assemblies.Net70
- Basic.Reference.Assemblies.Net60
- Basic.Reference.Assemblies.Net60Windows
- Basic.Reference.Assemblies.Net50
- Basic.Reference.Assemblies.NetCoreApp31
- Basic.Reference.Assemblies.NetStandard13
- Basic.Reference.Assemblies.Net461
What is wrong with using typeof(Enumerable).Assembly
?
Developers working on .NET Framework will often end up with the following pattern for creating Compilation
instances:
Assembly systemCoreAssembly = typeof(System.Linq.Enumerable).Assembly;
string systemCorePath = systemCoreAssembly.Location;
MetadataReference systemCoreRef = AssemblyMetadata.CreateFromFile(path).GetReference();
This pattern will often work on .NET Framework but will fail when running on .NET Core. The reason for this is due to the differences in reference and implementation assemblies. Reference assemblies are designed for use at build time, while implementation assemblies are used at runtime. A particular type for a given target framework doesn't necessarily live in the same reference and implementation assembly. Also, the set of implementation assemblies can be larger than the reference assemblies for the same target framework.
The reason the above tends to work on .NET Framework is that the split between reference and implementation assemblies is not as pronounced. In most cases, there is a 1:1 relationship. On .NET Core, the split is much more pronounced, and it often requires probing for implementation assemblies to get a set which will work for building. This is a fragile process, though, and developers are much better off using the reference assemblies as intended by the .NET team.
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 was computed. 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.Common (>= 4.9.2)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on Basic.Reference.Assemblies:
Package | Downloads |
---|---|
Microsoft.ProgramSynthesis.Compiler
Library for generating code for a DSL from its grammar. Part of the Microsoft PROgram Synthesis using Examples SDK (PROSE). |
|
Neon.CSharp
C# dynamic compilation support utilities. |
|
LR.RuntimeProxies
Package Description |
|
Nowy.RuntimeProxies
Package Description |
|
Passingwind.Abp.ElsaModule.ElsaExtensions
Package Description |
GitHub repositories (11)
Showing the top 5 popular GitHub repositories that depend on Basic.Reference.Assemblies:
Repository | Stars |
---|---|
ChilliCream/graphql-platform
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
|
|
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
|
|
Fydar/RPGCore
RPGCore is a toolkit for producing games and mechanics in C#.
|
|
StateSmith/StateSmith
A state machine code generation tool suitable for bare metal, embedded and more.
|
|
docopt/docopt.net
Port of docopt to .net
|
Version | Downloads | Last updated |
---|---|---|
1.7.9 | 4,518 | 9/19/2024 |
1.7.8 | 9,300 | 8/28/2024 |
1.7.7 | 471 | 8/23/2024 |
1.7.6 | 161 | 8/23/2024 |
1.7.5 | 224 | 8/21/2024 |
1.7.4 | 619 | 8/16/2024 |
1.7.3 | 3,627 | 8/15/2024 |
1.7.2 | 16,525 | 5/7/2024 |
1.7.1 | 1,184 | 5/1/2024 |
1.6.0 | 7,732 | 4/12/2024 |
1.5.0 | 9,559 | 3/1/2024 |
1.4.5 | 33,631 | 8/22/2023 |
1.4.4 | 447 | 8/18/2023 |
1.4.2 | 17,950 | 5/12/2023 |
1.4.1 | 51,859 | 11/3/2022 |
1.4.0 | 1,059 | 10/23/2022 |
1.3.0 | 1,143 | 10/3/2022 |
1.2.4 | 115,051 | 9/7/2021 |
1.2.3 | 514 | 9/2/2021 |
1.2.2 | 525 | 8/30/2021 |
1.2.1 | 449 | 8/26/2021 |
1.2.0 | 505 | 8/25/2021 |
1.1.2 | 23,351 | 4/8/2021 |
1.1.1 | 669 | 2/23/2021 |
1.1.0 | 440 | 2/23/2021 |
1.0.0 | 100,100 | 1/31/2021 |
0.1.9 | 460 | 1/31/2021 |
0.1.8 | 389 | 1/30/2021 |
0.1.7 | 357 | 1/30/2021 |
0.1.6 | 575 | 1/30/2021 |