RSCG–ShadowWriter ProjectInfo

RSCG – ShadowWriterProjectInfo
 
 

name ShadowWriterProjectInfo
nuget https://www.nuget.org/packages/ShadowWriter/
link https://github.com/StefanStolz/ShadowWriter
author Stefan Stolz

Generating C# code from project attributes

 

This is how you can use ShadowWriterProjectInfo .

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>

  <ItemGroup>
    <PackageReference Include="ShadowWriter" Version="0.9.5">
      <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


// Access project information anywhere in your code 
using ShadowWriter;
Console.WriteLine($"Project Name: {TheProject.Name}");
Console.WriteLine($"Project Version: {TheProject.Version}");
Console.WriteLine($"Project Build Date: {TheProject.BuildTimeUtc}");

 

The code that is generated is

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


Posted

in

, ,

by

Tags: