Repository navigation
Project Structure
The Commands Library project layout and the responsibility of each file.
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.
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
The two CFX command entry points. These are the classes the CFX Runtime discovers and binds to Solution Explorer context menu items.
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.
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.
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).
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.
A progress display shown during single-page migration. Updates in real time as each step completes.
Static helper methods shared between the two dialogs — input validation, project name normalization.
The engine layer. Commands call into MigrationEngine; MigrationEngine calls the generator classes in Generation/. Commands never call generators directly.
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.
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
|
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.
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.
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.
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.
Generates the .Client/Program.cs with the HttpClient base address, scoped service registrations (including CartService), and Blazor WASM root component setup.
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
CFX-WebForms2WASMMigration · Built with the CodeFactory SDK · Derived from WebForms2BlazorServer by John Hannah