Browse Source

Merge pull request #353 from VaclavElias/update-26-add-extensibility

docs: Add Extensibility section and C# Libraries guide
Vaclav Elias 1 year ago
parent
commit
1d4209c670
3 changed files with 51 additions and 0 deletions
  1. 38 0
      en/manual/extensibility/csharp-libraries.md
  2. 7 0
      en/manual/extensibility/index.md
  3. 6 0
      en/manual/toc.yml

+ 38 - 0
en/manual/extensibility/csharp-libraries.md

@@ -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 - 0
en/manual/extensibility/index.md

@@ -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 - 0
en/manual/toc.yml

@@ -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: