BlazorLore.Scaffold.Cli
1.0.0
See the version list below for details.
dotnet tool install --global BlazorLore.Scaffold.Cli --version 1.0.0
dotnet new tool-manifest
dotnet tool install --local BlazorLore.Scaffold.Cli --version 1.0.0
#tool dotnet:?package=BlazorLore.Scaffold.Cli&version=1.0.0
nuke :add-package BlazorLore.Scaffold.Cli --version 1.0.0
BlazorLore Scaffold CLI
A powerful command-line tool for scaffolding and refactoring Blazor components with modern C# patterns. Generate components, forms, and more with ease while following best practices.
✨ Features
- 🚀 Component Generation - Create Blazor components with optional code-behind and CSS isolation
- 📝 Form Generation - Generate forms from C# model classes with validation support
- 🔧 Code Refactoring - Extract inline code to code-behind files
- 🎯 Modern C# Support - Convert legacy
[Inject]attributes to constructor injection - ⚡ AOT Compiled - Fast startup and execution with ahead-of-time compilation
- 📦 Template-Based - Customizable Scriban templates for code generation
📥 Installation
As a Global Tool
Install the CLI tool globally using the .NET CLI:
dotnet tool install --global BlazorLore.Scaffold.Cli
After installation, you can use the tool from anywhere:
blazor-scaffold --help
Update the Tool
To update to the latest version:
dotnet tool update --global BlazorLore.Scaffold.Cli
Uninstall
To uninstall the tool:
dotnet tool uninstall --global BlazorLore.Scaffold.Cli
🚀 Quick Start
Generate a Component
Create a new Blazor component:
# Basic component
blazor-scaffold component generate MyComponent
# With code-behind and CSS
blazor-scaffold component generate MyComponent --code-behind --css
# Specify output path
blazor-scaffold component generate MyComponent --path ./Components
Generate a Form from a Model
Create a form from a C# model class:
# Generate create form
blazor-scaffold form generate ./Models/Product.cs
# Generate edit form with custom name
blazor-scaffold form generate ./Models/Product.cs --name ProductEditForm --edit
# Custom submit action
blazor-scaffold form generate ./Models/User.cs --submit-action HandleRegistration
Refactor Existing Components
Extract inline code to code-behind:
blazor-scaffold component refactor ./Components/MyComponent.razor --extract-code
Modernize code-behind to use constructor injection:
blazor-scaffold component modernize ./Components/MyComponent.razor.cs
📚 Commands
Component Commands
component generate
Generate a new Blazor component.
Arguments:
name- The name of the component (required)
Options:
--path- Output directory (default: current directory)--code-behind- Generate with code-behind file--css- Generate with CSS isolation file
Example:
blazor-scaffold component generate UserProfile --path ./Components/Users --code-behind --css
component refactor
Refactor an existing Blazor component.
Arguments:
file- Path to the component file (required)
Options:
--extract-code- Extract @code block to code-behind file
Example:
blazor-scaffold component refactor ./Components/Dashboard.razor --extract-code
component modernize
Modernize component code-behind to use constructor injection.
Arguments:
file- Path to the code-behind file (required)
Example:
blazor-scaffold component modernize ./Components/Dashboard.razor.cs
component list
List all Blazor components in a directory.
Options:
--dir- Directory to search (default: current directory)
Example:
blazor-scaffold component list --dir ./src/Components
Form Commands
form generate
Generate a form from a C# model class.
Arguments:
model- Path to the model file (required)
Options:
--name- Form component name (default: {ModelName}Form)--path- Output directory (default: current directory)--edit- Generate as edit form with parameter--submit-action- Method name for form submission (default: OnSubmit)
Example:
blazor-scaffold form generate ./Models/Customer.cs --name CustomerRegistrationForm --path ./Forms
🎯 Examples
Creating a Complete Feature
- Create a model:
// Models/Product.cs
using System.ComponentModel.DataAnnotations;
namespace MyApp.Models;
public class Product
{
public int Id { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
[Range(0.01, 10000)]
public decimal Price { get; set; }
public bool IsActive { get; set; }
}
- Generate a form for the model:
blazor-scaffold form generate ./Models/Product.cs --name ProductForm --path ./Components/Products
- Generate a component to display products:
blazor-scaffold component generate ProductList --path ./Components/Products --code-behind
Refactoring Legacy Components
- Extract inline code from an existing component:
blazor-scaffold component refactor ./Legacy/OldComponent.razor --extract-code
- Modernize the extracted code-behind:
blazor-scaffold component modernize ./Legacy/OldComponent.razor.cs
🔧 Configuration
Template Customization
Templates are located in the Templates directory and use the Scriban template engine. You can customize them to match your coding standards.
Demo Mode
Run without arguments to see a live demo:
blazor-scaffold
🏗️ Architecture
The CLI tool is built with:
- .NET 9 - Latest framework features
- System.CommandLine - Modern command-line parsing
- Scriban - Powerful template engine
- AOT Compilation - Native performance
Project Structure
BlazorLore.Scaffold.Cli/
├── Commands/ # CLI command definitions
├── Services/ # Core business logic
├── Templates/ # Scriban templates
├── Models/ # Sample models for testing
└── Program.cs # Entry point with demo mode
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Built with ❤️ for the Blazor community
- Powered by Scriban template engine
- Uses System.CommandLine for CLI parsing
📞 Support
- 📧 Email: support@blazorlore.com
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
Made with ⚡ by the BlazorLore team
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
This package has no dependencies.
Initial release with component and form generation support