RSCG – ThisAssembly.Metadata

RSCG – ThisAssembly.Metadata    

name ThisAssembly.Metadata
nuget https://www.nuget.org/packages/ThisAssembly.Metadata/
link https://github.com/devlooped/ThisAssembly
author Daniel Cazzulino

Generating code from assembly metadata

 

This is how you can use ThisAssembly.Metadata .

The code that you start with is

  <Project Sdk="Microsoft.NET.Sdk">    <PropertyGroup>     <OutputType>Exe</OutputType>     <TargetFramework>net8.0</TargetFramework>     <ImplicitUsings>enable</ImplicitUsings>     <Nullable>enable</Nullable>   </PropertyGroup> 	<ItemGroup> 		<AssemblyMetadata Include="MyName" Value="Andrei" /> 	</ItemGroup> 	<ItemGroup> 	  <PackageReference Include="ThisAssembly.Metadata" Version="1.4.3"> 	    <PrivateAssets>all</PrivateAssets> 	    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> 	  </PackageReference> 	</ItemGroup> 	<PropertyGroup> 		<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> 		<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> 	</PropertyGroup> </Project>   

The code that you will use is

  [assembly: System.Reflection.AssemblyMetadataAttribute("Name", "Test")]  Console.WriteLine(ThisAssembly.Metadata.Name); Console.WriteLine(ThisAssembly.Metadata.MyName);   

  The code that is generated is

 //------------------------------------------------------------------------------ // <auto-generated> //     This code was generated by a tool. // //     Changes to this file may cause incorrect behavior and will be lost if //     the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------  using System.CodeDom.Compiler; using System.Runtime.CompilerServices;  /// <summary> /// Provides access to the current assembly information as pure constants,  ///  without requiring reflection. /// </summary> partial class ThisAssembly {     /// <summary>     /// Gets the assembly metadata.     /// </summary>     [GeneratedCode("ThisAssembly.Metadata", "1.4.3")]     [CompilerGenerated]     public static partial class Metadata     {         /// <summary>Name = Test</summary>         public const string Name =  """ Test """;          /// <summary>MyName = Andrei</summary>         public const string MyName =  """ Andrei """;      } } 

Code and pdf at https://ignatandrei.github.io/RSCG_Examples/v2/docs/ThisAssembly.Metadata