Last active
June 30, 2017 15:07
-
-
Save sdurandeu/a670d2e4692cc5cb10ee35fd313db82d to your computer and use it in GitHub Desktop.
.NET Core: Get Embedded File in 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
| // NOTE: if the file is embedded in the executing assembly, this code can be simplified | |
| // NOTE: this works even if the file is not embedded in the executing assembly | |
| private async Task<string> GetEmbeddedFile(string fileName) | |
| { | |
| // NOTE: this code is not great but allows us to have the stored procedure js in the TryAzureCdn.Data project | |
| // Resources (.resx file) are not working with embedded files | |
| var assembly = typeof(DocumentDBRepository).GetTypeInfo().Assembly; | |
| var resourceName = assembly.GetManifestResourceNames().FirstOrDefault(m => m.Contains(fileName)); | |
| Stream resourceStream = assembly.GetManifestResourceStream(resourceName); | |
| string fileContents = string.Empty; | |
| using (var reader = new StreamReader(resourceStream, Encoding.UTF8)) | |
| { | |
| fileContents = await reader.ReadToEndAsync(); | |
| } | |
| return fileContents; | |
| } |
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
| // add the following code | |
| "buildOptions": { | |
| "embed": { | |
| "include": [ | |
| "./StoredProcedures/*.js" | |
| ] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment