Course contentsShow
← C#
Lesson 1391 of 1,90812. Modern Frontend with Razor and BlazorFree lesson

Custom Component Libraries

Publish and version your component libraries using NuGet for internal enterprise sharing.

In this lesson, you will learn how to transition your shared UI components from local source code into versioned, distributable NuGet packages for seamless enterprise-wide consumption.

From Local Project to Enterprise Asset

Up until now, you have likely been referencing your shared UI components via direct project references. While this works for monolithic solutions, it becomes a maintenance nightmare in large-scale enterprises. By packaging your components as NuGet packages, you decouple your UI library from the main application lifecycle, allowing different teams to consume specific versions of your components without risking breaking changes.

Packaging for NuGet

To prepare your Blazor Class Library (BCL) for distribution, you first need to configure the project metadata. Open your .csproj file and add the relevant NuGet properties:

<PropertyGroup>
  <TargetFramework>net8.0</TargetFramework>
  <PackageId>Company.Enterprise.Components</PackageId>
  <Version>1.2.0</Version>
  <Authors>CoreUI-Team</Authors>
  <Company>YourEnterprise</Company>
  <PackageDescription>Standardized Blazor components for internal apps.</PackageDescription>
</PropertyGroup>

Once configured, you generate the package using dotnet pack. This produces a .nupkg file—a compressed artifact containing your compiled DLLs, CSS assets, and static web resources.

Versioning and Internal Feeds

In an enterprise environment, you don't push these to the public nuget.org gallery. Instead, you utilize a private package feed, such as Azure Artifacts or GitHub Packages.

Versioning is critical here. Always follow Semantic Versioning (SemVer):

  • Major (2.0.0): Breaking changes (e.g., changing a component parameter name).
  • Minor (1.3.0): Adding new components or features in a backward-compatible way.
  • Patch (1.2.1): Bug fixes.

By publishing these as versioned artifacts, an application team can lock their dependency to [1.2.0, 2.0.0) in their csproj, ensuring they receive bug fixes automatically while shielding them from breaking changes until they are ready to upgrade. This creates a "contract" between the library maintainers and the consuming teams, fostering stability across your organization.

Key Takeaway: By packaging your Blazor components as versioned NuGet packages, you transform your UI code into a stable, enterprise-grade product that allows teams to scale development without tight coupling.