Skip to main content

String Resource Tool creates C# wrapper classes for managed string resources. The app developer creates a .strings file to declare the list of strings. Each line includes the name of the string and its list of parameters. For example: ConnectionFailure(server) = Failed to connect to server {0}. The above line creates the following entry in the wrapper class: [System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class StringConnectionInfo { public static string ConnectionFailure(string server) { return Keys.GetString(Keys.ConnectionFailure, server); } } The package includes a targets file for incorporating srgen into an msbuild-based development project and a sample strings file.

Total Downloads
23.3K
23,307
Published
Nov 16, 2023
3y ago

Get Started

dotnet add package Microsoft.Data.Tools.StringResourceTool --version 4.3.0
ProductVersions
.NET
net6.0
Other
.NETFramework4.6.2

README

Microsoft.Data.Tools.StringResourceTool

This package implements an MSBUILD target that converts a .INI file with a [strings] section into a set of resx and .cs files. The generated C# code provides strongly typed accessors for the resource strings defined in the resx file.

See the Microsoft.Data.Tools.StringResourceTool.targets file for properties that can be set on Sqlstringresource items to customize the code generation.

Sample strings file content

# String resource file
#
# When processed by the String Resource Tool, this file generates
# both a .CS and a .RESX file with the same name as the file.
# The .CS file contains a class which can be used to access these
# string resources, including the ability to format in
# parameters, which are identified with the .NET {x} format
# (see String.Format help).
#
# Comments below assume the file name is SR.strings.
#
# Lines starting with a semicolon ";" are also treated as comments
#

[strings]
ConnectionCannotBeChanged = Connection properties cannot be changed after a connection has been established.
NotInTransaction = Cannot perform this operation as there is no open transaction.
ConnectionFailure(server) = Failed to connect to server {0}.
InvalidPropertyValue(value, property, reason) = Cannot apply value '{0}' to property {1}: {2}.
; this is a comment

Sample project file content


<ItemGroup>
  <Sqlstringresource Include="SR.strings" />
</ItemGroup>

Downloads by Version

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.