AzureZeng.MSBuildTasks.Json2Resources 1.0.1

dotnet add package AzureZeng.MSBuildTasks.Json2Resources --version 1.0.1
                    
NuGet\Install-Package AzureZeng.MSBuildTasks.Json2Resources -Version 1.0.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="AzureZeng.MSBuildTasks.Json2Resources" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AzureZeng.MSBuildTasks.Json2Resources" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="AzureZeng.MSBuildTasks.Json2Resources" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AzureZeng.MSBuildTasks.Json2Resources --version 1.0.1
                    
#r "nuget: AzureZeng.MSBuildTasks.Json2Resources, 1.0.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.
#:package AzureZeng.MSBuildTasks.Json2Resources@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AzureZeng.MSBuildTasks.Json2Resources&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=AzureZeng.MSBuildTasks.Json2Resources&version=1.0.1
                    
Install as a Cake Tool

Json2Resource

This NuGet package converts JSON resource file(s) to standard .NET resource (.resources) files and embeds them into the target assembly automatically during build.

Currently, this package is enough for normal usage. Maybe more features are needed to be implemented in the future.

WARNING: This package may have some breaking changes in the future.

Usage

After installing this package, add JSON resource file(s) as JsonResource item type:

<ItemGroup>
    <JsonResource Include="Test.json"/>
</ItemGroup>

The JSON manifest is converted to a .resources file and embedded into the assembly automatically. The intermediate .resources files are generated under the IntermediateOutputPath and are removed when the project is cleaned.

How it works

  1. JsonResourcePropEval evaluates each JsonResource item and computes its LogicalName (RootNamespace + directory-as-namespace + file name, with a .resources suffix) and IntermediatePath (obj/{LogicalName}.resources). It also scans every manifest for external files referenced through the FilePrefix keys.
  2. CompileJsonResources converts each manifest into a .resources file. See JSON_RES_FORMAT.md for the manifest format.
  3. CompileAndAddJsonResources adds the generated files as EmbeddedResource items, so they are compiled into the assembly.

Supported properties

Property Name Description Accepted Values Default Value
FilePrefix The prefix of resource keys whose value is loaded from an external file Any string $file:
LogicalName The logical resource name in the assembly Any Auto-determined by task
ContextPath Base directory for resolving relative external file paths in the manifest FileDir, or any directory Project directory

Notes:

  • LogicalName defaults to RootNamespace + the manifest's relative path (directories become namespace segments, e.g. Data/Test.json under root namespace MyApp yields MyApp.Data.Test). Setting LogicalName explicitly overrides the whole name (the .resources suffix is appended automatically).
  • ContextPath is used only when resolving relative paths in external-file ($file:) values. If it is set to FileDir, the base directory becomes the directory that contains the JSON manifest file; otherwise it is interpreted as a directory, defaulting to the project directory.

Reading the resources at runtime

The resources are embedded with their logical names and can be loaded with ResourceManager:

var rm = new ResourceManager("MyApp.Data.Test", typeof(SomeTypeInTheAssembly).Assembly);

string   text   = rm.GetString("SubKeys.Key1");   // nested keys are flattened with dots
byte[]   binary = (byte[])rm.GetObject("Image");  // external file, binary mode (prefix is stripped)
Stream   stream = rm.GetStream("Log");            // external file, stream mode (prefix is stripped)

Incremental builds

The CompileJsonResources target tracks both the JSON resource files and the external files referenced by FilePrefix keys as incremental-build inputs. Changes to either trigger regeneration, so the embedded resources never go stale.

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.1 153 8/2/2026
1.0.0 134 8/2/2026
0.0.2 297 11/16/2025
0.0.1.5 228 11/22/2024
0.0.1.4 259 8/19/2024
0.0.1.3 225 7/17/2024
0.0.1.2 204 7/17/2024