Creating a C# Project for Extensions
This article explains how to create an empty C# project for Beutl extensions.
This guide introduces the methods using Visual Studio Code or Visual Studio.
Beutl 2.0 ships an MSBuild SDK called Beutl.Extensibility.Sdk that wires up the target framework, language defaults, the standard package references (Beutl.Api, Beutl.Extensibility, Beutl.ProjectSystem, Beutl.NodeGraph, Beutl.Editor, Beutl.Controls, Beutl.Engine.SourceGenerators), and the sideload output path. Using it keeps the csproj small.
Pick the SDK version that matches the Beutl release you target. The SDK and the Beutl runtime packages are versioned together (for example, 2.0.0-preview.14). You can override the resolved package versions with the BeutlPackagesVersion property if you need a different combination.
Visual Studio Code
- Use the terminal to create a class library.
dotnet new classlib -o MyBeutlExtension
Ensure the directory structure is as follows:
MyBeutlExtension
┣━ obj
┃ ┗━ (...)
┣━ Class1.cs
┗━ MyBeutlExtension.csproj
- Run the following commands to generate
nuget.configand add the package source. The Beutl SDK and runtime packages are distributed via thenuget.beditor.netfeed.
dotnet new nugetconfig
dotnet nuget add source "https://nuget.beditor.net/v3/index.json" --name nuget.beditor.net
- Edit the generated
MyBeutlExtension.csprojas follows:
<Project Sdk="Beutl.Extensibility.Sdk/2.0.0-preview.14">
<PropertyGroup>
<PackageId>MyBeutlExtension</PackageId>
<Title>Sample Extension</Title>
<Description>Sample</Description>
<PackageTags>sample</PackageTags>
<Version>1.0.0</Version>
<Authors>Author Name</Authors>
<RepositoryUrl>url/to/repository</RepositoryUrl>
<!-- Copy Debug builds to the sideload directory. -->
<DebugApplication Condition="'$(Configuration)'=='Debug'">true</DebugApplication>
</PropertyGroup>
</Project>
The SDK takes care of:
- Setting
TargetFrameworktonet11.0(net10.0up to preview.11), plusImplicitUsingsandNullabletoenable. - Adding
PackageReferences toBeutl.Api,Beutl.Extensibility,Beutl.ProjectSystem,Beutl.NodeGraph,Beutl.Editor,Beutl.Controls, and theBeutl.Engine.SourceGeneratorsanalyzer. - Redirecting the output path to
~/.beutl/sideloads/<AssemblyName>whenDebugApplicationistrue. - Turning each
BeutlHostPackageReferenceinto a compile-only reference at the version Beutl ships (since preview.11). - Compiling
asyncmethods with .NET 11 runtime async, as Beutl does (since preview.14).
Since preview.9, the SDK references Beutl.Engine.SourceGenerators as a build-only analyzer with PrivateAssets="all". The manual workaround needed by preview.8 and earlier to keep the generator out of package dependencies is no longer necessary.
This completes the creation of an empty C# project for extensions.
Customizing references
Set any of these properties to false if you want to opt out of a specific auto-reference:
BeutlAutoReferenceAllBeutlAutoReferenceApiBeutlAutoReferenceExtensibilityBeutlAutoReferenceProjectSystemBeutlAutoReferenceNodeGraphBeutlAutoReferenceEditorBeutlAutoReferenceControlsBeutlAutoReferenceSourceGenerators
Override BeutlSideloadPath to choose the sideload directory. Otherwise, the SDK uses sideloads/<AssemblyName> under BEUTL_HOME, or under ~/.beutl when that environment variable is unset.
Libraries Beutl ships
To use a library that Beutl also ships, such as FluentIcons, add a BeutlHostPackageReference with its package ID and no version. The SDK references it at the version Beutl ships and keeps it out of your output and package. A name Beutl does not ship stops the restore; see libraries that Beutl already ships.
<ItemGroup>
<BeutlHostPackageReference Include="FluentIcons.Avalonia.Fluent" />
</ItemGroup>
Runtime async
Since preview.14, the SDK adds runtime-async=on to Features. An async method that returns Task or ValueTask then has no compiler-generated state machine: the .NET 11 runtime suspends and resumes it, and stack traces show the method itself instead of MoveNext. async void methods and async iterators keep their state machines. To keep them for every method, append runtime-async=off, since the last value wins:
<PropertyGroup>
<Features>$(Features);runtime-async=off</Features>
</PropertyGroup>
Visual Studio
-
Open Visual Studio and click File > New > Project.

-
Select Class Library and click Next.

-
Enter the project name and location, then click Next.

-
Select
.NET 11.0as the framework (.NET 10.0for preview.11 and earlier). (TheBeutl.Extensibility.Sdkwill override this anyway, but pick a framework that matches the Beutl release you target so IntelliSense is correct from the start.) -
Click Create.
Ensure the directory structure is as follows:
MyBeutlExtension
┣━ MyBeutlExtension
┃ ┣━ obj
┃ ┃ ┗━ (...)
┃ ┣━ Class1.cs
┃ ┗━ MyBeutlExtension.csproj
┗━ MyBeutlExtension.sln
- Run the following commands to generate
nuget.configand add the package source.
dotnet new nugetconfig
dotnet nuget add source "https://nuget.beditor.net/v3/index.json" --name nuget.beditor.net
- Edit the generated
MyBeutlExtension.csprojas follows:
<Project Sdk="Beutl.Extensibility.Sdk/2.0.0-preview.14">
<PropertyGroup>
<PackageId>MyBeutlExtension</PackageId>
<Title>Sample Extension</Title>
<Description>Sample</Description>
<PackageTags>sample</PackageTags>
<Version>1.0.0</Version>
<Authors>Author Name</Authors>
<RepositoryUrl>url/to/repository</RepositoryUrl>
<DebugApplication Condition="'$(Configuration)'=='Debug'">true</DebugApplication>
</PropertyGroup>
</Project>
- Click Restore NuGet Packages to ensure that NuGet dependencies are restored correctly.

This completes the creation of an empty C# project for extensions.