Skip to main content

AssemblyVersionInfo by Black White Yoshi

NuGet / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: AssemblyVersionInfo

AssemblyVersionInfo is a very simple source generator that generates constant strings of your assembly name and version. The intended usage is for the System.CodeDom.Compiler.GeneratedCodeAttribute.

Author: Black White Yoshi

NuGet: https://www.nuget.org/packages/AssemblyVersionInfo/

You can find more details at https://github.com/BlackWhiteYoshi/AssemblyVersionInfo

Source: https://github.com/BlackWhiteYoshi/AssemblyVersionInfo

Original Readme

note

AssemblyVersionInfo

AssemblyVersionInfo is a very simple source generator that generates constant strings of your assembly name and version.
The intended usage is for the GeneratedCodeAttribute.

All it does is generating a the static class Assembly in the namespace AssemblyVersionInfo:

// <auto-generated/>

namespace AssemblyVersionInfo;

internal static class Assembly {
public const string NAME = "{{compilation.name}}";

public const string VERSION_MAJOR = "{{compilation.version.Major}}";
public const string VERSION_MINOR = "{{compilation.version.Minor}}";
public const string VERSION_BUILD = "{{compilation.version.Build}}";
public const string VERSION_REVISION = "{{compilation.version.Revision}}";

public const string VERSION = "{{compilation.version}}";
public const string VERSION_MAJOR_MINOR = "{{compilation.version.Major}}.{{compilation.version.Minor}}";
public const string VERSION_MAJOR_MINOR_BUILD = "{{compilation.version.Major}}.{{compilation.version.Minor}}.{{compilation.version.Build}}";
}

## Get Started
  1. Add PackageReference to your .csproj file.
<ItemGroup>
<PackageReference Include="AssemblyVersionInfo" Version="{latest version}" PrivateAssets="all" />
</ItemGroup>
  1. Access the strings in the Assembly class.
using AssemblyVersionInfo;

const string example = $"AssemblyName={Assembly.NAME}, AssemblyVersion={Assembly.VERSION}";
Console.WriteLine(example);

About

note

Generating assembly version and other info from csproj to csharp

How to use

Example (source csproj, source files)

This is the CSharp Project that references AssemblyVersionInfo

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>


<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="AssemblyVersionInfo" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated/>
#pragma warning disable
#nullable enable annotations


namespace AssemblyVersionInfo;

/// <summary>
/// This class provides constant strings holding information about the Assembly name and version.
/// </summary>
[System.CodeDom.Compiler.GeneratedCodeAttribute("AssemblyVersionInfo", "1.0.2")]
internal static class Assembly {
/// <summary>
/// The simple name of the assembly.
/// </summary>
public const string NAME = "DemoAttr";


/// <summary>
/// The major component of the version number, thats usually the first number.
/// </summary>
public const string VERSION_MAJOR = "1";

/// <summary>
/// The minor component of the version number, thats usually the second number.
/// </summary>
public const string VERSION_MINOR = "0";

/// <summary>
/// The build component of the version number, thats usually the third number.
/// </summary>
public const string VERSION_BUILD = "0";

/// <summary>
/// The revision component of the version number, thats usually the fourth number.
/// </summary>
public const string VERSION_REVISION = "0";


/// <summary>
/// <para>The full version number:</para>
/// <para>{Major}.{Minor}.{Build}.{Revision}</para>
/// </summary>
public const string VERSION = "1.0.0.0";

/// <summary>
/// <para>Version number with only major and minor:</para>
/// <para>{Major}.{Minor}</para>
/// </summary>
public const string VERSION_MAJOR_MINOR = "1.0";

/// <summary>
/// <para>Version number with only major, minor and build:</para>
/// <para>{Major}.{Minor}.{Build}</para>
/// </summary>
public const string VERSION_MAJOR_MINOR_BUILD = "1.0.0";
}

Useful

Download Example (.NET C#)

Share AssemblyVersionInfo

https://ignatandrei.github.io/RSCG_Examples/v2/docs/AssemblyVersionInfo

In the same category (EnhancementProject) - 19 other generators

AutoInvoke.Generator

AutoSpectre

BuildInfo

CommandLine

Credfeto.Version.Information.Generator

Larcanum.GitInfo

LinqGen.Generator

Pekspro.BuildInformationGenerator

PlantUmlClassDiagramGenerator

RSCG_AMS

RSCG_ExportDiagram

RSCG_FunctionsWithDI

RSCG_NameGenerator

RSCG_TimeBombComment

RSCG_Wait

ShadowWriterProjectInfo

ThisAssembly

ThisAssembly.Constants

ThisAssembly.Metadata