diff --git a/README.md b/README.md index e0d983841..467267f7c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# RSCG - 209 Examples of Roslyn Source Code Generators / 14 created by Microsoft / +# RSCG - 210 Examples of Roslyn Source Code Generators / 14 created by Microsoft / -## Latest Update : 2025-07-26 => 26 July 2025 +## Latest Update : 2025-07-28 => 28 July 2025 If you want to see examples with code, please click ***[List V2](https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG)*** @@ -20,11 +20,33 @@ If you want to be notified each time I add a new RSCG example , please click htt ## Content -Those are the 209 Roslyn Source Code Generators that I have tested you can see and download source code example. +Those are the 210 Roslyn Source Code Generators that I have tested you can see and download source code example. ( including 14 from Microsoft ) -### 209. [ShadowWriterProjectInfo](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterProjectInfo) , in the [Builder](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#builder) category +### 210. [AssemblyVersionInfo](https://ignatandrei.github.io/RSCG_Examples/v2/docs/AssemblyVersionInfo) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category -Generated on : 2025-07-24 => 24 July 2025 +Generated on : 2025-07-28 => 28 July 2025 + +
+ Expand + + + +Author: Black White Yoshi + +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. + +Nuget: [https://www.nuget.org/packages/AssemblyVersionInfo/](https://www.nuget.org/packages/AssemblyVersionInfo/) + + +Link: [https://ignatandrei.github.io/RSCG_Examples/v2/docs/AssemblyVersionInfo](https://ignatandrei.github.io/RSCG_Examples/v2/docs/AssemblyVersionInfo) + +Source: [https://github.com/BlackWhiteYoshi/AssemblyVersionInfo](https://github.com/BlackWhiteYoshi/AssemblyVersionInfo) + +
+ +### 209. [ShadowWriterProjectInfo](https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterProjectInfo) , in the [EnhancementProject](https://ignatandrei.github.io/RSCG_Examples/v2/docs/rscg-examples#enhancementproject) category + +Generated on : 2025-07-27 => 27 July 2025
Expand diff --git a/later.md b/later.md index 13c37167d..151b52c36 100644 --- a/later.md +++ b/later.md @@ -1,6 +1,6 @@ # Just later -## Latest Update : 2025-07-26 => 26 July 2025 +## Latest Update : 2025-07-28 => 28 July 2025 diff --git a/v2/Generator/all.csv b/v2/Generator/all.csv index b26f5eaca..07b190d7f 100644 --- a/v2/Generator/all.csv +++ b/v2/Generator/all.csv @@ -207,4 +207,5 @@ Nr,Key,Source,Category 206,ShadowWriterBuilder, https://github.com/StefanStolz/ShadowWriter,Builder 207,AutoInterface, https://github.com/BlackWhiteYoshi/AutoInterface,Interface 208,AsyncIt, https://github.com/oleg-shilo/AsyncIt,Async -209,ShadowWriterProjectInfo, https://github.com/StefanStolz/ShadowWriter,Builder +209,ShadowWriterProjectInfo, https://github.com/StefanStolz/ShadowWriter,EnhancementProject +210,AssemblyVersionInfo, https://github.com/BlackWhiteYoshi/AssemblyVersionInfo,EnhancementProject diff --git a/v2/RSCGExamplesData/GeneratorDataRec.json b/v2/RSCGExamplesData/GeneratorDataRec.json index c0e219d92..5b3dbe2ad 100644 --- a/v2/RSCGExamplesData/GeneratorDataRec.json +++ b/v2/RSCGExamplesData/GeneratorDataRec.json @@ -1259,8 +1259,14 @@ }, { "ID":"ShadowWriterProjectInfo", - "Category": 4, - "dtStart": "2025-07-24T00:00:00", + "Category": 1, + "dtStart": "2025-07-27T00:00:00", + "show": true +}, +{ + "ID":"AssemblyVersionInfo", + "Category": 1, + "dtStart": "2025-07-28T00:00:00", "show": true } ] \ No newline at end of file diff --git a/v2/book/examples/AssemblyVersionInfo.html b/v2/book/examples/AssemblyVersionInfo.html new file mode 100644 index 000000000..4e4b0dd2c --- /dev/null +++ b/v2/book/examples/AssemblyVersionInfo.html @@ -0,0 +1,68 @@ + +

RSCG nr 210 : AssemblyVersionInfo

+ +

Info

+Nuget : https://www.nuget.org/packages/AssemblyVersionInfo/ + +

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

+ +

Author :Black White Yoshi

+ +

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

+ +

About

+ +Generating assembly version and other info from csproj to csharp + +

+ How to use +

+

+ Add reference to the AssemblyVersionInfo in the csproj +

+ + +

This was for me the starting code

+ +
+ I have coded the file Program.cs +
+ +
+

And here are the generated files

+ +
+ The file generated is Assembly.g.cs +
+ + +
+ The file generated is BuilderAttribute.g.cs +
+ + +
+ The file generated is NullObjectAttribute.g.cs +
+ + +
+ The file generated is ShadowWriter.TheProject.g.cs +
+ + +

+ You can download the code and this page as pdf from + + https://ignatandrei.github.io/RSCG_Examples/v2/docs/AssemblyVersionInfo + +

+ + +

+ You can see the whole list at + + https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG + +

+ diff --git a/v2/book/list.html b/v2/book/list.html index 2e81820ee..077841f40 100644 --- a/v2/book/list.html +++ b/v2/book/list.html @@ -17,7 +17,7 @@

-This is the list of 209 RSCG with examples => +This is the list of 210 RSCG with examples =>

@@ -862,6 +862,10 @@

+ + + +
209 ShadowWriterProjectInfo
210AssemblyVersionInfo
diff --git a/v2/book/pandocHTML.yaml b/v2/book/pandocHTML.yaml index a87b5b18a..d45ed22e2 100644 --- a/v2/book/pandocHTML.yaml +++ b/v2/book/pandocHTML.yaml @@ -223,6 +223,7 @@ input-files: - examples/AutoInterface.html - examples/AsyncIt.html - examples/ShadowWriterProjectInfo.html +- examples/AssemblyVersionInfo.html # or you may use input-file: with a single value # defaults: diff --git a/v2/rscg_examples/AssemblyVersionInfo/description.json b/v2/rscg_examples/AssemblyVersionInfo/description.json new file mode 100644 index 000000000..da03ac827 --- /dev/null +++ b/v2/rscg_examples/AssemblyVersionInfo/description.json @@ -0,0 +1,22 @@ +{ + "generator":{ + "name":"AssemblyVersionInfo", + "nuget":[ + "https://www.nuget.org/packages/AssemblyVersionInfo/" + ], + "link":"https://github.com/BlackWhiteYoshi/AssemblyVersionInfo", + "author":"Black White Yoshi", + "source":"https://github.com/BlackWhiteYoshi/AssemblyVersionInfo" + }, + "data":{ + "goodFor":["Generating assembly version and other info from csproj to csharp"], + "csprojDemo":"DemoAttr.csproj", + "csFiles":["Program.cs"], + "excludeDirectoryGenerated":[""], + "includeAdditionalFiles":[""] + }, + "links":{ + "blog":"", + "video":"" + } +} \ No newline at end of file diff --git a/v2/rscg_examples/AssemblyVersionInfo/nuget.txt b/v2/rscg_examples/AssemblyVersionInfo/nuget.txt new file mode 100644 index 000000000..423aa4434 --- /dev/null +++ b/v2/rscg_examples/AssemblyVersionInfo/nuget.txt @@ -0,0 +1 @@ +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. \ No newline at end of file diff --git a/v2/rscg_examples/AssemblyVersionInfo/readme.txt b/v2/rscg_examples/AssemblyVersionInfo/readme.txt new file mode 100644 index 000000000..921634916 --- /dev/null +++ b/v2/rscg_examples/AssemblyVersionInfo/readme.txt @@ -0,0 +1,46 @@ +# 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](https://learn.microsoft.com/en-us//dotnet/api/system.codedom.compiler.generatedcodeattribute). + +All it does is generating a the static class *Assembly* in the namespace *AssemblyVersionInfo*: + +```csharp +// + +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. + +```xml + + + +``` + +2. Access the strings in the *Assembly* class. + +```csharp +using AssemblyVersionInfo; + +const string example = $"AssemblyName={Assembly.NAME}, AssemblyVersion={Assembly.VERSION}"; +Console.WriteLine(example); +``` diff --git a/v2/rscg_examples/AssemblyVersionInfo/src/.tours/AssemblyVersionInfo.tour b/v2/rscg_examples/AssemblyVersionInfo/src/.tours/AssemblyVersionInfo.tour new file mode 100644 index 000000000..29c27e4a5 --- /dev/null +++ b/v2/rscg_examples/AssemblyVersionInfo/src/.tours/AssemblyVersionInfo.tour @@ -0,0 +1,48 @@ + +{ + "$schema": "https://aka.ms/codetour-schema", + "title": "AssemblyVersionInfo", + "steps": + [ + { + "file": "DemoAttr/DemoAttr.csproj", + "description": "First, we add Nuget [AssemblyVersionInfo](https://www.nuget.org/packages/AssemblyVersionInfo/) in csproj ", + "pattern": "AssemblyVersionInfo" + } + + ,{ + "file": "DemoAttr/Program.cs", + "description": "File Program.cs \r\n>> dotnet run --project DemoAttr/DemoAttr.csproj ", + "pattern": "this is the code" + } + + + ,{ + "file": "DemoAttr/obj/GX/ShadowWriter/ShadowWriter.ProjectInfoGenerator/ShadowWriter.TheProject.g.cs", + "description": "Generated File 4 from 4 : ShadowWriter.TheProject.g.cs ", + "line": 1 + } + + ,{ + "file": "DemoAttr/obj/GX/ShadowWriter/ShadowWriter.NullObjectGenerator/NullObjectAttribute.g.cs", + "description": "Generated File 3 from 4 : NullObjectAttribute.g.cs ", + "line": 1 + } + + ,{ + "file": "DemoAttr/obj/GX/ShadowWriter/ShadowWriter.BuilderGenerator/BuilderAttribute.g.cs", + "description": "Generated File 2 from 4 : BuilderAttribute.g.cs ", + "line": 1 + } + + ,{ + "file": "DemoAttr/obj/GX/AssemblyVersionInfo/AssemblyVersionInfo.Generator/Assembly.g.cs", + "description": "Generated File 1 from 4 : Assembly.g.cs ", + "line": 1 + } + + ], + + "ref": "main" + +} \ No newline at end of file diff --git a/v2/rscg_examples/AssemblyVersionInfo/src/DemoAttr.sln b/v2/rscg_examples/AssemblyVersionInfo/src/DemoAttr.sln new file mode 100644 index 000000000..9133e4a8c --- /dev/null +++ b/v2/rscg_examples/AssemblyVersionInfo/src/DemoAttr.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36408.4 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DemoAttr", "DemoAttr\DemoAttr.csproj", "{E7AE387F-3B33-41EF-A809-94E5C21EDBFC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E7AE387F-3B33-41EF-A809-94E5C21EDBFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E7AE387F-3B33-41EF-A809-94E5C21EDBFC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E7AE387F-3B33-41EF-A809-94E5C21EDBFC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E7AE387F-3B33-41EF-A809-94E5C21EDBFC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {75065D34-E2FE-414E-BE26-D871D5945284} + EndGlobalSection +EndGlobal diff --git a/v2/rscg_examples/AssemblyVersionInfo/src/DemoAttr/DemoAttr.csproj b/v2/rscg_examples/AssemblyVersionInfo/src/DemoAttr/DemoAttr.csproj new file mode 100644 index 000000000..222a5170f --- /dev/null +++ b/v2/rscg_examples/AssemblyVersionInfo/src/DemoAttr/DemoAttr.csproj @@ -0,0 +1,23 @@ + + + + Exe + net9.0 + enable + enable + + + + + true + $(BaseIntermediateOutputPath)\GX + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + diff --git a/v2/rscg_examples/AssemblyVersionInfo/src/DemoAttr/Program.cs b/v2/rscg_examples/AssemblyVersionInfo/src/DemoAttr/Program.cs new file mode 100644 index 000000000..8350c315c --- /dev/null +++ b/v2/rscg_examples/AssemblyVersionInfo/src/DemoAttr/Program.cs @@ -0,0 +1,4 @@ +// Access project information anywhere in your code +Console.WriteLine($"Project Name: {AssemblyVersionInfo.Assembly.NAME}"); +Console.WriteLine($"Project Version: {AssemblyVersionInfo.Assembly.VERSION}"); +; \ No newline at end of file diff --git a/v2/rscg_examples/AssemblyVersionInfo/video.json b/v2/rscg_examples/AssemblyVersionInfo/video.json new file mode 100644 index 000000000..cd7fa018a --- /dev/null +++ b/v2/rscg_examples/AssemblyVersionInfo/video.json @@ -0,0 +1,39 @@ +{ + "scriptName": "AssemblyVersionInfo", + "steps": +[ + {"typeStep":"exec","arg":"clipchamp.exe launch"}, + {"typeStep":"text","arg": "Welcome to Roslyn Examples"}, + {"typeStep":"text","arg":"If you want to see more examples , see List Of RSCG"}, + {"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG"}, + {"typeStep":"text","arg": "My name is Andrei Ignat and I am deeply fond of Roslyn Source Code Generator. "}, + +{"typeStep":"text","arg": "Today I will present AssemblyVersionInfo . Generating assembly version and other info from csproj to csharp ."}, +{"typeStep":"browser","arg":"https://www.nuget.org/packages/AssemblyVersionInfo/"}, +{"typeStep":"text","arg": "The whole example is here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/AssemblyVersionInfo"}, +{"typeStep":"text","arg": "You can download the code from here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/AssemblyVersionInfo#download-example-net--c-"}, +{"typeStep":"text","arg":"Here is the code downloaded "}, +{"typeStep":"exec","arg":"explorer.exe /select,D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\AssemblyVersionInfo\\src\\DemoAttr.sln"}, +{"typeStep":"text","arg": "So , let's start the project with Visual Studio Code "}, +{"typeStep":"stepvscode","arg": "-n D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\AssemblyVersionInfo\\src"}, + +{"typeStep":"text","arg": "To use it ,you will put the Nuget AssemblyVersionInfo into the csproj "}, + +{"typeStep":"stepvscode","arg": "-r -g D:\\gth\\RSCG_Examples\\v2\\rscg_examples\\AssemblyVersionInfo\\src\\DemoAttr\\DemoAttr.csproj"}, + +{"typeStep":"text","arg": "And now I will show you an example of using AssemblyVersionInfo"}, + +{"typeStep":"hide","arg": "now execute the tour in VSCode"}, +{"typeStep":"tour", "arg": "src/.tours/"}, +{"typeStep":"text","arg":" And I will execute the project"}, +{"typeStep":"showproj", "arg":"DemoAttr.csproj"}, +{"typeStep":"text","arg":" This concludes the project"}, +{"typeStep":"waitseconds","arg":"30"}, +{"typeStep":"text","arg": "Remember, you can download the code from here"}, +{"typeStep":"browser","arg":"https://ignatandrei.github.io/RSCG_Examples/v2/docs/AssemblyVersionInfo#download-example-net--c-", +SpeakTest=" "}, +{"typeStep":"waitseconds","arg":"30"}, +] +} diff --git a/v2/rscg_examples_site/docs/Categories/Builder.md b/v2/rscg_examples_site/docs/Categories/Builder.md index 8d41eef86..6b0c0d3ba 100644 --- a/v2/rscg_examples_site/docs/Categories/Builder.md +++ b/v2/rscg_examples_site/docs/Categories/Builder.md @@ -1,6 +1,6 @@

Builder

-Number RSCG: 8 +Number RSCG: 7 1 [Architect.DomainModeling](/docs/Architect.DomainModeling) @@ -14,7 +14,5 @@ Number RSCG: 8 6 [ShadowWriterBuilder](/docs/ShadowWriterBuilder) - 7 [ShadowWriterProjectInfo](/docs/ShadowWriterProjectInfo) - - 8 [StepwiseBuilderGenerator](/docs/StepwiseBuilderGenerator) + 7 [StepwiseBuilderGenerator](/docs/StepwiseBuilderGenerator) \ No newline at end of file diff --git a/v2/rscg_examples_site/docs/Categories/EnhancementProject.md b/v2/rscg_examples_site/docs/Categories/EnhancementProject.md index 3e91b5d5c..0f12198d2 100644 --- a/v2/rscg_examples_site/docs/Categories/EnhancementProject.md +++ b/v2/rscg_examples_site/docs/Categories/EnhancementProject.md @@ -1,40 +1,44 @@

EnhancementProject

-Number RSCG: 18 +Number RSCG: 20 - 1 [AutoInvoke.Generator](/docs/AutoInvoke.Generator) + 1 [AssemblyVersionInfo](/docs/AssemblyVersionInfo) - 2 [AutoSpectre](/docs/AutoSpectre) + 2 [AutoInvoke.Generator](/docs/AutoInvoke.Generator) - 3 [BuildInfo](/docs/BuildInfo) + 3 [AutoSpectre](/docs/AutoSpectre) - 4 [CommandLine](/docs/CommandLine) + 4 [BuildInfo](/docs/BuildInfo) - 5 [Credfeto.Version.Information.Generator](/docs/Credfeto.Version.Information.Generator) + 5 [CommandLine](/docs/CommandLine) - 6 [Larcanum.GitInfo](/docs/Larcanum.GitInfo) + 6 [Credfeto.Version.Information.Generator](/docs/Credfeto.Version.Information.Generator) - 7 [LinqGen.Generator](/docs/LinqGen.Generator) + 7 [Larcanum.GitInfo](/docs/Larcanum.GitInfo) - 8 [Pekspro.BuildInformationGenerator](/docs/Pekspro.BuildInformationGenerator) + 8 [LinqGen.Generator](/docs/LinqGen.Generator) - 9 [PlantUmlClassDiagramGenerator](/docs/PlantUmlClassDiagramGenerator) + 9 [Pekspro.BuildInformationGenerator](/docs/Pekspro.BuildInformationGenerator) - 10 [RSCG_AMS](/docs/RSCG_AMS) + 10 [PlantUmlClassDiagramGenerator](/docs/PlantUmlClassDiagramGenerator) - 11 [RSCG_ExportDiagram](/docs/RSCG_ExportDiagram) + 11 [RSCG_AMS](/docs/RSCG_AMS) - 12 [RSCG_FunctionsWithDI](/docs/RSCG_FunctionsWithDI) + 12 [RSCG_ExportDiagram](/docs/RSCG_ExportDiagram) - 13 [RSCG_NameGenerator](/docs/RSCG_NameGenerator) + 13 [RSCG_FunctionsWithDI](/docs/RSCG_FunctionsWithDI) - 14 [RSCG_TimeBombComment](/docs/RSCG_TimeBombComment) + 14 [RSCG_NameGenerator](/docs/RSCG_NameGenerator) - 15 [RSCG_Wait](/docs/RSCG_Wait) + 15 [RSCG_TimeBombComment](/docs/RSCG_TimeBombComment) - 16 [ThisAssembly](/docs/ThisAssembly) + 16 [RSCG_Wait](/docs/RSCG_Wait) - 17 [ThisAssembly.Constants](/docs/ThisAssembly.Constants) + 17 [ShadowWriterProjectInfo](/docs/ShadowWriterProjectInfo) - 18 [ThisAssembly.Metadata](/docs/ThisAssembly.Metadata) + 18 [ThisAssembly](/docs/ThisAssembly) + + 19 [ThisAssembly.Constants](/docs/ThisAssembly.Constants) + + 20 [ThisAssembly.Metadata](/docs/ThisAssembly.Metadata) \ No newline at end of file diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/AssemblyVersionInfo.md b/v2/rscg_examples_site/docs/RSCG-Examples/AssemblyVersionInfo.md new file mode 100644 index 000000000..0d511f398 --- /dev/null +++ b/v2/rscg_examples_site/docs/RSCG-Examples/AssemblyVersionInfo.md @@ -0,0 +1,406 @@ +--- +sidebar_position: 2100 +title: 210 - AssemblyVersionInfo +description: Generating assembly version and other info from csproj to csharp +slug: /AssemblyVersionInfo +--- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import TOCInline from '@theme/TOCInline'; + +# AssemblyVersionInfo by Black White Yoshi + + + + +## NuGet / site data +[![Nuget](https://img.shields.io/nuget/dt/AssemblyVersionInfo?label=AssemblyVersionInfo)](https://www.nuget.org/packages/AssemblyVersionInfo/) +[![GitHub last commit](https://img.shields.io/github/last-commit/BlackWhiteYoshi/AssemblyVersionInfo?label=updated)](https://github.com/BlackWhiteYoshi/AssemblyVersionInfo) +![GitHub Repo stars](https://img.shields.io/github/stars/BlackWhiteYoshi/AssemblyVersionInfo?style=social) + +## 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](https://learn.microsoft.com/en-us//dotnet/api/system.codedom.compiler.generatedcodeattribute). + +All it does is generating a the static class *Assembly* in the namespace *AssemblyVersionInfo*: + +```csharp +// + +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. + +```xml + + + +``` + +2. Access the strings in the *Assembly* class. + +```csharp +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** +```xml showLineNumbers {18} + + + + Exe + net9.0 + enable + enable + + + + + true + $(BaseIntermediateOutputPath)\GX + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + +``` + + + + + + This is the use of **AssemblyVersionInfo** in *Program.cs* + +```csharp showLineNumbers +// Access project information anywhere in your code +Console.WriteLine($"Project Name: {AssemblyVersionInfo.Assembly.NAME}"); +Console.WriteLine($"Project Version: {AssemblyVersionInfo.Assembly.VERSION}"); +; +``` + + + + +### Generated Files + +Those are taken from $(BaseIntermediateOutputPath)\GX + + + + + + + +```csharp showLineNumbers +// +#pragma warning disable +#nullable enable annotations + + +namespace AssemblyVersionInfo; + +/// +/// This class provides constant strings holding information about the Assembly name and version. +/// +[System.CodeDom.Compiler.GeneratedCodeAttribute("AssemblyVersionInfo", "1.0.2")] +internal static class Assembly { + /// + /// The simple name of the assembly. + /// + public const string NAME = "DemoAttr"; + + + /// + /// The major component of the version number, thats usually the first number. + /// + public const string VERSION_MAJOR = "1"; + + /// + /// The minor component of the version number, thats usually the second number. + /// + public const string VERSION_MINOR = "0"; + + /// + /// The build component of the version number, thats usually the third number. + /// + public const string VERSION_BUILD = "0"; + + /// + /// The revision component of the version number, thats usually the fourth number. + /// + public const string VERSION_REVISION = "0"; + + + /// + /// The full version number: + /// {Major}.{Minor}.{Build}.{Revision} + /// + public const string VERSION = "1.0.0.0"; + + /// + /// Version number with only major and minor: + /// {Major}.{Minor} + /// + public const string VERSION_MAJOR_MINOR = "1.0"; + + /// + /// Version number with only major, minor and build: + /// {Major}.{Minor}.{Build} + /// + public const string VERSION_MAJOR_MINOR_BUILD = "1.0.0"; +} + +``` + + + + + + + +```csharp showLineNumbers +// + +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 + { + + } +} +``` + + + + + + + +```csharp showLineNumbers +// + +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; + } + } +} +``` + + + + + + + +```csharp showLineNumbers +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); +} +``` + + + + + + +## Useful + +### Download Example (.NET C#) + +:::tip + +[Download Example project AssemblyVersionInfo ](/sources/AssemblyVersionInfo.zip) + +::: + + +### Share AssemblyVersionInfo + + + +https://ignatandrei.github.io/RSCG_Examples/v2/docs/AssemblyVersionInfo + +### In the same category (EnhancementProject) - 19 other generators + + +#### [AutoInvoke.Generator](/docs/AutoInvoke.Generator) + + +#### [AutoSpectre](/docs/AutoSpectre) + + +#### [BuildInfo](/docs/BuildInfo) + + +#### [CommandLine](/docs/CommandLine) + + +#### [Credfeto.Version.Information.Generator](/docs/Credfeto.Version.Information.Generator) + + +#### [Larcanum.GitInfo](/docs/Larcanum.GitInfo) + + +#### [LinqGen.Generator](/docs/LinqGen.Generator) + + +#### [Pekspro.BuildInformationGenerator](/docs/Pekspro.BuildInformationGenerator) + + +#### [PlantUmlClassDiagramGenerator](/docs/PlantUmlClassDiagramGenerator) + + +#### [RSCG_AMS](/docs/RSCG_AMS) + + +#### [RSCG_ExportDiagram](/docs/RSCG_ExportDiagram) + + +#### [RSCG_FunctionsWithDI](/docs/RSCG_FunctionsWithDI) + + +#### [RSCG_NameGenerator](/docs/RSCG_NameGenerator) + + +#### [RSCG_TimeBombComment](/docs/RSCG_TimeBombComment) + + +#### [RSCG_Wait](/docs/RSCG_Wait) + + +#### [ShadowWriterProjectInfo](/docs/ShadowWriterProjectInfo) + + +#### [ThisAssembly](/docs/ThisAssembly) + + +#### [ThisAssembly.Constants](/docs/ThisAssembly.Constants) + + +#### [ThisAssembly.Metadata](/docs/ThisAssembly.Metadata) + diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/ShadowWriterBuilder.md b/v2/rscg_examples_site/docs/RSCG-Examples/ShadowWriterBuilder.md index f5b02bfd9..2866a01f6 100644 --- a/v2/rscg_examples_site/docs/RSCG-Examples/ShadowWriterBuilder.md +++ b/v2/rscg_examples_site/docs/RSCG-Examples/ShadowWriterBuilder.md @@ -331,7 +331,7 @@ public partial record Person https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterBuilder -### In the same category (Builder) - 7 other generators +### In the same category (Builder) - 6 other generators #### [Architect.DomainModeling](/docs/Architect.DomainModeling) @@ -349,8 +349,5 @@ https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterBuilder #### [Hsu.Sg.FluentMember](/docs/Hsu.Sg.FluentMember) -#### [ShadowWriterProjectInfo](/docs/ShadowWriterProjectInfo) - - #### [StepwiseBuilderGenerator](/docs/StepwiseBuilderGenerator) diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/ShadowWriterProjectInfo.md b/v2/rscg_examples_site/docs/RSCG-Examples/ShadowWriterProjectInfo.md index 1fd94e34b..1df72cbca 100644 --- a/v2/rscg_examples_site/docs/RSCG-Examples/ShadowWriterProjectInfo.md +++ b/v2/rscg_examples_site/docs/RSCG-Examples/ShadowWriterProjectInfo.md @@ -336,26 +336,62 @@ internal static class TheProject https://ignatandrei.github.io/RSCG_Examples/v2/docs/ShadowWriterProjectInfo -### In the same category (Builder) - 7 other generators +### In the same category (EnhancementProject) - 19 other generators -#### [Architect.DomainModeling](/docs/Architect.DomainModeling) +#### [AssemblyVersionInfo](/docs/AssemblyVersionInfo) -#### [BuilderGenerator](/docs/BuilderGenerator) +#### [AutoInvoke.Generator](/docs/AutoInvoke.Generator) -#### [DimonSmart.BuilderGenerator](/docs/DimonSmart.BuilderGenerator) +#### [AutoSpectre](/docs/AutoSpectre) -#### [Fluentify](/docs/Fluentify) +#### [BuildInfo](/docs/BuildInfo) -#### [Hsu.Sg.FluentMember](/docs/Hsu.Sg.FluentMember) +#### [CommandLine](/docs/CommandLine) -#### [ShadowWriterBuilder](/docs/ShadowWriterBuilder) +#### [Credfeto.Version.Information.Generator](/docs/Credfeto.Version.Information.Generator) -#### [StepwiseBuilderGenerator](/docs/StepwiseBuilderGenerator) +#### [Larcanum.GitInfo](/docs/Larcanum.GitInfo) + + +#### [LinqGen.Generator](/docs/LinqGen.Generator) + + +#### [Pekspro.BuildInformationGenerator](/docs/Pekspro.BuildInformationGenerator) + + +#### [PlantUmlClassDiagramGenerator](/docs/PlantUmlClassDiagramGenerator) + + +#### [RSCG_AMS](/docs/RSCG_AMS) + + +#### [RSCG_ExportDiagram](/docs/RSCG_ExportDiagram) + + +#### [RSCG_FunctionsWithDI](/docs/RSCG_FunctionsWithDI) + + +#### [RSCG_NameGenerator](/docs/RSCG_NameGenerator) + + +#### [RSCG_TimeBombComment](/docs/RSCG_TimeBombComment) + + +#### [RSCG_Wait](/docs/RSCG_Wait) + + +#### [ThisAssembly](/docs/ThisAssembly) + + +#### [ThisAssembly.Constants](/docs/ThisAssembly.Constants) + + +#### [ThisAssembly.Metadata](/docs/ThisAssembly.Metadata) diff --git a/v2/rscg_examples_site/docs/RSCG-Examples/index.md b/v2/rscg_examples_site/docs/RSCG-Examples/index.md index aef5fa52e..3265b0fd0 100644 --- a/v2/rscg_examples_site/docs/RSCG-Examples/index.md +++ b/v2/rscg_examples_site/docs/RSCG-Examples/index.md @@ -1,7 +1,7 @@ --- sidebar_position: 30 -title: 209 RSCG list by category -description: 209 RSCG list by category +title: 210 RSCG list by category +description: 210 RSCG list by category slug: /rscg-examples --- @@ -145,7 +145,7 @@ import DocCardList from '@theme/DocCardList'; ## Builder
- Expand Builder =>examples:8 + Expand Builder =>examples:7 @@ -181,11 +181,6 @@ import DocCardList from '@theme/DocCardList'; [ShadowWriterBuilder](/docs/ShadowWriterBuilder) - - - -[ShadowWriterProjectInfo](/docs/ShadowWriterProjectInfo) -
@@ -555,7 +550,7 @@ import DocCardList from '@theme/DocCardList'; ## EnhancementProject
- Expand EnhancementProject =>examples:18 + Expand EnhancementProject =>examples:20 @@ -646,6 +641,16 @@ import DocCardList from '@theme/DocCardList'; [Larcanum.GitInfo](/docs/Larcanum.GitInfo) + + + +[ShadowWriterProjectInfo](/docs/ShadowWriterProjectInfo) + + + + +[AssemblyVersionInfo](/docs/AssemblyVersionInfo) +
@@ -1355,8 +1360,6 @@ flowchart LR; Builder--> ShadowWriterBuilder((ShadowWriterBuilder)) - Builder--> ShadowWriterProjectInfo((ShadowWriterProjectInfo)) - Clone--> CopyTo((CopyTo)) Clone--> Dolly((Dolly)) @@ -1513,6 +1516,10 @@ flowchart LR; EnhancementProject--> Larcanum.GitInfo((Larcanum.GitInfo)) + EnhancementProject--> ShadowWriterProjectInfo((ShadowWriterProjectInfo)) + + EnhancementProject--> AssemblyVersionInfo((AssemblyVersionInfo)) + Enum--> NetEscapades.EnumGenerators((NetEscapades.EnumGenerators)) Enum--> EnumClass((EnumClass)) diff --git a/v2/rscg_examples_site/docs/about.md b/v2/rscg_examples_site/docs/about.md index 87330babe..92746d9a5 100644 --- a/v2/rscg_examples_site/docs/about.md +++ b/v2/rscg_examples_site/docs/about.md @@ -6,7 +6,7 @@ title: About ## Content You will find here code examples -of 209 Roslyn Source Code Generator (RSCG) +of 210 Roslyn Source Code Generator (RSCG) that can be useful for you. That means, you will write more elegant and concise code - even if the generators code is not always nice to look. ## Are those examples ready for production? diff --git a/v2/rscg_examples_site/docs/indexRSCG.md b/v2/rscg_examples_site/docs/indexRSCG.md index cffaf4580..0dc5cfe93 100644 --- a/v2/rscg_examples_site/docs/indexRSCG.md +++ b/v2/rscg_examples_site/docs/indexRSCG.md @@ -10,9 +10,9 @@ import useBaseUrl from '@docusaurus/useBaseUrl';