Skip to main content

RSCG_Utils by Ignat Andrei

NuGet / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

Original Readme

note

RSCG_Utils

Roslyn Source Code Generators Utils

pack to nuget

pack to nuget

Usage

Additional Files

Allow you to see additional files directly as C# const. For this, please add some .gen. files to the project.

In your csproj

<ItemGroup>
<PackageReference Include="rscgutils" Version="2023.502.835" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="Second.gen.txt" />
<AdditionalFiles Include="first.gen.txt" />
<AdditionalFiles Include="test\Afirst.gen.txt" />
<AdditionalFiles Include="sql/**/*" />
</ItemGroup>

In the code

//see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string
string x= MyAdditionalFiles.Second_gen_txt;

To debug, you can add into the .csproj

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

More details at http://msprogrammer.serviciipeweb.ro/2023/05/08/file-to-csharp-const/

More Roslyn Source Code Generators

You can find more RSCG with examples at Roslyn Source Code Generators

About

note

Add files as C# consts

How to use

Example (source csproj, source files)

This is the CSharp Project that references RSCG_Utils

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

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

<ItemGroup>
<PackageReference Include="rscgutils" Version="2023.514.835" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="data.gen.txt" />
</ItemGroup>

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


</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX


public static partial class MyAdditionalFiles
{
//https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/tokens/raw-string
public const string data_gen_txt = """"""""""
This is a data
That you will retrieve
as C# const
"""""""""";
}

Useful

Download Example (.NET C#)

Share RSCG_Utils

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

aaa

Category "FilesToCode" has the following generators:

1 Chorn.EmbeddedResourceAccessGenerator

2 corecraft

3 Datacute.EmbeddedResourcePropertyGenerator

4 DotnetYang

5 EmbedResourceCSharp

6 LingoGen

7 NFH.FileEmbed

8 NotNotAppSettings

9 Podimo.ConstEmbed

10 ResXGenerator

11 RSCG_JSON2Class

12 RSCG_Utils

13 Strings.ResourceGenerator

14 ThisAssembly_Resources

15 ThisAssembly.Strings

16 Weave

See category

FilesToCode