Getting Started

A new approach

I would normally start a Blazor project by opening Visual Studio and creating a new Blazor server app, and then adding any NuGet packages required.

This time I will try something different.

In my searching for information about Photino I also came across a GitHub repository by Nathan Wilson that seemed to provide an answer all my questions - how to create a new Visual Studio solution/project from scratch. Here I reproduce Nathan Wilson's steps.

Creating a Photino Blazor app from the CLI

Prerequisites

  • Make sure .NET 9.0 SDK is installed (How to check)
  • I'm using Visual Studio 2022

Create the Solution

In File Manager I created a folder in my default 'repos' directory for the new solution. I named it 'PhotinoDemo'. This will be the name of the solution/project and namespace.

I used Git Bash as the command line interface, but suspect that a Windows command prompt would work just as well.

In Git Bash

  • Change directory to the folder created for the solution
  • Create the project
    • dotnet new blazor
  • Install Photino Blazor
    • dotnet add package Photino.Blazor
  • Could close Git Bash at this point

In File Manager browse to the project folder and open the csproj file (in my case PhotinoDemo.csproj) with Visual Studio.

In Visual Studio:

  • Change to wwwroot
  • Add a new file, call it index.html and replace all code with:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <app>Loading...</app>
    <script src="_framework/blazor.webview.js"></script>
</body>
</html>
  • Update App.razor by removing the following from the <body>  tag, if present.
<script src="_framework/blazor.web.js"></script>
  • Update .csproj - replacing all code with this:
<Project Sdk="Microsoft.NET.Sdk.razor">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <Content Update="wwwroot\**">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Photino.Blazor" Version="4.0.13" />
  </ItemGroup>

</Project>
  • Update Program.cs - replacing all code with this:
using Microsoft.Extensions.DependencyInjection;
using Photino.Blazor;

namespace PhotinoDemo
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            var appBuilder = PhotinoBlazorAppBuilder.CreateDefault(args);

            appBuilder.Services.AddLogging();

            appBuilder.RootComponents.Add<App>("app");

            var app = appBuilder.Build();

            app.MainWindow.SetTitle("Photino Blazor Demo");

            AppDomain.CurrentDomain.UnhandledException += (sender, error) =>
            {
                app.MainWindow.ShowMessage("Fatal Exception", error.ExceptionObject.ToString());
            };

            app.Run();
        }
    }
}
  • In the above, change the namespace to your project's name (in my case Photino Demo).
  • (I also had to add 'using Photino.Blazor;' at the top of the file - the only difference I found from Nathan Wilson's instructions)
  • (Note that appBuilder.RootComponents.Add<App>("app"); has a red squiggle under <App> . This will eventually disappear. (Closing and re-opening the solution appears to solve this problem.)
  • Remove Server-side directives from Counter.razor and Weather.razor
    • @rendermode InteractiveServer from Counter.razor
    • @attribute [StreamRendering] from Weather.razor
  • Ensure .csproj uses Razor SDK:
<Project Sdk="Microsoft.NET.Sdk.razor">
  • Ensure Program.cs includes:
using Microsoft.Extensions.DependencyInjection;
  • Delete unnecessary files
    • ./Components/Pages/Error.razor
  • Remove <ImportMap> from ./Components/App.razor

Save all files. This will trigger the .sln file to be saved in the solution folder in File Manager. Following the save a message will appear at the top of Visual Studio prompting a reload; click the reload button.

With all files saved and the project re-loaded, run the application from Visual Studio.