Create blazor library project in the Visual Studio 2019 preview

Correct way is to create ASP.NET Core Web Application and in the second step select “Razor Class Library” project template.

If you create Standard or AspNet.Core library directly then your project file will not contain correct setup for razor component source generation, but you can easily correct this manually:

The correct .csproj file structure of razor library project

<Project Sdk="Microsoft.NET.Sdk.Razor">


    <FrameworkReference Include="Microsoft.AspNetCore.App" />



_Imports.razor file

Imports razor file can contain any number of statements (usually centralized using statements). The file will be automatically included in all razor component files in the folder and all subfolders of imports file.

@using MatBlazor
@using Bisaga.Organization.Web.Pages;

Razor files and coresponding code behind file naming convension

If we want to have “code behind” files (with csharp code) hidden “under” the razor file (in Visual Studio) then you need to name components with the same name and additional suffix “.cs”.


The name of the component “BsgCompanyForm.razor” and the code behind with “functions” in csharp file named “BsgCompanyForm.razor.cs”. But don’t forget that the name of the class cannot be the same as the component name (in this case “BsgCompanyForm” but we usually add some additional suffix in the class name too.

Both files are then connected with the @inherits statement

BsgCompanyForm.razor file:

@inherits BsgCompanyFormBase


BsgCompanyForm.razor.cs file:

using Bisaga.Framework.Web;
using System;
using System.Collections.Generic;
using System.Text;

namespace Bisaga.Organization.Web.Pages
    public class BsgCompanyFormBase : BsgPageBase

If you need to include additional resources (as javascript, CSS) to the project for the final web project deployment, use EmbeddedBlazorContent library:

EmbeddedBlazorContent – how to include static content from blazor libraries

If you want to include some static resources from the Blazor component library use “EmbeddedBlazorContent” tool.


Create static content in Blazor component library

Create “content” folder in the root of the library project and add CSS and JS files in.

Add embeded resource build action on all the files

Open properties on each resource file and select “Embedded resource” build action on it.

Additional attributes for embedded resource in the project file

Open .CSPROJ project file and edit EmbeddedResource definition to have additional LogicalName definition.

For CSS files:


For JS files:



    <EmbeddedResource Include="content\bisaga_core.css">
    <EmbeddedResource Include="content\bisaga_core.js">

Add EmbeddedBlazorContent library to blazor server side web project


Add configuration for embeded content library to Configure metod in Startup.cs

# Startup.cs


Add call to EmbeddedBlazorContent where you wish to include embedded files.

@using EmbeddedBlazorContent


Syncfusion EJ2 AspNet Core Blazor components installation

If you need professional and supported set of components for server side / client side Blazor web applications use Syncfusion components.

More info:

Installation – NuGet packages :

  • Syncfusion.EJ2.Blazor


Configure method

Licensing is not needed in case of preview version and library don’t even contain “Licensing” namespace.

// Register Syncfusion license
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("...licence string...");


@addTagHelper *, Syncfusion.EJ2.Blazor

    <link href="" rel="stylesheet" />
    <!--    <link href="" rel="stylesheet" />-->
    <!--    <link href="" rel="stylesheet" />-->
    <script src=""></script>
    <script src=""></script></head>


@using Syncfusion.EJ2.Blazor<br>
@using Syncfusion.EJ2.Blazor.Calendars

Components usage in razor files

@page "/"
<h1>Hello, world!</h1>
Welcome to your new app.
<br />

The result

If everything is deployed as expected you should see similar result page:

MatBlazor components installation

AspNet Core – Server side Blazor framework


If you need open source components for Blazor you definitively need to look at MatBlazor component library.


  • MatBlazor nuget library
  • EmbeddedBlazorContent nuget library (for server side blazor projects)


Configure method

// Embedded blazor content get static content from depended DLLs 


Add additional “using” statement for MatBlazor

@using MatBlazor


@addTagHelper *, MatBlazor
@using EmbeddedBlazorContent

    <!-- static resources from dependent blazor libraries -->

Application bar sample

In the NavMenu.razor file add:

    <MatAppBar Fixed="true">
                <MatIconButton Icon="menu"></MatIconButton>
                <MatAppBarTitle>Trade scanner</MatAppBarTitle>
            <MatAppBarSection Align="@MatAppBarSectionAlign.End">
                <MatIconButton Icon="favorite"></MatIconButton>

After compile your application should look something like :

Blazor components are encoded without namespaces, it means @addTagHelper and @using statements are in place and working.

Database migrations with FluentMigrator

How to setup database migrations in AspNet Core 3 project and SQLite database

Add NuGet packages to projects with migration classes (data layer library):
– FluentMigrator
– Microsoft.Data.Sqlite

Add two additional NuGet packages to AspNet Core web project :
– FluentMigrator.Runner
– FluentMigrator.Runner.SQLite

Configure Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

using FluentMigrator.Runner;
using FluentMigrator.Runner.Initialization;
using Bisaga.Core.Data.Model.Common;
using Trade.Core.Data.Model;

namespace Trade.Scanner
     public class Startup
        public Startup(IConfiguration configuration)
            Configuration = configuration;

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit
        public void ConfigureServices(IServiceCollection services)

            //Setup data migrations 
                .ConfigureRunner(rb => rb
                    // Add SQLite support to FluentMigrator
                    // Set the connection string
                    // Define the assemblies containing the migrations
                ).AddLogging(lb => lb

            // Setup services 

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IMigrationRunner migrationRunner)
            if (env.IsDevelopment())
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see



            app.UseEndpoints(endpoints =>

            // Run database migrations 

Part of the statement: “.ScanIn(typeof(Company).Assembly).For.Migrations()” is where we define assembly (DLL) where the migration classes are. In case of multiple libraries we simply repeat same method again. The class defined in the “typeof” function could be any class from the targeted assembly.

Migration runner – MigrateUp procedure

To migrate database up we define interface of migration runner in the “Configure” method as parameter. The dependency injection will give us an instance of runner on which we run “MigrateUp” on. Configure will run immediately after ConfigureServices in the application start process.

Sample migration class

using System;
using System.Collections.Generic;
using System.Text;
using FluentMigrator;
namespace Bisaga.Core.Data.Migrations
  public class AddCompanyExhangeStock : Migration
    public override void Up()     {         


       .WithColumn("ExchangeId").AsInt64().ForeignKey("Exchange", "Id");

    public override void Down()     {         
       throw new NotImplementedException();

More informations :