RSCG_Utils by Ignat Andrei
Nuget / site data
Details
Info
Name: RSCG_Utils
Additional files as strings
Author: Ignat Andrei
NuGet: https://www.nuget.org/packages/rscgutils
You can find more details at https://learn.microsoft.com/en-us/dotnet/standard/serialization/system-text-json/source-generation
Original Readme
RSCG_Utils
Roslyn Source Code Generators Utils
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
Add files as C# consts
How to use
Example ( source csproj, source files )
- CSharp Project
- Program.cs
- data.gen.txt
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>
This is the use of RSCG_Utils in Program.cs
Console.WriteLine("Hello, World!");
string dataFromFile = MyAdditionalFiles.data_gen_txt;
Console.Write(dataFromFile);
This is the use of RSCG_Utils in data.gen.txt
This is a data
That you will retrieve
as C# const
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- MyAdditionalFiles.data.gen.txt.cs
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