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

Useful

Download Example (.NET C#)

Share Podimo.ConstEmbed

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

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