NetEscapades.ProjectInfo
A source generator for exposing information about your project at compile time
Install
| Product | Versions |
|---|---|
| .NET Standard |
README
NetEscapades.ProjectInfo
NetEscapades.ProjectInfo is a small source generator that echoes values from your project file into a generated ProjectInfo class, as const string values or as ReadOnlySpan<byte> UTF-8 literals.
Adding NetEscapades.ProjectInfo to your project
Add the package to your application using
dotnet add package NetEscapades.ProjectInfo
You can mark the package as PrivateAssets="all", as nothing from it is needed at runtime.
Usage
Declare the values you want in your .csproj file:
<ItemGroup>
<ProjectInfoString Include="Version" Value="1.2.3" />
<ProjectInfoUtf8 Include="VersionBytes" Value="4.5.6" />
</ItemGroup>
This generates the following class:
#nullable enable
internal static partial class ProjectInfo
{
public const string Version = "1.2.3";
public static global::System.ReadOnlySpan<byte> VersionBytes => "4.5.6"u8;
}
ProjectInfoStringgenerates apublic const string.ProjectInfoUtf8generates aReadOnlySpan<byte>property using a"..."u8literal. This requires C# 11 or later (and a target that hasReadOnlySpan<byte>, e.g. the System.Memory package on .NET Framework).- The item name (
Version) is the member name, and theValuemetadata is the value (an empty or missingValuegenerates""). Nothing is generated if you don't declare any items.
The class is generated in your project's <RootNamespace> if one is set, otherwise in the global namespace. It is internal and partial by default; set <ProjectInfoVisibility>public</ProjectInfoVisibility> to make it public.
Diagnostics
Invalid items are reported as errors and skipped; other items are still generated.
| ID | Meaning |
|---|---|
| NEPI001 | The item name is not a valid C# identifier (or is ProjectInfo) |
| NEPI002 | The item name is defined more than once (the first definition wins) |
| NEPI003 | No longer used: an empty Value generates an empty string |
| NEPI004 | ProjectInfoUtf8 is used with a language version lower than C# 11 |
| NEPI005 | An item could not be read: values containing a back-quote (`) are not supported |
Changes from Previous Version
Adoption Assessment
Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.
Related Guides & Workflows
Learn how to evaluate, integrate, or audit this package in your .NET project.