Datacute.EmbeddedResourcePropertyGenerator
0.0.1-alpha
See the version list below for details.
dotnet add package Datacute.EmbeddedResourcePropertyGenerator --version 0.0.1-alpha
NuGet\Install-Package Datacute.EmbeddedResourcePropertyGenerator -Version 0.0.1-alpha
<PackageReference Include="Datacute.EmbeddedResourcePropertyGenerator" Version="0.0.1-alpha"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Datacute.EmbeddedResourcePropertyGenerator" Version="0.0.1-alpha" />
<PackageReference Include="Datacute.EmbeddedResourcePropertyGenerator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Datacute.EmbeddedResourcePropertyGenerator --version 0.0.1-alpha
#r "nuget: Datacute.EmbeddedResourcePropertyGenerator, 0.0.1-alpha"
#:package Datacute.EmbeddedResourcePropertyGenerator@0.0.1-alpha
#addin nuget:?package=Datacute.EmbeddedResourcePropertyGenerator&version=0.0.1-alpha&prerelease
#tool nuget:?package=Datacute.EmbeddedResourcePropertyGenerator&version=0.0.1-alpha&prerelease
Embedded Resource Property Generator
This project generates properties for embedded resources in a project.
In a similar way to how the resx source generator adds properties for strings or objects in a resx file, this project adds properties where the embedded resources are a directory of files.
By adding the EmbeddedResourceProperties attribute to a partial class,
and specifying the filename extension and folder path to search,
the source generator will add a property to the class
for each matching embedded resource file. Accessing the property will
return the text content of the embedded resource file.
Why not just use a resx file?
The use case for this project is when you have a large number of text files that you want to embed in your project, such as SQL queries, and you wish to develop these files with an external editor that supports syntax highlighting, execution, debugging, and other features.
While resx files do support including files, doing so requires either the use of another custom editor, or manipulating the xml of the resx file directly.
What's wrong with just using Assembly.GetManifestResourceStream?
The purpose of providing properties to access the text, is to aid the developer by generating doc-comments along with the properties, showing the start of the file.
/// <summary>Text value of the Embedded Resource: GoodIndenting.cypher</summary>
/// <value>
/// <code>
/// MERGE (n)
/// ON CREATE SET n.prop = 0
/// MERGE (a:A)-[:T]-(b:B)
/// ON CREATE SET a.name = 'me'
/// ON MATCH SET b.name = 'you'
/// RETURN a.prop
/// </code>
/// </value>
/// <remarks>
/// The value is read from the embedded resource on first access.
/// </remarks>
public static string GoodIndenting => _GoodIndenting ??= ReadEmbeddedResource("StyleGuide.GoodIndenting.cypher");
private static string? _GoodIndenting;
The full names of the embedded resources are also generated, and no longer need to be supplied by the developer, making it easy to move the location of the resource files to another directory, without needing to find and fix all the references to the resource names.
Usage
- Add a reference to the
EmbeddedResourcePropertyGeneratorproject. - Modify your project file to include the following:
<PropertyGroup>
<AdditionalFileItemNames>$(AdditionalFileItemNames);EmbeddedResource</AdditionalFileItemNames>
</PropertyGroup>
- Add a directory to your project to group the files you want to embed.
- Add text files to your project, in that directory, and set their Build Action to
EmbeddedResource.
> SqlQueries
SelectAll.sql
SelectById.sql
Program.cs
<ItemGroup>
<EmbeddedResource Include="SqlQueries\SelectAll.sql" />
<EmbeddedResource Include="SqlQueries\SelectById.sql"/>
</ItemGroup>
- Add a partial class to your code.
- Include a using statement to the namespace of the code generator.
- Put the attribute
[EmbeddedResourcePropertyGenerator]on the class - Use the properties generated on the partial class.
using Datacute.EmbeddedResourcePropertyGenerator;
[EmbeddedResourceProperties(".sql", "SqlQueries")]
public static partial class SqlQuery;
class Program
{
static void Main()
{
Console.WriteLine(SqlQuery.SelectAll);
}
}
Localisation and External Overrides
Localisation and External Overrides are not supported. If you need these features, consider using a resx file instead.
Non-text file types
This project expects UTF-8 encoded text files, so that it can generate doc-comments.
If you need to embed other types of files, use the Assembly.GetManifestResourceStream method directly.
Extending the Behaviour
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.11.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.1 | 132 | 8/3/2025 |
| 1.1.0 | 121 | 6/29/2025 |
| 1.0.0 | 155 | 10/28/2024 |
| 0.0.1-alpha.6b | 84 | 9/24/2024 |
| 0.0.1-alpha.5 | 78 | 9/22/2024 |
| 0.0.1-alpha.4 | 120 | 9/15/2024 |
| 0.0.1-alpha.3 | 88 | 9/14/2024 |
| 0.0.1-alpha | 111 | 9/9/2024 |