Skip to content

A source generator that generates C# code based on Sitecore Content Serialization (SCS) .yml files.

License

Notifications You must be signed in to change notification settings

hermanussen/Fairy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fairy

A source generator that generates C# code based on Sitecore Content Serialization (SCS) .yml files.

publish to nuget Nuget Nuget Twitter URL

⚠️ This package is highly experimental! It has not been tested very well.

⚠️ Visual Studio does not support generated code very well in < .NET 5 projects, and Sitecore needs a 4.x full framework version. This results in errors when editing (though it DOES work when building).

Installation

  1. Ensure that you have .NET 5 installed. It does not have to be used in your project, but you do need it for the source generator to work.
  2. Install the NuGet package in your project. Run the following command in the NuGet package manager console
Install-Package Fairy
  1. Ensure the SCS .yml files that you want to generate code for are added as AdditionalFiles in your .csproj file. E.g.:
<ItemGroup>
  <AdditionalFiles Include="../serialization/**/*.yml" Visible="false" />
</ItemGroup>
  1. You can now use the generated classes in your code. Reference the following namespace to get to them.
using Templates;

Use your own Scriban template instead of the default one

If you have specific needs for the generated code, you can easily create a Scriban template to replace the default one. All you have to do is:

  1. Create a file named FairyTemplate.sbntxt and place it in the root of your project.
  2. Ensure that the file is included in the AdditionalFiles for your project (the same way that you include your json files).
  3. Copy the contents of the default template, paste them in the file and save. Or find a template you like under the templates that are used for testing
  4. Change the template in any way you want, and you should observe the changes when you build your project.

Viewing generated source files

Because of the Visual Studio issue that is mentioned in the warning above, it may be helpful to view the generated source files. If you add the following to your project file, you can see the generated files in the obj\GeneratedFiles folder.

<PropertyGroup>
  <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
  <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GeneratedFiles</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

More

It was based on ideas and code from:

About

A source generator that generates C# code based on Sitecore Content Serialization (SCS) .yml files.

Topics

Resources

License

Stars

Watchers

Forks

Languages