{"id":116937,"date":"2024-06-03T08:48:05","date_gmt":"2024-06-03T06:48:05","guid":{"rendered":"https:\/\/code-maze.com\/?p=116937"},"modified":"2024-06-03T08:48:05","modified_gmt":"2024-06-03T06:48:05","slug":"dotnet-embedded-resources","status":"publish","type":"post","link":"https:\/\/code-maze.com\/dotnet-embedded-resources\/","title":{"rendered":"Embedded Resources in .NET"},"content":{"rendered":"<p>We&#8217;ve covered resources in a couple of our previous articles.<\/p>\n<p>In <a href=\"https:\/\/code-maze.com\/aspnetcore-localization\/\" target=\"_blank\" rel=\"noopener\">Localization in ASP.NET Core<\/a>, we delved into .NET localization, touching upon resources since XML files utilized for localization fall under .NET resources.<\/p>\n<p>We also discussed resources in our article, <a href=\"https:\/\/code-maze.com\/csharp-string-resource-file\/\" target=\"_blank\" rel=\"noopener\">How to Read a String From a .resx (Resource) File in C#<\/a>, where we explored how developers can extract strings from RESX files, a type of resource.<\/p>\n<p>However, in this article, we&#8217;ll <strong>focus on embedded resources.<\/strong><\/p>\n<div style=\"padding: 20px; border-left: 5px #dc2323 solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">To download the source code for this article, you can visit our <a href=\"https:\/\/github.com\/CodeMazeBlog\/CodeMazeGuides\/tree\/main\/csharp-intermediate-topics\/Embedded_Resources_in_NET\" target=\"_blank\" rel=\"nofollow noopener\">GitHub repository<\/a>.<\/div>\n<p>Let&#8217;s dive in.<\/p>\n<h2>What Are Embedded Resources?<\/h2>\n<p>In addition to data in our program, we often <strong>need outside resources<\/strong>. Sometimes, these resources are provided by the end-user, but there are also situations where we have all the resources at the time of development. We need an <strong>option to ship them with our program somehow.<\/strong><\/p>\n<p>Rather than merely attaching files to our program, it&#8217;s advantageous to <strong>include them within its assembly<\/strong>. This ensures they&#8217;re always readily available and eliminates the risk of overlooking them.<\/p>\n<p><strong>The encapsulation of resources within the program itself constitutes embedded resources.<\/strong><\/p>\n<h2>Test Project With Embedded Resources<\/h2>\n<p>We&#8217;ll walk through the creation of a sample command-line application in several steps:<\/p>\n<ul>\n<li>Start by crafting an empty command-line application.<\/li>\n<li>Utilize Visual Studio to incorporate embedded resources.<\/li>\n<li>Manually include embedded resources.<\/li>\n<li>Learn how to retrieve the list of embedded resources within our application.<\/li>\n<li>Construct a satellite assembly containing embedded resources.<\/li>\n<li>Finally, read and use embedded resources in our program.<\/li>\n<\/ul>\n<p>Let&#8217;s start by preparing a quick test program, a basic command-line app. We can either make a new command line app right from Visual Studio or utilize the dotnet command:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">dotnet new console -n Embedded_Resources_in_NET<\/code><\/p>\n<p>Once our command-line project is set up, we can promptly <strong>incorporate embedded resources into our app.<\/strong><\/p>\n<p>We&#8217;ll generate sample text (<code>.txt<\/code>) and PDF (<code>.pdf<\/code>) files for testing. We can grab files from our hard drive or extract them from the Code Maze sample application.<\/p>\n<h3>Creating Sample Folders and Files<\/h3>\n<p>Let&#8217;s set up the <strong>folders and files for our resources<\/strong>. First, we&#8217;ll create two subfolders within our project directory: <code>Resources<\/code> and <code>Files<\/code>. While the specific names aren&#8217;t crucial, <strong><code>Resources<\/code> is commonly used.<\/strong><\/p>\n<p>Here&#8217;s how we can do it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">md Resources\r\ncd Resources\r\nmd Pdf\r\ncd ..\r\nmd Files<\/pre>\n<p>So, we have created a folder structure where the <code>Resources<\/code> and <code>Files<\/code> folders are on the same level, and the <code>Pdf<\/code> folder is under <code>Resources<\/code>.<\/p>\n<p>Next, copy some text files from the disk into the <code>Resources<\/code> and <code>Files<\/code> folders, naming it <code>text-file.txt<\/code>. Similarly, let&#8217;s duplicate a sample PDF file, naming it <code>pdf-file.pdf<\/code>, and place it within the <code>Pdf<\/code> subfolder under <code>Resources<\/code>.<\/p>\n<p>After completing these steps, our folder structure will look like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">|\r\n|-- Resources\r\n    |-- text-file.txt\r\n    |-- Pdf\r\n        |-- pdf-file.pdf\r\n|-- Files\r\n    |-- text-file.txt\r\n<\/pre>\n<p>The actual content of the files is not significant for our purposes.<\/p>\n<h3>Adding Embedded Resources Using Visual Studio<\/h3>\n<p>Now that we&#8217;ve included all the folders and files in our .NET\/C# project, <strong>they should be visible in the Solution Explorer.<\/strong><\/p>\n<p>To <strong>designate these files as embedded resources<\/strong>, follow these steps:<\/p>\n<ol>\n<li>Right-click each file.<\/li>\n<li>From the context menu, choose &#8216;Properties.&#8217;<\/li>\n<li>In the Properties window, select &#8216;Build Action.&#8217;<\/li>\n<li>Choose &#8216;Embedded resource&#8217; from the dropdown menu.<\/li>\n<\/ol>\n<p><a href=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/EmbeddedResource.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-116939\" src=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/EmbeddedResource.png\" alt=\"embedded resource properties window\" width=\"364\" height=\"188\" srcset=\"https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/EmbeddedResource.png 364w, https:\/\/code-maze.com\/wp-content\/uploads\/2024\/05\/EmbeddedResource-300x155.png 300w\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" \/><\/a><\/p>\n<h2>Reading the List of Embedded Resources in Our Application<\/h2>\n<p>Now that we&#8217;ve embedded three resources in our application, let&#8217;s write some C# code <strong>to retrieve a list of these files<\/strong>.<\/p>\n<p>First, we&#8217;ll need a handle to the <strong>assembly containing the embedded resources<\/strong>. Since we&#8217;ve added all resources to our main assembly, we can easily reference it:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static Assembly ThisAssembly\r\n    =&gt; typeof(SampleResourceReader).Assembly;<\/pre>\n<p>Once we have the assembly handle, we can list all the resources within it using the <code>GetManifestResourceNames()<\/code> method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static void ListResourcesInAssembly(Assembly? assembly)\r\n{\r\n    if (assembly is null) \r\n        return;\r\n\r\n    var resources = assembly.GetManifestResourceNames();\r\n    if (resources.Length == 0)\r\n        return;\r\n\r\n    Console.WriteLine($\"Resources in {assembly.FullName}\");\r\n    foreach (var resource in resources)\r\n    {\r\n        Console.WriteLine(resource);\r\n    }\r\n\r\n    Console.WriteLine();\r\n}<\/pre>\n<p>This is a general function, so we first check if we have a valid assembly handle. Then, we call the <code>GetManifestResourceNames()<\/code> method to get the list of all the embedded resources within it. If there are no embedded files, we exit the function. Otherwise, <strong>we display the names of the resources in the Console.<\/strong><\/p>\n<h3>The Names of the Embedded Files<\/h3>\n<p>By running the current code, we will get the list of files:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Resources in Embedded_Resources_in_NET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\r\nEmbedded_Resources_in_NET.Files.text-file.txt\r\nEmbedded_Resources_in_NET.Resources.text-file.txt\r\nEmbedded_Resources_in_NET.Resources.Pdf.pdf-file.pdf<\/pre>\n<p><strong>Dots separate each resource name.<\/strong> If we take the example of the PDF file, &#8216;<code>Embedded_Resources_in_NET.Resources.Pdf.pdf-file.pdf<\/code>&#8216;, and split it by dots (except the last one), we get:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Embedded_Resources_in_NET\r\nResources\r\nPdf\r\npdf-file.pdf<\/pre>\n<p>&#8216;<code>Embedded_Resources_in_NET<\/code>&#8216; is our <strong>assembly name<\/strong>, <code>Resources<\/code> and <code>Pdf<\/code> are the <strong>respective sub-folders<\/strong>, and <code>pdf-file.pdf<\/code> <strong>is the filename of the embedded resource<\/strong>. The dot (&#8216;.&#8217;) is a separator between the assembly name, the entire folder structure, and the name of the embedded resource itself.<\/p>\n<p>This structure allows us to have two identical files named <code>text-file.txt<\/code> as embedded resources in our assembly <strong>without conflict<\/strong>. One resides in the <code>Files<\/code> sub-folder, hence its name is <code>Embedded_Resources_in_NET.Files.text-file.txt<\/code>, while the other is in the <code>Resources<\/code> sub-folder, making its name <code>Embedded_Resources_in_NET.Resources.text-file.txt<\/code>. <strong>Since the names are distinct, there&#8217;s no issue.<\/strong><\/p>\n<h3>Embedded Resources in the .csproj File<\/h3>\n<p>In the .csproj file, Visual Studio records the embedded file selection. Here&#8217;s the relevant portion of the XML:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\">&lt;ItemGroup&gt;\r\n    &lt;EmbeddedResource Include=\"Files\\text-file.txt\" \/&gt;\r\n    &lt;EmbeddedResource Include=\"Resources\\Pdf\\pdf-file.pdf\" \/&gt;\r\n    &lt;EmbeddedResource Include=\"Resources\\text-file.txt\" \/&gt;\r\n&lt;\/ItemGroup&gt;<\/pre>\n<p><strong>This XML fragment indicates which files are designated as embedded resources.<\/strong><\/p>\n<h3>Embedded Resources Outside Our Project<\/h3>\n<p>By <strong>modifying the .csproj file<\/strong>, we can <strong>embed files that aren&#8217;t within our project&#8217;s subfolders<\/strong>, a capability not directly available in Visual Studio. Editing the file allows us to include files from different locations, like so:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-highlight=\"5,6\">&lt;ItemGroup&gt;\r\n    &lt;EmbeddedResource Include=\"Files\\text-file.txt\" \/&gt;\r\n    &lt;EmbeddedResource Include=\"Resources\\Pdf\\pdf-file.pdf\" \/&gt;\r\n    &lt;EmbeddedResource Include=\"Resources\\text-file.txt\" \/&gt;\r\n    &lt;EmbeddedResource Include=\"..\\Embedded_Resources_in_NET.sln\" \/&gt;\r\n    &lt;EmbeddedResource Include=\"..\\..\\README.md\" \/&gt;\r\n&lt;\/ItemGroup&gt;<\/pre>\n<p>With this setup, we&#8217;re embedding our solution file, one folder up, and even a <code>README.md<\/code> file that is two folders up. Executing this code will yield:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-highlight=\"5,6\">Resources in Embedded_Resources_in_NET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\r\nEmbedded_Resources_in_NET.Files.text-file.txt\r\nEmbedded_Resources_in_NET.Resources.text-file.txt\r\nEmbedded_Resources_in_NET.Resources.Pdf.pdf-file.pdf\r\nEmbedded_Resources_in_NET.Embedded_Resources_in_NET.sln\r\nEmbedded_Resources_in_NET.README.md<\/pre>\n<p>Notice how all such resources are named <strong>as if they were in the same folder as our assembly.<\/strong><\/p>\n<p>However, this was just a test to explore the possibility. While feasible, embedding resources from outside our project is ill-advised. <strong>We should not embed resources outside our project, as we can\u2019t guarantee their availability at build time.<\/strong><\/p>\n<h2>Embedded Resources in a Satellite Assembly<\/h2>\n<p>Now that we&#8217;ve learned how to retrieve a list of embedded resources in our main assembly let&#8217;s attempt to list the embedded resources in a satellite assembly that we&#8217;ll create.<\/p>\n<p>For this experiment, let&#8217;s create a new project and embed a text file into that assembly:<\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">dotnet new classlib -o Embedded_Resources_in_NET_Satellite<\/code><\/p>\n<p>Next, open this new project in Visual Studio and <strong>embed a text file<\/strong>. Alternatively, we can edit the .csproj file:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\">&lt;ItemGroup&gt;\r\n    &lt;EmbeddedResource Include=\"Resources\\text-file.txt\" \/&gt;\r\n&lt;\/ItemGroup&gt;<\/pre>\n<p>This setup will <strong>embed the <code>text-file.txt<\/code> into our satellite assembly.<\/strong><\/p>\n<h3>Reading a List of Embedded Resources in a Satellite Assembly<\/h3>\n<p>We can apply the <strong>same approach to any assembly<\/strong>, including satellite assemblies.<\/p>\n<p>We already have the method <code>ListResourcesInAssembly()<\/code> for this purpose. All we need to do is specify the correct assembly:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static Assembly SatelliteAssembly =&gt;\r\n    Assembly.Load(\"Embedded_Resources_in_NET_Satellite\");<\/pre>\n<p>Then, we can call the method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static void ListResourcesInOurSatelliteAssembly()\r\n    =&gt; ListResourcesInAssembly(SatelliteAssembly);<\/pre>\n<p>Since our satellite assembly contains only one embedded resource, we&#8217;ll receive a list with just one element:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\">Resources in Embedded_Resources_in_NET_Satellite, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\r\nEmbedded_Resources_in_NET_Satellite.Resources.text-file.txt<\/pre>\n<p><strong>This demonstrates how we can read embedded resources from any assembly<\/strong>, providing flexibility in resource management.<\/p>\n<h3>Reading a List of Embedded Resources in All of the Assemblies of Our Project<\/h3>\n<p>To list all the embedded resources in all the assemblies comprising our solution, <strong>we can first obtain a list of all assemblies of the current application domain<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static Assembly[] AllAssembliesOfCurrentAppDomain\r\n    =&gt; AppDomain.CurrentDomain.GetAssemblies();<\/pre>\n<p>Then, <strong>we can iterate over this list<\/strong> and call the <code>ListResourcesInAssembly<\/code> method for each assembly:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">public static void ListResourcesInAllAssemblies() \r\n    =&gt; AllAssembliesOfCurrentAppDomain.ToList().ForEach(ListResourcesInAssembly);<\/pre>\n<p>This approach allows us to comprehensively gather information about embedded resources across all assemblies within our solution.<\/p>\n<h2>Reading the Content of an Embedded Resource<\/h2>\n<p>Indeed, understanding how to access the content of an embedded resource is crucial for utilizing them.<\/p>\n<p>Similar to retrieving a list of all embedded resources using the <code>GetManifestResourceNames()<\/code> method, <strong>we can obtain the content of a resource via the <code>GetManifestResourceStream()<\/code> method.<\/strong><\/p>\n<div style=\"padding: 20px; border-left: 5px gray solid; display: block; margin-bottom: 20px; box-shadow: 1px 1px 5px 0px lightgrey;\">We&#8217;ve covered <code>Streams<\/code> extensively on Code Maze, with articles such as <a href=\"https:\/\/code-maze.com\/csharp-basics-streamwriter-streamreader\/\" target=\"_blank\" rel=\"noopener\">StreamWriter and StreamReader Classes in C#<\/a>, <a href=\"https:\/\/code-maze.com\/csharp-memorystream\/\" target=\"_blank\" rel=\"noopener\">How to Use MemoryStream in C#<\/a>, <a href=\"https:\/\/code-maze.com\/using-streams-with-httpclient-to-improve-performance-and-memory-usage\/\" target=\"_blank\" rel=\"noopener\">Using Streams with HttpClient to Improve Performance and Memory Usage<\/a>, and more.<\/div>\n<p>Once we have a <code>Stream<\/code> object, we can perform <strong>various operations, including reading, transforming, displaying, saving to disk, transmitting over the network, and more.<\/strong> <code>Streams<\/code> provide a flexible and powerful means of handling data in C#.<\/p>\n<h3>Finding an Embedded Resource in Assemblies<\/h3>\n<p>To streamline the process of locating a specific embedded resource across all assemblies within our solution, we can implement a utility method:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static Stream? FindResource(Func&lt;string[]?, string?&gt; finder)\r\n{\r\n    foreach (var assembly in AllAssembliesOfCurrentAppDomain)\r\n    {\r\n        var resourceNames = assembly.GetManifestResourceNames();\r\n        var resourceName = finder(resourceNames);\r\n\r\n        if (resourceName is not null)\r\n        {\r\n            Console.WriteLine($\"Resource {resourceName} found in {assembly.FullName}\");\r\n            return assembly.GetManifestResourceStream(resourceName);\r\n        }\r\n    }\r\n\r\n    return null;\r\n}<\/pre>\n<p>Method iterates through each assembly and retrieves the list of embedded resources within that assembly using <code>GetManifestResourceNames()<\/code>, and then passes this list to an external <code>finder<\/code> method.<\/p>\n<p>If the <code>finder<\/code> method successfully locates the desired resource, we print a message indicating its discovery and return the corresponding <code>Stream<\/code> using <code>GetManifestResourceStream()<\/code>. If the resource is not found in any assembly, we return null.<\/p>\n<p><strong>This utility method simplifies locating and accessing specific embedded resources within our solution&#8217;s assemblies.<\/strong><\/p>\n<h3>Finding a Resource by Specifying the Whole Name<\/h3>\n<p>To find an embedded resource by its complete name, we can create a <strong>finder method that returns the name if it matches precisely:<\/strong><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">FindResource(names =&gt; names?.FirstOrDefault(rn =&gt; rn == resourceName));<\/code><\/p>\n<p>This method utilizes the <code>FirstOrDefault)=<\/code> LINQ function to find the first resource name that matches the provided <code>resourceName<\/code>.<\/p>\n<h3>Finding a Resource by Specifying Part of a Name<\/h3>\n<p>Similarly, to find a resource by specifying only part of its name, such as &#8216;pdf-file.pdf&#8217;, <strong>we can modify the finder method to check for name containment:<\/strong><\/p>\n<p><code class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">FindResource(names =&gt; names?.FirstOrDefault(rn =&gt; rn.Contains(partialResourceName)));<\/code><\/p>\n<p>Here, we use the <code>Contains<\/code> method to check if any resource name contains the specified <code>partialResourceName<\/code>. If a match is found, that resource name is returned.<\/p>\n<h2>Displaying the Content of an Embedded Resource<\/h2>\n<p>Once we have a <code>Stream<\/code> object representing our embedded resource, <strong>displaying its content on the screen is straightforward<\/strong>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static void DisplayResource(string resourceName, Stream resourceStream)\r\n{\r\n    using var reader = new StreamReader(resourceStream);\r\n    var resourceContent = reader.ReadToEnd();\r\n    Console.WriteLine($\"Resource {resourceName} content:\");\r\n    Console.WriteLine(resourceContent);\r\n}<\/pre>\n<p>Method utilizes a <code>StreamReader<\/code> to read the content of the resource stream. It then prints the resource name and its content to the console.<\/p>\n<h3>Showing the PDF File<\/h3>\n<p>To display the embedded PDF file, <strong>we first need to save its content to disk, then open the saved file using a PDF application<\/strong>. We can accomplish this with two methods:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\">private static string SaveResourceToAFile(string partialResourceName, Stream resourceStream)\r\n{\r\n    var tempFileName = Path.Combine(Path.GetTempPath(), partialResourceName);\r\n    using var fileStream = new FileStream(tempFileName, FileMode.Create, FileAccess.Write);\r\n    resourceStream.CopyTo(fileStream);\r\n    fileStream.Close();\r\n\r\n    return tempFileName;\r\n}\r\n\r\nprivate\u00a0static\u00a0void\u00a0ShowFile(string\u00a0fileName)\u00a0\r\n    =&gt; Process.Start(new ProcessStartInfo(fileName) { UseShellExecute = true });<\/pre>\n<p>The <code>SaveResourceToAFile()<\/code> method accepts the partial file name and the Stream representing the embedded resource. It creates a temporary file in the system&#8217;s temporary folder and writes the contents of the resource stream to that file. It then returns the name of the newly created file.<\/p>\n<p>The <code>ShowFile()<\/code> method starts a new process using the system&#8217;s default application for opening PDF files, passing the file name as an argument. This opens the PDF file using the default PDF viewer installed on the system.<\/p>\n<h2>Conclusion<\/h2>\n<p>In conclusion, embedding resources into .NET assemblies is straightforward. We can select them in Visual Studio or manually add them as XML tags in the .csproj file.<\/p>\n<p>Every embedded resource is named by concatenating the assembly name with the folder path and file name, separated by commas. For example, &#8216;Embedded_Resources_in_NET.Resources.Pdf.pdf-file.pdf&#8217;.<\/p>\n<p>Invoking the GetManifestResourceNames () method of the Assembly object retrieves the list of all embedded resources in an assembly. Similarly, the GetManifestResourceStream() method obtains the embedded resource stream.<\/p>\n<p>This simple yet powerful mechanism allows us to seamlessly integrate various resources, such as text files, images, and even binary files like PDFs, directly into our .NET assemblies, streamlining deployment and ensuring that all necessary resources are readily available to our applications.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve covered resources in a couple of our previous articles. In Localization in ASP.NET Core, we delved into .NET localization, touching upon resources since XML files utilized for localization fall under .NET resources. We also discussed resources in our article, How to Read a String From a .resx (Resource) File in C#, where we explored [&hellip;]<\/p>\n","protected":false},"author":53,"featured_media":62189,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[12],"tags":[2202,2201,2203,1212,2200],"class_list":["post-116937","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-csharp","tag-assembly","tag-embedded-resources","tag-embedding","tag-files","tag-resources","et-has-post-format-content","et_post_format-et-post-format-standard"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Embedded Resources in .NET<\/title>\n<meta name=\"description\" content=\"Learn how to effectively manage embedded resources in .NET assemblies. We discover creation, inclusion, and access techniques.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/code-maze.com\/dotnet-embedded-resources\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Embedded Resources in .NET\" \/>\n<meta property=\"og:description\" content=\"Learn how to effectively manage embedded resources in .NET assemblies. We discover creation, inclusion, and access techniques.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/code-maze.com\/dotnet-embedded-resources\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Maze\" \/>\n<meta property=\"article:published_time\" content=\"2024-06-03T06:48:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1100\" \/>\n\t<meta property=\"og:image:height\" content=\"620\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Matjaz Prtenjak\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:site\" content=\"@CodeMazeBlog\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Matjaz Prtenjak\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/\"},\"author\":{\"name\":\"Matjaz Prtenjak\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/fb52db5fd702889fb141605f63bff589\"},\"headline\":\"Embedded Resources in .NET\",\"datePublished\":\"2024-06-03T06:48:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/\"},\"wordCount\":1792,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"keywords\":[\"assembly\",\"embedded resources\",\"embedding\",\"files\",\"resources\"],\"articleSection\":[\"C#\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/code-maze.com\/dotnet-embedded-resources\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/\",\"url\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/\",\"name\":\"Embedded Resources in .NET\",\"isPartOf\":{\"@id\":\"https:\/\/code-maze.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"datePublished\":\"2024-06-03T06:48:05+00:00\",\"description\":\"Learn how to effectively manage embedded resources in .NET assemblies. We discover creation, inclusion, and access techniques.\",\"breadcrumb\":{\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/code-maze.com\/dotnet-embedded-resources\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/#primaryimage\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png\",\"width\":1100,\"height\":620,\"caption\":\"C# Development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/code-maze.com\/dotnet-embedded-resources\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/code-maze.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Embedded Resources in .NET\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/code-maze.com\/#website\",\"url\":\"https:\/\/code-maze.com\/\",\"name\":\"Code Maze\",\"description\":\"Learn. Code. Succeed.\",\"publisher\":{\"@id\":\"https:\/\/code-maze.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/code-maze.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/code-maze.com\/#organization\",\"name\":\"Code Maze\",\"url\":\"https:\/\/code-maze.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png\",\"width\":3511,\"height\":3510,\"caption\":\"Code Maze\"},\"image\":{\"@id\":\"https:\/\/code-maze.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/CodeMazeBlog\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/fb52db5fd702889fb141605f63bff589\",\"name\":\"Matjaz Prtenjak\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/code-maze.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/MatjazPrtenjak_400x400-150x150.jpg\",\"contentUrl\":\"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/MatjazPrtenjak_400x400-150x150.jpg\",\"caption\":\"Matjaz Prtenjak\"},\"description\":\"Matjaz is a seasoned professional with over 25 years of expertise in software development. He began his programming journey during the era when IBM dominated with mainframe computers, and personal computers were yet to be born. He possesses a rich background and has authored two books on C++ and VBA programming languages. Lately, he has dedicated himself to harnessing the power of .NET technology in his innovative projects.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/mprtenja\/\"],\"url\":\"https:\/\/code-maze.com\/author\/mprtenjak\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Embedded Resources in .NET","description":"Learn how to effectively manage embedded resources in .NET assemblies. We discover creation, inclusion, and access techniques.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/code-maze.com\/dotnet-embedded-resources\/","og_locale":"en_US","og_type":"article","og_title":"Embedded Resources in .NET","og_description":"Learn how to effectively manage embedded resources in .NET assemblies. We discover creation, inclusion, and access techniques.","og_url":"https:\/\/code-maze.com\/dotnet-embedded-resources\/","og_site_name":"Code Maze","article_published_time":"2024-06-03T06:48:05+00:00","og_image":[{"width":1100,"height":620,"url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","type":"image\/png"}],"author":"Matjaz Prtenjak","twitter_card":"summary_large_image","twitter_creator":"@CodeMazeBlog","twitter_site":"@CodeMazeBlog","twitter_misc":{"Written by":"Matjaz Prtenjak","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/#article","isPartOf":{"@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/"},"author":{"name":"Matjaz Prtenjak","@id":"https:\/\/code-maze.com\/#\/schema\/person\/fb52db5fd702889fb141605f63bff589"},"headline":"Embedded Resources in .NET","datePublished":"2024-06-03T06:48:05+00:00","mainEntityOfPage":{"@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/"},"wordCount":1792,"commentCount":0,"publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"image":{"@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","keywords":["assembly","embedded resources","embedding","files","resources"],"articleSection":["C#"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/code-maze.com\/dotnet-embedded-resources\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/","url":"https:\/\/code-maze.com\/dotnet-embedded-resources\/","name":"Embedded Resources in .NET","isPartOf":{"@id":"https:\/\/code-maze.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/#primaryimage"},"image":{"@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/#primaryimage"},"thumbnailUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","datePublished":"2024-06-03T06:48:05+00:00","description":"Learn how to effectively manage embedded resources in .NET assemblies. We discover creation, inclusion, and access techniques.","breadcrumb":{"@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/code-maze.com\/dotnet-embedded-resources\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/#primaryimage","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2021\/12\/social-csharp.png","width":1100,"height":620,"caption":"C# Development"},{"@type":"BreadcrumbList","@id":"https:\/\/code-maze.com\/dotnet-embedded-resources\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/code-maze.com\/"},{"@type":"ListItem","position":2,"name":"Embedded Resources in .NET"}]},{"@type":"WebSite","@id":"https:\/\/code-maze.com\/#website","url":"https:\/\/code-maze.com\/","name":"Code Maze","description":"Learn. Code. Succeed.","publisher":{"@id":"https:\/\/code-maze.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/code-maze.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/code-maze.com\/#organization","name":"Code Maze","url":"https:\/\/code-maze.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2020\/01\/Code-Maze-Only-Logo-Transparent-HRez.png","width":3511,"height":3510,"caption":"Code Maze"},"image":{"@id":"https:\/\/code-maze.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/CodeMazeBlog"]},{"@type":"Person","@id":"https:\/\/code-maze.com\/#\/schema\/person\/fb52db5fd702889fb141605f63bff589","name":"Matjaz Prtenjak","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/code-maze.com\/#\/schema\/person\/image\/","url":"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/MatjazPrtenjak_400x400-150x150.jpg","contentUrl":"https:\/\/code-maze.com\/wp-content\/uploads\/2023\/12\/MatjazPrtenjak_400x400-150x150.jpg","caption":"Matjaz Prtenjak"},"description":"Matjaz is a seasoned professional with over 25 years of expertise in software development. He began his programming journey during the era when IBM dominated with mainframe computers, and personal computers were yet to be born. He possesses a rich background and has authored two books on C++ and VBA programming languages. Lately, he has dedicated himself to harnessing the power of .NET technology in his innovative projects.","sameAs":["https:\/\/www.linkedin.com\/in\/mprtenja\/"],"url":"https:\/\/code-maze.com\/author\/mprtenjak\/"}]}},"_links":{"self":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/116937","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/users\/53"}],"replies":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/comments?post=116937"}],"version-history":[{"count":2,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/116937\/revisions"}],"predecessor-version":[{"id":116940,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/posts\/116937\/revisions\/116940"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media\/62189"}],"wp:attachment":[{"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/media?parent=116937"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/categories?post=116937"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code-maze.com\/wp-json\/wp\/v2\/tags?post=116937"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}