-
-
Notifications
You must be signed in to change notification settings - Fork 6
start demo #395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
start demo #395
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Just later | ||
|
|
||
| ## Latest Update : 2025-08-07 => 07 August 2025 | ||
| ## Latest Update : 2025-08-08 => 08 August 2025 | ||
|
|
||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
|
|
||
| <h1>RSCG nr 220 : NFH.FileEmbed</h1> | ||
|
|
||
| <h2>Info</h2> | ||
| Nuget : <a href="https://www.nuget.org/packages/NFH.FileEmbed/" target="_blank">https://www.nuget.org/packages/NFH.FileEmbed/</a> | ||
|
|
||
| <p>You can find more details at : <a href="https://github.com/SirCxyrtyx/FileEmbed" target="_blank"> https://github.com/SirCxyrtyx/FileEmbed</a></p> | ||
|
|
||
| <p>Author :Natalie Howes</p> | ||
|
|
||
| <p>Source: <a href="https://github.com/SirCxyrtyx/FileEmbed" target="_blank">https://github.com/SirCxyrtyx/FileEmbed</a> </p> | ||
|
ignatandrei marked this conversation as resolved.
|
||
|
|
||
| <h2>About</h2> | ||
|
|
||
| Generating embedded files | ||
|
|
||
| <h2> | ||
| How to use | ||
| </h2> | ||
| <h3> | ||
| Add reference to the <a href="https://www.nuget.org/packages/NFH.FileEmbed/" target="_blank">NFH.FileEmbed</a> in the csproj | ||
| </h3> | ||
| <img src="images/NFH.FileEmbed/EmbedDemo.csproj.png" width="580" height="580" /> | ||
|
|
||
| <h3>This was for me the <b>starting</b> code</h3> | ||
|
|
||
| <br /> | ||
| I have <b>coded</b> the file Program.cs | ||
| <br /> | ||
| <img src="images/NFH.FileEmbed/csFiles/Program.cs.png" width="580" height="580" /> | ||
| <hr /> | ||
|
|
||
| <br /> | ||
| I have <b>coded</b> the file TestData.cs | ||
| <br /> | ||
| <img src="images/NFH.FileEmbed/csFiles/TestData.cs.png" width="580" height="580" /> | ||
| <hr /> | ||
|
|
||
| <br /> | ||
| I have <b>coded</b> the file Countries.txt | ||
| <br /> | ||
| <img src="images/NFH.FileEmbed/csFiles/Countries.txt.png" width="580" height="580" /> | ||
| <hr /> | ||
| <h3>And here are the <i>generated</i> files</h3> | ||
|
|
||
| <br /> | ||
| The file <i>generated</i> is EMBEDDED__Countries.txt.g.cs | ||
| <br /> | ||
| <img src="images/NFH.FileEmbed/generated/EMBEDDED__Countries.txt.g.cs.png" width="580" height="580" /> | ||
|
|
||
| <br /> | ||
| The file <i>generated</i> is FileEmbedAttribute.g.cs | ||
| <br /> | ||
| <img src="images/NFH.FileEmbed/generated/FileEmbedAttribute.g.cs.png" width="580" height="580" /> | ||
|
|
||
| <p> | ||
| You can download the code and this page as pdf from | ||
| <a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/NFH.FileEmbed'> | ||
| https://ignatandrei.github.io/RSCG_Examples/v2/docs/NFH.FileEmbed | ||
| </a> | ||
| </p> | ||
|
|
||
|
|
||
| <p> | ||
| You can see the whole list at | ||
| <a target="_blank" href='https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG'> | ||
| https://ignatandrei.github.io/RSCG_Examples/v2/docs/List-of-RSCG | ||
| </a> | ||
| </p> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "generator":{ | ||
| "name":"NFH.FileEmbed", | ||
| "nuget":[ | ||
| "https://www.nuget.org/packages/NFH.FileEmbed/" | ||
| ], | ||
| "link":"https://github.com/SirCxyrtyx/FileEmbed", | ||
| "author":"Natalie Howes", | ||
| "source":"https://github.com/SirCxyrtyx/FileEmbed" | ||
| }, | ||
| "data":{ | ||
| "goodFor":["Generating embedded files "], | ||
| "csprojDemo":"EmbedDemo.csproj", | ||
| "csFiles":["Program.cs","TestData.cs","Countries.txt"], | ||
| "excludeDirectoryGenerated":[""], | ||
| "includeAdditionalFiles":[""] | ||
| }, | ||
| "links":{ | ||
| "blog":"", | ||
| "video":"" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| A source generator for embedding resource files directly into your assembly. Access them as a ReadOnlySpan<byte>, with no allocations or reflection needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # C# FileEmbed | ||
|
|
||
| A source generator for embedding resource files directly into your assembly. Access them as a `ReadOnlySpan<byte>`, with no allocations or reflection needed. | ||
|
|
||
| Add the package to your application using | ||
|
|
||
| ``` | ||
| dotnet add package NFH.FileEmbed | ||
| ``` | ||
|
|
||
| You will probably wish to add `PrivateAssets="all"` to the `PackageReference` for this package in your csproj, to prevent this becoming a dependency (as it's only needed at compile time). | ||
|
|
||
| ## Example Usage | ||
| ```csharp | ||
| //attribute is in this namespace | ||
| using FileEmbed; | ||
|
|
||
| namespace EmbedExample; | ||
|
|
||
| //partial methods must be in partial types | ||
| public static partial class Program | ||
| { | ||
| //Place the attribute on a static partial method that returns a ReadOnlySpan<byte> | ||
| [FileEmbed(@"Capture.PNG")] | ||
| public static partial ReadOnlySpan<byte> Bytes(); | ||
|
|
||
|
|
||
| //works in any type that can contain a static method | ||
| private partial record struct MyStruct | ||
| { | ||
| //Path is relative to your project directory (specifically, the ProjectDir MSBuild property) | ||
| [FileEmbed(@"Resources\Capture.7z")] | ||
| internal static partial ReadOnlySpan<byte> StructBytes(); | ||
| } | ||
|
|
||
| public partial interface IExampleInterface | ||
| { | ||
| //two optional arguments, Offset and Length, allow you to embed a slice of the file | ||
| [FileEmbed(@"Resources\Capture.7z", 4, 8)] | ||
| internal static partial ReadOnlySpan<byte> InterfaceBytes(); | ||
| } | ||
|
|
||
| public static void Main() | ||
| { | ||
| Console.WriteLine($"{Bytes().Length} bytes"); | ||
| Console.WriteLine($"{MyStruct.StructBytes().Length} bytes"); | ||
| Console.WriteLine($"{IExampleInterface.InterfaceBytes().Length} bytes"); | ||
| } | ||
| } | ||
| ``` | ||
| Autogenerated code for `IExampleInterface.InterfaceBytes`: | ||
| ```csharp | ||
| namespace EmbedExample | ||
| { | ||
| partial class Program | ||
| { | ||
| partial interface IExampleInterface | ||
| { | ||
| [global::System.CodeDom.Compiler.GeneratedCodeAttribute("FileEmbed", "0.1.0.0")] | ||
| internal static partial global::System.ReadOnlySpan<byte> InterfaceBytes() => new byte[] { 39,28,0,4,115,228,9,158, }; | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Limitations | ||
| This doesn't work so well for input files larger than 1MB unfortunately. The source generator itself can handle large files just fine, but, in my experience, Visual Studio chokes on the generated output, using huge amounts of memory after the files are generated. I have not yet investigated why. To protect users of this source generator from accidently locking up VS, it imposes a 1MB limit on input files. This can be overriden if you wish to try using this with larger files. To do so, put this in your csproj file: | ||
| ```xml | ||
| <!-- To set FileEmbed_MaxEmbedSize, you must first make it visible to the compiler --> | ||
| <ItemGroup> | ||
| <CompilerVisibleProperty Include="FileEmbed_MaxEmbedSize" /> | ||
| </ItemGroup> | ||
| <PropertyGroup> | ||
| <FileEmbed_MaxEmbedSize>SIZE_IN_BYTES_GOES_HERE</FileEmbed_MaxEmbedSize> | ||
| </PropertyGroup> | ||
| ``` |
48 changes: 48 additions & 0 deletions
48
v2/rscg_examples/NFH.FileEmbed/src/.tours/NFH.FileEmbed.tour
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
|
|
||
| { | ||
| "$schema": "https://aka.ms/codetour-schema", | ||
| "title": "NFH.FileEmbed", | ||
| "steps": | ||
| [ | ||
| { | ||
| "file": "EmbedDemo/EmbedDemo.csproj", | ||
| "description": "First, we add Nuget [NFH.FileEmbed](https://www.nuget.org/packages/NFH.FileEmbed/) in csproj ", | ||
| "pattern": "NFH.FileEmbed" | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "EmbedDemo/TestData/Countries.txt", | ||
| "description": "File Countries.txt ", | ||
| "pattern": "this is the code" | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "EmbedDemo/TestData.cs", | ||
| "description": "File TestData.cs ", | ||
| "pattern": "this is the code" | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "EmbedDemo/Program.cs", | ||
| "description": "File Program.cs \r\n>> dotnet run --project EmbedDemo/EmbedDemo.csproj ", | ||
| "pattern": "this is the code" | ||
| } | ||
|
|
||
|
|
||
| ,{ | ||
| "file": "EmbedDemo/obj/GX/FileEmbed/FileEmbed.FileEmbedGenerator/FileEmbedAttribute.g.cs", | ||
| "description": "Generated File 2 from 2 : FileEmbedAttribute.g.cs ", | ||
| "line": 1 | ||
| } | ||
|
|
||
| ,{ | ||
| "file": "EmbedDemo/obj/GX/FileEmbed/FileEmbed.FileEmbedGenerator/EMBEDDED__Countries.txt.g.cs", | ||
| "description": "Generated File 1 from 2 : EMBEDDED__Countries.txt.g.cs ", | ||
| "line": 1 | ||
| } | ||
|
|
||
| ], | ||
|
|
||
| "ref": "main" | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.12.35424.110 d17.12 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbedDemo", "EmbedDemo\EmbedDemo.csproj", "{71D83A8E-C979-4D40-91BD-4A6EB7771B4F}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {71D83A8E-C979-4D40-91BD-4A6EB7771B4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {71D83A8E-C979-4D40-91BD-4A6EB7771B4F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {71D83A8E-C979-4D40-91BD-4A6EB7771B4F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {71D83A8E-C979-4D40-91BD-4A6EB7771B4F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| EndGlobal |
33 changes: 33 additions & 0 deletions
33
v2/rscg_examples/NFH.FileEmbed/src/EmbedDemo/EmbedDemo.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
|
|
||
| <ItemGroup> | ||
| <EmbeddedResource Include="TestData\Countries.txt" /> | ||
| </ItemGroup> | ||
|
|
||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="NFH.FileEmbed" Version="0.1.0-beta" /> | ||
| </ItemGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <AdditionalFileItemNames>$(AdditionalFileItemNames);EmbeddedResource</AdditionalFileItemNames> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles> | ||
| <CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath> | ||
| </PropertyGroup> | ||
| <!--<ItemGroup> | ||
| <CompilerVisibleProperty Include="FileEmbed_MaxEmbedSize" /> | ||
| </ItemGroup> | ||
| <PropertyGroup> | ||
| <FileEmbed_MaxEmbedSize>SIZE_IN_BYTES_GOES_HERE</FileEmbed_MaxEmbedSize> | ||
| </PropertyGroup>--> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // See https://aka.ms/new-console-template for more information | ||
| using EmbedDemo; | ||
| using System.Text; | ||
|
|
||
| Console.WriteLine("Hello, World!"); | ||
|
|
||
| var data= TestData.Countries(); | ||
|
|
||
| Console.WriteLine(Encoding.UTF8.GetString(data) ); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.