Skip to content

Commit

Permalink
Merge pull request #353 from VaclavElias/update-26-add-extensibility
Browse files Browse the repository at this point in the history
docs: Add Extensibility section and C# Libraries guide
  • Loading branch information
VaclavElias authored Dec 1, 2024
2 parents 82e88e6 + fc9c780 commit 1d4209c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
38 changes: 38 additions & 0 deletions en/manual/extensibility/csharp-libraries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# C# Libraries

<span class="badge text-bg-primary">Advanced</span>
<span class="badge text-bg-success">Programmer</span>

If you want to share code between multiple projects or create reusable components, you can create a C# library and reference it in your Stride project.

If your library uses the @Stride.Core.DataContractAttribute and you want to reference it through a **NuGet** package, there are additional steps required to make it compatible with Stride.

## Adding a Module Initializer

First, add a module initializer to your library. This ensures your library is properly registered with Stride's serialization system.

Example `Module.cs`:

```csharp
using Stride.Core.Reflection;
using System.Reflection;

namespace MyProjectName;

internal class Module
{
[ModuleInitializer]
public static void Initialize()
{
AssemblyRegistry.Register(typeof(Module).GetTypeInfo().Assembly, AssemblyCommonCategories.Assets);
}
}
```

## Updating to the Latest Stride NuGet Packages

If your library references any Stride NuGet packages, you must recompile it with the latest version of those packages. This ensures compatibility with the current Stride ecosystem.

## About the Module Initializer Attribute

The `ModuleInitializer` attribute is now generated using a Roslyn source generator. This means the file `sources/core/Stride.Core.CompilerServices/Generators/ModuleInitializerGenerator.cs` must run during your code's compilation. Otherwise, the module initializer and potentially other source generators added in the future will not function correctly.
7 changes: 7 additions & 0 deletions en/manual/extensibility/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Extensibility

## Introduction

Stride game project is a regular .NET project, and as such, it can be extended by a regular C# library. This is a great way to share code between multiple projects, or to create reusable components.

Read more about this subject in [C# Libraries](extensibility/csharp-libraries.md).
6 changes: 6 additions & 0 deletions en/manual/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,12 @@ items:
- name: Create Packages
href: nuget/create-packages.md

- name: Extensibility
href: extensibility/index.md
items:
- name: C# Libraries
href: extensibility/csharp-libraries.md

- name: Troubleshooting
href: troubleshooting/index.md
items:
Expand Down

0 comments on commit 1d4209c

Please sign in to comment.