Search code examples
twitter-bootstraprazorblazormaui-blazor

How do you include Bootstrap in Razor class library


I'd like to create a razor class library with several components and use that in various Blazor or MAUI Blazor projects. However, these projects have inconsistent Bootstrap versions, and I would like for this class library to have its own Bootstrap version, making it really self-contained.

How to self-contain a specific Bootstrap version withing my Razor class library?


Solution

  • At first, you can try to add the Package Reference into the Razor class library's csproj file according to this case, such as:

    <ItemGroup>
      <PackageReference Include="Twitter.Bootstrap" Version="3.0.0" PrivateAssets="All" />
    </ItemGroup>
    

    But you need to change the Razor class library to a nuget package. Because the RCL can't add Client-Side Library directly. And the boostrap's style files such as .js and .ccs file need be added in the wwwroot folder.

    For more information, you can check this link.