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

Usefull

Download Example (.NET C# )

Share RSCG_Utils

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

In the same category (FilesToCode) - 10 other generators

Chorn.EmbeddedResourceAccessGenerator

corecraft

EmbedResourceCSharp

LingoGen

NotNotAppSettings

Podimo.ConstEmbed

ResXGenerator

RSCG_JSON2Class

ThisAssembly_Resources

Weave