Skip to content

Instantly share code, notes, and snippets.

@sdurandeu
Last active June 30, 2017 15:07
Show Gist options
  • Select an option

  • Save sdurandeu/a670d2e4692cc5cb10ee35fd313db82d to your computer and use it in GitHub Desktop.

Select an option

Save sdurandeu/a670d2e4692cc5cb10ee35fd313db82d to your computer and use it in GitHub Desktop.
.NET Core: Get Embedded File in Assembly
// 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;
}
// 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