RSCG – AssemblyVersionInfo

RSCG – AssemblyVersionInfo
 
 

name AssemblyVersionInfo
nuget https://www.nuget.org/packages/AssemblyVersionInfo/
link https://github.com/BlackWhiteYoshi/AssemblyVersionInfo
author Black White Yoshi

Generating assembly version and other info from csproj to csharp

 

This is how you can use AssemblyVersionInfo .

The code that you start with is


<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>


The code that you will use is


// Access project information anywhere in your code 
Console.WriteLine($"Project Name: {AssemblyVersionInfo.Assembly.NAME}");
Console.WriteLine($"Project Version: {AssemblyVersionInfo.Assembly.VERSION}");
;

 

The code that is generated is

// <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";
}

// <auto-generated/>

using System;
using System.CodeDom.Compiler;
using System.Runtime.CompilerServices;

namespace ShadowWriter
{
    [CompilerGenerated]
    [GeneratedCode("ShadowWriter", "0.9.5.0")]
    [System.AttributeUsage(AttributeTargets.Class)]
    internal sealed class BuilderAttribute : System.Attribute
    {

    }
}
// <auto-generated/>

using System;
using System.CodeDom.Compiler;
using System.Runtime.CompilerServices;

namespace ShadowWriter
{
    [CompilerGenerated]
    [GeneratedCode("ShadowWriter", "0.9.5.0")]
    [System.AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class)]
    internal sealed class NullObjectAttribute : System.Attribute
    {

    }

    [CompilerGenerated]
    [GeneratedCode("ShadowWriter", "0.9.5.0")]
    [System.AttributeUsage(System.AttributeTargets.Interface)]
    internal sealed class ClassNameAttribute : System.Attribute
    {
        public string Name { get; }

        public ClassNameAttribute(string name)
        {
            this.Name = name;
        }

        public ClassNameAttribute()
        {
            this.Name = string.Empty;
        }
    }
}
using System;
using System.CodeDom.Compiler;
using System.Runtime.CompilerServices;

namespace ShadowWriter;

[CompilerGenerated]
[GeneratedCode("ShadowWriter", "0.9.5.0")]
internal static class TheProject
{
  public static string FullPath => @"D:\gth\RSCG_Examples\v2\rscg_examples\ShadowWriterProjectInfo\src\DemoAttr\DemoAttr\DemoAttr.csproj";
  public static string ProjectDirectory => @"D:\gth\RSCG_Examples\v2\rscg_examples\ShadowWriterProjectInfo\src\DemoAttr\DemoAttr";
  public static string Name => @"DemoAttr";
  public static string OutDir => @"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\bin\Debug\net9.0\";
  public static string Version => @"1.0.0";
  public static string RootNamespace => @"DemoAttr";
  public static DateTimeOffset BuildTimeUtc => new DateTimeOffset(638911364201257764, TimeSpan.Zero);
}

Code and pdf at

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


Posted

in

, ,

by

Tags: