Skip to main content

Podimo.ConstEmbed by Podimo

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: Podimo.ConstEmbed

A source generator that turns additional files into file constants in a generated namespace. This is an alternative approach to embedding files in C# source manually, or loading them manually as embedded resources via reflection. With ConstEmbed, you will never have to see a runtime error because you mistyped the name, as the constants are evaluated at compile-time.

Author: Podimo

NuGet: https://www.nuget.org/packages/Podimo.ConstEmbed/

You can find more details at https://github.com/podimo/Podimo.ConstEmbed

Source : https://github.com/podimo/Podimo.ConstEmbed

Original Readme

note

Podimo.ConstEmbed

This project is a Source Generator which generates constant strings from files at compile-time.

Using

We use project files to control the generation of constants. You can see how these are used in Podimo.ExampleConsoleApp.

License

See LICENSE-APACHE, LICENSE-MIT.

About

note

File content transformed to constants

How to use

Example ( source csproj, source files )

This is the CSharp Project that references Podimo.ConstEmbed

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

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

<ItemGroup>
<PackageReference Include="Podimo.ConstEmbed" Version="1.0.2" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>


<PropertyGroup>
<!-- The namespace under which we generate the constants. -->
<ConstEmbedNamespace>MyAppNamespace</ConstEmbedNamespace>
<!-- The visibility of the classes in which the constants are declared. -->
<ConstEmbedVisibility>public</ConstEmbedVisibility>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="sql/*.sql" ConstEmbed="SQL" />
</ItemGroup>
<ItemGroup>
<None Remove="sql\createDB.sql" />
</ItemGroup>


</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

namespace MyAppNamespace
{
public static partial class SQL
{
public const string createDB = @"create database Andrei;
GO;
use Andrei;
GO;
";
}
}

Usefull

Download Example (.NET C# )

Share Podimo.ConstEmbed

https://ignatandrei.github.io/RSCG_Examples/v2/docs/Podimo.ConstEmbed

In the same category (FilesToCode) - 13 other generators

Chorn.EmbeddedResourceAccessGenerator

corecraft

Datacute.EmbeddedResourcePropertyGenerator

DotnetYang

EmbedResourceCSharp

LingoGen

NotNotAppSettings

ResXGenerator

RSCG_JSON2Class

RSCG_Utils

ThisAssembly_Resources

ThisAssembly.Strings

Weave