Created
February 21, 2019 10:37
-
-
Save dradovic/0548310e623391145cfb0c04bd2db772 to your computer and use it in GitHub Desktop.
How to use the ManifestEmbeddedFileProvider with a Satellite Assembly
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
using System; | |
using System.IO; | |
using System.Reflection; | |
using Microsoft.Extensions.FileProviders; | |
namespace ReadingEmbeddedResource | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var provider = new ManifestEmbeddedFileProvider(Assembly.GetEntryAssembly()); | |
var fileInfo = provider.GetFileInfo("Resource.de-CH.json"); | |
Console.WriteLine($"Exists: {fileInfo.Exists}"); // prints true | |
string json; | |
using (var reader = new StreamReader(fileInfo.CreateReadStream())) | |
{ | |
json = reader.ReadToEnd(); | |
} | |
Console.WriteLine(json); | |
} | |
} | |
} |
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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp2.1</TargetFramework> | |
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="2.1.1" /> | |
</ItemGroup> | |
<ItemGroup> | |
<EmbeddedResource Include="Resource.de-CH.json" /> | |
</ItemGroup> | |
</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
{ | |
"This is a test": "Das ist ein Test" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment