Sylvan.BuildTools.Resources 0.6.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Sylvan.BuildTools.Resources --version 0.6.1
NuGet\Install-Package Sylvan.BuildTools.Resources -Version 0.6.1
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="Sylvan.BuildTools.Resources" Version="0.6.1">
  <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 Sylvan.BuildTools.Resources --version 0.6.1
#r "nuget: Sylvan.BuildTools.Resources, 0.6.1"
#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 Sylvan.BuildTools.Resources as a Cake Addin
#addin nuget:?package=Sylvan.BuildTools.Resources&version=0.6.1

// Install Sylvan.BuildTools.Resources as a Cake Tool
#tool nuget:?package=Sylvan.BuildTools.Resources&version=0.6.1

Sylvan.BuildTools.Resources

Provides resource file support and code generation in C# projects. Referencing the Sylvan.BuildTools.Resources package will not add a rumtine dependency to your project, nor create a transitive package dependency for your nuget package. The package operates at build time and will embed resources in your output assembly, and includes compiled code files containing resource accessors.

Localized Resource .resj Files

JSON resource files provides an alternative to using resx XML resource files to define resources in C# projects.

The benefits over resx are:

  • human authorable file format (resx is human readable, but diffcult to author without documentation or tooling support)
  • generated C# code doesn't get included in project/source control (unlike designer.cs files)
  • Doesn't require modifying the .csproj (adding a single resx file will add ~12 lines to your csproj file)
  • Implemented with build-time code-gen and doesn't require Visual Studio to function. (resx files require Visual Studio design time code gen)
  • Still get Intellisense in Visual Studio for the generated code.

JSON resource files use the ".resj" file extension, and a very simple json document to specify resources. Currently supports strings and text files. Text file path should be specified relative to the resj file location. Supports creating localized satellite assemblies using the same naming convention as resx.

Example files:

[Resources.resj]

{
  "Strings": {
    "Greeting": "Hello, Resj",
    "Farewell": "Goodbye, Resx"
  },
  "Files": {
    "ComplexQuery": "sql/query.sql"
  }
}

[Resources.de-DE.resj]

{
  "Strings": {
    "Greeting": "Hallo, Resj",
    "Farewell": "Auf Wiedersehen, Resx"
  }
}

You can control the resource generation specifying a custom namespace, and the visibility of the generated class:

  <ItemGroup>
    <JsonResource Update="Path/To/Resource.resj">
      <AccessModifier>Public</AccessModifier>
      <Namespace>CustomNS</Namespace>
      <ResourceName>CustomResourceName</ResourceName>
    </JsonResource>
  </ItemGroup>

Static String Code Generation

The static string code generation feature allows adding string constants to your project where each string constant is defined in a separate file in a folder structure. This is intended to support scenarios where you need to include long string constants that contain structured language that would be better maintained in a separate file, instead of inlining the code in a C# file. This allows text like long SQL queries, chunks of HTML or JavaScript to be edited in a file with appropriate syntax highlighting, then accessed from C# code as if it were defined as a native string constant.

Static resources are added to a project by defining a StaticResourceFolder item in the .csproj file, which names a folder that contains static resource files.

	<ItemGroup>
		<StaticResourceFolder Include="Sql"/>
	</ItemGroup>

If the Sql folder contains a file named select_user_data.sql it would generate code roughly equivalent to the following:

namespace ProjectRootNamespace {
    class Sql {
        public static readonly string SelectUserData = "...";
    }
}

The generated code is compiled into the project assembly, but is not included in the project source code. The generated types/members will still be visible in intellisense in Visual Studio.

Release Notes:

0.6.1

  • Adds PreProcess capability to StaticResourceFolder.
  • Improves error reporting for some malformed JSON scenarios.

0.6.0

  • Adds support for generating static code from a folder holding static resources (non-localizable).

0.5.1

  • Mark package as DevelopmentDependency so it doesn't become a transitive dependency for consuming packages.

0.5.0

  • Project/package renamed to avoid name collision with technology from mega-corp.

0.4.0

  • Adds code comments to generated code, allowing projects that use WarningsAsErrors and DocumentationFile to compile without error.
  • Big thanks to @teddybeermaniac for his contribution here.

Running Sylvan.BuildTools.Resources.Tests on Unix

If you'd like to develop Sylvan.BuildTools.Resources under Mono, and encounter issues with reference assemblies not being found while running tests, you might need to run something similar beforehand (source1, source2):

export FrameworkPathOverride=/lib/mono/4.6-api
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Sylvan.BuildTools.Resources:

Repository Stars
MarkPflug/Sylvan.Data.Excel
The fastest .NET library for reading Excel data files.
Version Downloads Last updated
0.6.1 3,462 1/23/2023
0.6.1-b0001 545 1/22/2023
0.6.0 1,876 1/20/2022
0.5.1 339 1/10/2022
0.5.0 657 1/27/2021