[Asp.Net Core MVC] Is posssible to embed the wwwroot directory inside the dist binary? #55657
-
I have an Asp Net Core MVC project with my assets in wwwroot. My intent is to have only the binary and the appsettings file so is easy to update the application in production without to lose some updated assets files. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Yes, you can do this 😀 Here is how: In your <PropertyGroup>
<!-- all the usual stuff -->
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="wwwroot\**" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.4" />
<!-- all your other dependencies -->
</ItemGroup> Next, in your // all the usual stuff
var builder = WebApplication.CreateBuilder(args);
// all the usual stuff
var fileProvider = new ManifestEmbeddedFileProvider(Assembly.GetAssembly(type: typeof(Program))!, "wwwroot");
var app = builder.Build();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = fileProvider,
RequestPath = string.Empty,
});
// other stuff That's it 👍. Please notice, that you request these files without the trailing I hope that helps you 😀 |
Beta Was this translation helpful? Give feedback.
Yes, you can do this 😀 Here is how:
In your
*.csproj
:Next, in your
Program.cs
: