Raffinert.ContentItemAccessGenerator 1.0.5

dotnet add package Raffinert.ContentItemAccessGenerator --version 1.0.5                
NuGet\Install-Package Raffinert.ContentItemAccessGenerator -Version 1.0.5                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Raffinert.ContentItemAccessGenerator" Version="1.0.5">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Raffinert.ContentItemAccessGenerator --version 1.0.5                
#r "nuget: Raffinert.ContentItemAccessGenerator, 1.0.5"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Raffinert.ContentItemAccessGenerator as a Cake Addin
#addin nuget:?package=Raffinert.ContentItemAccessGenerator&version=1.0.5

// Install Raffinert.ContentItemAccessGenerator as a Cake Tool
#tool nuget:?package=Raffinert.ContentItemAccessGenerator&version=1.0.5                

StandWithUkraine

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

NuGet version (Raffinert.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();
    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);
  • 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:

There are no supported framework assets in this package.

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.

Version Downloads Last updated
1.0.5 73 10/22/2024
1.0.4 66 10/22/2024
1.0.3 78 10/14/2024
1.0.2 87 10/8/2024
1.0.1 71 10/7/2024
1.0.0 78 10/7/2024

v 1.0.5 - Fix missing using System.Threading directive.
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.