Raffinert.ContentItemAccessGenerator
1.0.4
See the version list below for details.
dotnet add package Raffinert.ContentItemAccessGenerator --version 1.0.4
NuGet\Install-Package Raffinert.ContentItemAccessGenerator -Version 1.0.4
<PackageReference Include="Raffinert.ContentItemAccessGenerator" Version="1.0.4"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Raffinert.ContentItemAccessGenerator --version 1.0.4
#r "nuget: Raffinert.ContentItemAccessGenerator, 1.0.4"
// Install Raffinert.ContentItemAccessGenerator as a Cake Addin #addin nuget:?package=Raffinert.ContentItemAccessGenerator&version=1.0.4 // Install Raffinert.ContentItemAccessGenerator as a Cake Tool #tool nuget:?package=Raffinert.ContentItemAccessGenerator&version=1.0.4
A refined version of the original EmbeddedResourceAccessGenerator by ChristophHornung adapted for Content items.
Important: The original EmbeddedResourceAccessGenerator is incompatible with this generator and must be removed before adding this generator.
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
content item 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();
string text = Content_TestAsset.Test_txt.ReadAllText();
string textAsync = await Content_TestAsset.Test_txt.ReadAllTextAsync(CancellationToken.None);
byte[] bytes = Content_TestAsset.Test_txt.ReadAllBytes();
byte[] bytesAsync = await Content_TestAsset.Test_txt.ReadAllBytesAsync(CancellationToken.None);
See also:
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.4 - Fix missing using System.Threading.Tasks directive.
v 1.0.3 - Separate readmes between the projects and update them.
v 1.0.2 - Added ReadAllBytes and ReadAllBytesAsync methods
v.1.0.1 - Fix the msbuild condition
v.1.0.0 - Initial release.