Skip to content

Project Structure

Bill Fencken edited this page Mar 20, 2026 · 1 revision

Project Structure

The Commands Library project layout and the responsibility of each file.


Overview

The Commands Library is a .NET Framework 4.8 Visual Studio project. It uses the CFX SDK via NuGet. Every build runs the CFXPackager post-build step automatically, which bundles the compiled assembly, dialogs, and resources into a single WebForms2BlazorWASMCommands.cfx deployment file.

Why .NET Framework 4.8? The CFX Runtime runs inside the Visual Studio process, which is a .NET Framework host. All command code must target .NET Framework — you cannot use .NET Core / .NET 5+ APIs in the Commands Library. The projects it generates can target any framework.


Folder Structure

WebForms2BlazorWASM/
│
├── Commands/
│   ├── Project/
│   │   └── SetupBlazorProject.cs
│   └── Document/
│       └── MigrateWebForm.cs
│
├── Dialog/
│   ├── SetupBlazorDialog.xaml
│   ├── SetupBlazorDialog.xaml.cs
│   ├── MigrateWebFormDialog.xaml
│   ├── MigrateWebFormDialog.xaml.cs
│   └── DialogExtensions.cs
│
├── Migration/
│   ├── MigrationContext.cs
│   ├── MigrationEngine.cs
│   ├── MigrationEngine.Config.cs
│   ├── MigrationEngine.LogicClasses.cs
│   ├── MigrationEngine.StaticFiles.cs
│   ├── MigrationEngine.AspxFiles.cs
│   ├── MigrationEngine.ApiLayer.cs
│   └── MigrationEngine.ClientProgram.cs
│
└── Generation/
    ├── RazorPageGenerator.cs
    ├── ApiControllerGenerator.cs
    ├── SharedDtoGenerator.cs
    └── ClientProgramGenerator.cs

Commands/

The two CFX command entry points. These are the classes the CFX Runtime discovers and binds to Solution Explorer context menu items.

Commands/Project/SetupBlazorProject.cs

Type: ProjectCommandBase — binds to project nodes in Solution Explorer.

Enable gate: Returns true only when (1) no project in the solution has a name ending in .Client, and (2) the right-clicked project contains .aspx files. Returns false silently on any exception.

Execute sequence: Shows SetupBlazorDialog to collect the three project names. If the user cancels, writes a cancellation message to the output window and returns. Otherwise, creates a MigrationContext and calls the seven MigrationEngine methods in order.

Commands/Document/MigrateWebForm.cs

Type: DocumentCommandBase — binds to any document node, filtered to .aspx files.

Enable gate: Three-layer check — (1) the document name must end in .aspx, excluding .aspx.cs code-behind files, (2) a .Client project must exist in the solution (SetupBlazorProject must have run first), (3) the target .razor filename must not already exist in .Client/Pages/. Returns false on any exception.

Execute logic: Derives the target filename (Default.aspx → Index.razor, all others strip .aspx). Calls RazorPageGenerator to produce the component content. Writes the file to .Client/Pages/ via AddDocumentAsync.


Dialog/

WPF ViewUserControl classes that CFX shows inside Visual Studio during command execution. These are standard WPF user controls that inherit from ViewUserControl (the v2.0 replacement for VsUserControl).

SetupBlazorDialog.xaml/.cs

Three text input fields for the project names, with pre-populated defaults. A Run button triggers the migration. A Cancel button returns control to the command which then aborts cleanly.

MigrateWebFormDialog.xaml/.cs

A progress display shown during single-page migration. Updates in real time as each step completes.

DialogExtensions.cs

Static helper methods shared between the two dialogs — input validation, project name normalization.


Migration/

The engine layer. Commands call into MigrationEngine; MigrationEngine calls the generator classes in Generation/. Commands never call generators directly.

MigrationContext.cs

A plain C# class that holds the resolved VS project references for a single migration run:

public class MigrationContext
{
    public VsProject SourceProject { get; set; }
    public VsProject ClientProject { get; set; }
    public VsProject ServerProject { get; set; }
    public VsProject SharedProject { get; set; }
    public IVsActions VisualStudioActions { get; set; }
}

Why this pattern matters: CFX prohibits caching data model references between separate command invocations (Rule 4). MigrationContext is created fresh on each ExecuteCommandAsync call and discarded when the migration completes. It is never stored as a field on the command class.

MigrationEngine.cs (and partial classes)

The main orchestration class, split across eight partial class files for readability. The core class defines the seven-step sequence; each partial class owns one step:

Partial Class File Step Responsibility
MigrationEngine.cs Orchestration Calls steps in order, writes status to output window
MigrationEngine.Config.cs Step 2 web.config → appsettings.json
MigrationEngine.LogicClasses.cs Step 3 Migrates .cs class files to .Server
MigrationEngine.StaticFiles.cs Step 4 Copies images, scripts, CSS
MigrationEngine.AspxFiles.cs Step 5 Calls RazorPageGenerator for each .aspx
MigrationEngine.ApiLayer.cs Step 6 Calls ApiControllerGenerator per entity
MigrationEngine.ClientProgram.cs Step 7 Calls ClientProgramGenerator

Generation/

SourceFormatter-based generation helpers. Each class owns one output type and knows exactly what it produces. No CFX compliance rules apply to these classes directly — they are pure C# helper methods called from the engine.

RazorPageGenerator.cs

Produces a Blazor WASM component scaffold from a source filename and component name. Encodes the @inject HttpClient pattern, OnInitializedAsync lifecycle method, route derivation, and the provenance comment.

ApiControllerGenerator.cs

Reads the live EF entity model from the .Server project and generates an ASP.NET Core ApiController with standard CRUD action stubs. Route conventions and async patterns are encoded in this generator — they are not decided at call time.

SharedDtoGenerator.cs

The most interesting generator. Reads the EF entity class via GetCSharpSourceModelAsync, traverses its properties, strips [Key], [Required], virtual navigation properties, and EF-specific attributes, then emits a clean POCO via SourceFormatter. This is the "read the live model then emit a transformed version" pattern.

ClientProgramGenerator.cs

Generates the .Client/Program.cs with the HttpClient base address, scoped service registrations (including CartService), and Blazor WASM root component setup.


NuGet Dependencies

The Commands Library project references:

Package Version Purpose
CodeFactorySDK 1.23053.1 Core CFX SDK — commands, data models, actions API
CodeFactory.Formatting.CSharp latest stable Extended formatting helpers for SourceFormatter

Do not add these manually before the first build. The Commands Library project template adds them automatically. The first build triggers NuGet restore — expect errors until it succeeds. This is normal behavior documented by CFX.


Next: Reading the Source

← Home · ← What Gets Generated