NeuCharFramework (NCF)
  • NCF - NeuCharFramework
  • Projects

    • Preparation
    • Basic Library Source Code Analysis
    • DynamicWebApiEngine
    • Deployment
  • Help

    • Online Resources
    • Q&A Community
    • QQ Group (147054579)
    • Senparc WeChat SDK
  • Gitee
  • GitHub
  • English
  • 简体中文
GitHub
  • NCF - NeuCharFramework
  • Projects

    • Preparation
    • Basic Library Source Code Analysis
    • DynamicWebApiEngine
    • Deployment
  • Help

    • Online Resources
    • Q&A Community
    • QQ Group (147054579)
    • Senparc WeChat SDK
  • Gitee
  • GitHub
  • English
  • 简体中文
GitHub
  • NCF Overview

    • NCF - NeuCharFramework
    • About NCF
    • Environment Requirements
    • Frontend and Backend Separation Mode
    • Introduction to Xncf Modules
  • Prepare Development

    • Get NCF Template Source Code
    • Using Visual Studio to Run NCF
    • Running NCF Using CLI
    • Installation
    • Admin Login
    • Admin Backend
    • appsettings.json Configuration
    • Module Management
    • Accessing Documentation
  • Configuration

    • Entry File
    • Database Settings
    • appsettings.json Configuration
    • Docker
    • Dapr
    • Configure Multi-Tenant
    • Redis Cache
  • Modular Development

    • NCF Modular Development Concept
    • Composition of Xncf
    • Create the First Xncf Module
    • Xncf Module Sample Detailed Explanation
    • Implement Your Own Business Logic
    • Update Xncf Module
    • How to Call Between Modules
    • Publish Xncf Module to nuget.org
    • Update Base Library
    • Xncf Module Development
    • Embedding Static Resource Files into NCF
    • Publish Local Nuget Package
    • Advanced
  • Database

    • Database Settings
    • Multi-Database Support
    • Specify Database
    • Update database migration files for the Senparc.Service project (Migrations)
    • Multi-Database Principle
    • DatabasePlant
    • Tarmac Operation Database Migration and Update
  • Unit Testing

    • NCF Unit Test Introduction
    • Start Development
    • Advanced
    • Appendix
  • Q&A

    • NCF Terminology
    • NCF FAQ
  • Release

    • New Features
    • Upgrade Guide
    • Logs

Embedding Static Resource Files into NCF

Whether developing the frontend or backend, it is inevitable to use static resource files. The static resource files referred to here are (html, css, js, etc.).

Currently, our NCF uses the DDD (Domain-Driven Design) model for development, so we hope that developers can focus more on the business within their own development modules. This way, with the upgrade of the official core NCF, seamless integration can be achieved, avoiding more modifications and migration of files.

Creating Static Resources

Establish static resources under Xncf_Module, as shown in the figure:

Image text

Setting Static Resource Properties

Select any static resource file, right-click, and choose embedded resource, as shown in the figure:

Image text

Image text

Adding Library References and Related Configurations in .csproject File

<PropertyGroup>
  <TargetFramework>netcoreapp3.1</TargetFramework>
  <GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>

<ItemGroup>
  <EmbeddedResource Include="wwwroot\**\*" />
  <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.6" />
</ItemGroup>

Adding Embedded Resource Registration Service in Register

/* This must be added
using Microsoft.AspNetCore.Builder;
using Senparc.CO2NET.RegisterServices;
using Microsoft.Extensions.FileProviders;
using System.Reflection;

Register : IAreaRegister // Register XNCF page interface (optional)
*/

public override IApplicationBuilder UseXncfModule(IApplicationBuilder app, IRegisterService registerService)
{
    app.UseStaticFiles(new StaticFileOptions
    {
        FileProvider = new ManifestEmbeddedFileProvider(Assembly.GetExecutingAssembly(), "wwwroot")
    });

    return base.UseXncfModule(app, registerService);
}

Checking if Static Resources Have Been Embedded

Right-click the project and rebuild

Image text

In the corresponding Debug/Release directory, find the newly generated dll file

Image text

Open the .Net decompiler tool, drag the dll file in, and check if the resources exist and if the resource files you added are present. If they are, it means the embedding was successful.

Image text

How to Use Embedded Static Resources

Image text

Edit this page on GitHub
Last Updated:
Contributors: Jeffrey Su
Prev
Xncf Module Development
Next
Publish Local Nuget Package