Raffinert.EmbeddedResourceAccessGenerator
1.0.1
See the version list below for details.
dotnet add package Raffinert.EmbeddedResourceAccessGenerator --version 1.0.1
NuGet\Install-Package Raffinert.EmbeddedResourceAccessGenerator -Version 1.0.1
<PackageReference Include="Raffinert.EmbeddedResourceAccessGenerator" Version="1.0.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Raffinert.EmbeddedResourceAccessGenerator --version 1.0.1
#r "nuget: Raffinert.EmbeddedResourceAccessGenerator, 1.0.1"
// Install Raffinert.EmbeddedResourceAccessGenerator as a Cake Addin #addin nuget:?package=Raffinert.EmbeddedResourceAccessGenerator&version=1.0.1 // Install Raffinert.EmbeddedResourceAccessGenerator as a Cake Tool #tool nuget:?package=Raffinert.EmbeddedResourceAccessGenerator&version=1.0.1
A refined version of the original EmbeddedResourceAccessGenerator by ChristophHornung
EmbeddedResourceAccessGenerator
The Raffinert.EmbeddedResourceAccessGenerator is a code generator to allow easy access to all embedded resources.
Usage
Get the nuget package here.
After referencing the Raffinert.EmbeddedResourceAccessGenerator
nuget the code generation will
automatically create a class EmbeddedResources
in the root namespace of the project.
Together with the generated EmbeddedResource
enumeration there are several options to access
embedded resources:
E.g. for a Test.txt
embedded resource in the TestAsset
folder:
- Via enum access through the
EmbeddedResource
enum:
// Via the generated extension methods on the enum
using Stream s = EmbeddedResource.TestAsset_Test_txt.GetStream();
using StreamReader sr = EmbeddedResource.TestAsset_Test_txt.GetReader();
- Via enum access through the
EmbeddedResource[FolderName]
enum:
// Via the generated extension methods on the enum
using Stream s = EmbeddedResource_TestAsset.Test_txt.GetStream();
using StreamReader sr = EmbeddedResource_TestAsset.Test_txt.GetReader();
ContentItemAccessGenerator
The Raffinert.ContentItemAccessGenerator is a code generator to allow easy access to all content files with CopyToOutputDirectory attribute specified as Always or PreserveNewest.
Usage
Get the nuget package here.
After referencing the Raffinert.ContentItemAccessGenerator
nuget the code generation will
automatically create a class Contents
in the root namespace of the project.
Together with the generated Content
enumeration there are several options to access
content files:
E.g. for a Test.txt
embedded resource in the TestAsset
folder:
- Via enum access through the
Content
enum:
// Via the generated extension methods on the enum
using Stream s = Content.TestAsset_Test_txt.GetStream();
using StreamReader sr = Content.TestAsset_Test_txt.GetReader();
- Via enum access through the
Content[FolderName]
enum:
// Via the generated extension methods on the enum
using Stream s = Content_TestAsset.Test_txt.GetStream();
using StreamReader sr = Content_TestAsset.Test_txt.GetReader();
NoneItemAccessGenerator
The Raffinert.NoneItemAccessGenerator is a code generator to allow easy access to all none item files with CopyToOutputDirectory attribute specified as Always or PreserveNewest.
Usage
Get the nuget package here.
After referencing the Raffinert.NoneItemAccessGenerator
nuget the code generation will
automatically create a class Nones
in the root namespace of the project.
Together with the generated None
enumeration there are several options to access
none item files:
E.g. for a Test.txt
embedded resource in the TestAsset
folder:
- Via enum access through the
None
enum:
// Via the generated extension methods on the enum
using Stream s = None.TestAsset_Test_txt.GetStream();
using StreamReader sr = None.TestAsset_Test_txt.GetReader();
- Via enum access through the
None[FolderName]
enum:
// Via the generated extension methods on the enum
using Stream s = None_TestAsset.Test_txt.GetStream();
using StreamReader sr = None_TestAsset.Test_txt.GetReader();
Motivation
Instead of using magic strings in the resource access code that may point to non-existant resources this generator guarantees resources to exist and code to not compile when they are removed.
Grouping the resources via their path adds path specific enums, e.g. to easily write tests for all embedded resource in a subfolder.
Also it saves quite a bit of typing effort.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v 1.0.1
- Added ReadAllBytes and ReadAllBytesAsync methods
v 1.0.0
- Removed EmbeddedResources.{{identifierName}}_Stream and EmbeddedResources.StreamReader {{identifierName}}_Reader properties
- Added ReadAllText and ReadAllTextAsync methods
- No longer generating access for all AdditionalFiles as EmbeddedResources and thereforeit can be used together with ContentItemAccessGenerator and NoneItemAccessGenerator without conflicts.
Precedor's versions - see https://github.com/ChristophHornung/EmbeddedResourceGenerator/blob/main/EmbeddedResourceAccessGenerator/EmbeddedResourceAccessGenerator.csproj