Skip to main content
Version: 2.0.0-preview

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.

tip

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​

  1. 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
  1. Run the following commands to generate nuget.config and add the package source. The Beutl SDK and runtime packages are distributed via the nuget.beditor.net feed.
dotnet new nugetconfig
dotnet nuget add source "https://nuget.beditor.net/v3/index.json" --name nuget.beditor.net
  1. Edit the generated MyBeutlExtension.csproj as 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 TargetFramework to net11.0 (net10.0 up to preview.11), plus ImplicitUsings and Nullable to enable.
  • Adding PackageReferences to Beutl.Api, Beutl.Extensibility, Beutl.ProjectSystem, Beutl.NodeGraph, Beutl.Editor, Beutl.Controls, and the Beutl.Engine.SourceGenerators analyzer.
  • Redirecting the output path to ~/.beutl/sideloads/<AssemblyName> when DebugApplication is true.
  • Turning each BeutlHostPackageReference into a compile-only reference at the version Beutl ships (since preview.11).
  • Compiling async methods with .NET 11 runtime async, as Beutl does (since preview.14).
info

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:

  • BeutlAutoReferenceAll
  • BeutlAutoReferenceApi
  • BeutlAutoReferenceExtensibility
  • BeutlAutoReferenceProjectSystem
  • BeutlAutoReferenceNodeGraph
  • BeutlAutoReferenceEditor
  • BeutlAutoReferenceControls
  • BeutlAutoReferenceSourceGenerators

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​

  1. Open Visual Studio and click File > New > Project. Create Visual Studio Project

  2. Select Class Library and click Next. Select Class Library

  3. Enter the project name and location, then click Next. Confirm Name and Location

  4. Select .NET 11.0 as the framework (.NET 10.0 for preview.11 and earlier). (The Beutl.Extensibility.Sdk will override this anyway, but pick a framework that matches the Beutl release you target so IntelliSense is correct from the start.)

  5. Click Create.

Ensure the directory structure is as follows:

MyBeutlExtension
┣━ MyBeutlExtension
┃ ┣━ obj
┃ ┃ ┗━ (...)
┃ ┣━ Class1.cs
┃ ┗━ MyBeutlExtension.csproj
┗━ MyBeutlExtension.sln
  1. Run the following commands to generate nuget.config and add the package source.
dotnet new nugetconfig
dotnet nuget add source "https://nuget.beditor.net/v3/index.json" --name nuget.beditor.net
  1. Edit the generated MyBeutlExtension.csproj as 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>
  1. Click Restore NuGet Packages to ensure that NuGet dependencies are restored correctly. Restore NuGet Packages

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

Source​