Friday, November 26, 2021 / dotnet DirectoryBuildProps EmbeddedResource

Automatically Embed resources in dotnet

Automatically Embed Resources in dotnet


I am working on source generators and I want to include my scriban template in the dll as an embedded resource. This makes for easier to read templates than using multiline strings in the C# code itself.


Inside your Directory.Build.props file add the following:

  <Target Name="EmbedLocal" BeforeTargets="PrepareForBuild">    
    <!-- Include each file with given extension from None collection to EmbeddedResource-->
      <EmbeddedResource Include="@(None -> WithMetadataValue('Extension', '.scriban'))" />
      <EmbeddedResource Include="@(None -> WithMetadataValue('Extension', '.MyCoolExtension'))" />


To validate your resources are included you can use Telerik's JustDecomplie