12

I have an asp.net core 3.0 website and I am trying to use FileProvider. I created the below based on an example, but I keep getting the error

InvalidOperationException: Could not load the embedded file manifest 'Microsoft.Extensions.FileProviders.Embedded.Manifest.xml' for assembly 'Test'.

Below is my startup class

using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; using IntranetPages.Shared; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Server.IISIntegration; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Hosting; namespace Test { public class Startup { private readonly IWebHostEnvironment _env; public Startup(IWebHostEnvironment env, IConfiguration configuration) { Configuration = configuration; _env = env; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddAuthentication(IISDefaults.AuthenticationScheme); services.AddTransient<IClaimsTransformation, CustomClaimsTransformer>(); services.AddSingleton<IAuthorizationHandler, CheckGroupHandler>(); var physicalProvider = _env.ContentRootFileProvider; var manifestEmbeddedProvider = new ManifestEmbeddedFileProvider(typeof(Program).Assembly); var compositeProvider = new CompositeFileProvider(physicalProvider, manifestEmbeddedProvider); services.AddSingleton<IFileProvider>(compositeProvider); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapRazorPages(); }); } } } 

What am I missing? I tried installing the NuGet packages, but it made no difference.

3 Answers 3

21

If you're migrating from ASP.NET-Core 2.x to 3.x, since ASP.NET-Core 3.0 and above, Microsoft.NET.Sdk.Web MSBuild SDK doesn't automatically include Microsoft.Extensions.FileProviders.Embedded NuGet package anymore.

Microsoft.Extensions.FileProviders.Embedded needs to be added explicitly.

<Project Sdk="Microsoft.NET.Sdk.Web"> ... <ItemGroup> <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.0.3" /> <!-- Or use version 3.1.2 for ASP.NET-Core 3.1 --> </ItemGroup> ... </Project> 

For those not migrating from 2.x to 3.x, don't forget to also add the following to your .csproj:

<Project Sdk="Microsoft.NET.Sdk.Web"> ... <PropertyGroup> <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> </PropertyGroup> ... <ItemGroup> <EmbeddedResource Include="..." /> <!-- Add your directories and/or files here. --> </ItemGroup> ... </Project> 
Sign up to request clarification or add additional context in comments.

2 Comments

I had to add in addition to this answer, the following line to the .csproj: <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> in the propertygroup section.
: 'Invalid manifest format. 'ResourcePath' must contain a text value. '''
1

You also need to specify the files to embed with <EmbeddedResource> in csproj file

<ItemGroup> <EmbeddedResource Include="your file" /> </ItemGroup> 

Use glob patterns to specify one or more files to embed into the assembly.

Comments

-1

To generate a manifest of the embedded files:

  • Add the Microsoft.Extensions.FileProviders.Embedded NuGet package to your project.

  • Set the property to true. Specify the files to embed with :

     <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.0" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="Resource.txt" /> </ItemGroup> </Project> 
  • Use glob patterns to specify one or more files to embed into the assembly.

1 Comment

This is a duplicate of an existing answer that is older than yours.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.