DT Tech InfoDT Tech Info

      AspNet Core - Razor

      LEARN EASY
      • Home
      • Blog
      • AspNet Core - Razor
      • Asp.Net: Reusable static assets from Razor Class Library

      Asp.Net: Reusable static assets from Razor Class Library

      • Posted by DT-Tech
      • Categories AspNet Core - Razor, Web Development
      • Date April 21, 2023

      In this article we will see how to share static assets like css, libraries, etc., to the asp.net web projects. So that we can maintain uniformity or common user experience across applications.

      I assume, you are already familiar with asp.net core and creating Razor Class Library projects. So if you are following along, please create a RCL project within your solution.

      Add client library into RCL Project

      Create a folder called wwwroot in the RCL project, navigate to wwwroot then create sub folder called lib,  we will keep our common client libraries in this folder wwwroot\lib inside shared project.

      Right-click the project  folder wwwroot\lib. Choose Add > Client-Side Library. 

      Type the library name in the Libarary text box choose the necessary version from the dropdown list,  select which file to include and then click the install button to download the files.

      Now you should be able to see the files downloaded in to wwwroot\lib folder.

      Consume static styles from RCL/shared project

      I order to consume the library from the RCL / Shared library, we need to add the library reference in the consuming web project.

      Below is an example of using bootstrap css file from the RCL / Shared library.

      NOTE: We should use the following Url in the consuming app under the prefix “_content/{PACKAGE ID}/”,  here the default prefix is a static string “_content” followed by the shared assembly name and then the path inside wwwroot folder. 

      Tag:reusability, static assets reusability

      • Share:
      author avatar
      DT-Tech

      Previous post

      Logging with Serilog for WPF / WPF Core Applications
      April 21, 2023

      Next post

      Introduction to ArchiMate Modeling Language
      June 18, 2023

      Leave A Reply Cancel reply

      Your email address will not be published. Required fields are marked *

      Search

      Categories

      • Angular
      • Angular PWA
      • ArchiMate
      • AspNet Core – Razor
      • AspNet Core – WebApi
      • Best Practices
      • Design Patterns
      • EF Core
      • Entity Framework
      • IdentityServer4
      • RxJs for Beginners
      • Tips & Tricks
      • Uncategorized
      • Web Development
      • WPF / WPF Core

      Latest Posts

      Azure: Storage Services
      26Sep2024
      Angular Styles – Tips and Tricks
      23Dec2023
      Typescript – Tips and Tricks
      23Dec2023
      logo-eduma-the-best-lms-wordpress-theme

      webadmin@dt-tech.info

      Organization

      • Contact Us

      Links

      • Blogs
      • Gallery

      Recommend

      • Angular
      • RxJS
      • AspNet Core – Razor
      • AspNet Core – WebApi
      • AspNetCore

      Powered by DT Tech.