Default files for C# projects
A script that build a modular .NET solution following Clean Architecture principles, supporting standalone, local network, and cloud deployments. The system separates domain, application, and infrastructure layers, and is designed for maintainability, testability, and scalability.
Loading...
Searching...
No Matches
Default files for C# projects

Downloads Contributors Forks Stargazers Issues License GitHub Pages LinkedIn

Dotnet.DefaultFiles

This repository provides a template for initializing .NET projects with default files and a setup script. It is designed to help developers quickly scaffold a new solution following Clean Architecture principles, including recommended folder structure, configuration, and build scripts.

πŸ“š Table of Contents

πŸš€ Overview

Dotnet.DefaultFiles serves as a starting point for .NET development. It includes:

  • Standard files for solution and project setup
  • PowerShell script for creating a new Clean Architecture project
  • Quality criteria for artifacts and code
  • Copilot agents, instructions and prompts for generating artifacts, code and documentation.

🎯 Solution Goals

  • Provide a consistent starting point for .NET projects
  • Encourage best practices in project structure and configuration
  • Facilitate quick setup of Clean Architecture solutions
  • Include tools and resources for maintaining code quality and documentation
  • Support both Blazor and Web API project types with Clean Architecture principles
  • Offer flexibility through script arguments for different project needs

Setup & Usage

Initializing a New Project

  1. Create a folder with the name of your new solution. (e.g., mkdir MyNewSolution)
  2. Go to the new folder. (e.g., cd MyNewSolution)

Windows PowerShell

  1. Download and run the setup script to scaffold your solution. The script uses a YAML configuration file (solution-structure.config.yaml) to define the directory and file structure, which is loaded by import-yaml-config.ps1:
    • Scaffold a new solution with Clean Architecture principles:
      Invoke-WebRequest -Uri "https://raw.githubusercontent.com/TirsvadCLI/Dotnet.DefaultFiles/refs/heads/main/settings.yaml" -OutFile "settings.yaml"
      Invoke-WebRequest -Uri "https://raw.githubusercontent.com/TirsvadCLI/Dotnet.DefaultFiles/refs/heads/main/import-yaml-config.ps1" -OutFile "import-yaml-config.ps1"
      Invoke-WebRequest -Uri "https://raw.githubusercontent.com/TirsvadCLI/Dotnet.DefaultFiles/refs/heads/main/setupSolutionCleanArchentectureCSharp.ps1" -OutFile "setupSolutionCleanArchentectureCSharp.ps1"
      .\setupSolutionCleanArchentectureCSharp.ps1
    • Scaffold a new Blazor project with Clean Architecture principles and WebApi:
      Invoke-WebRequest -Uri "https://raw.githubusercontent.com/TirsvadCLI/Dotnet.DefaultFiles/refs/heads/main/setupSolutionCleanArchentectureCSharp.ps1" -OutFile "setupSolutionCleanArchentectureCSharp.ps1"
      .\setupSolutionCleanArchentectureCSharp.ps1 -Blazor -WebApi

This will create the recommended folder structure, add default files, and configure the solution for Clean Architecture, all based on the YAML configuration.

The folder structure will be created as follows:

πŸ› οΈ Script Arguments and Usage

The setupSolutionCleanArchentectureCSharp.ps1 script supports several arguments to customize the solution setup:

Arguments:

Switch Description
-Files Only create directories, hardlink, and copy default files.
-Arch Only set up Clean Architecture solution and projects (Domain, Application, Infrastructure).
-Blazor Set up Clean Architecture and add Blazor WebAssembly and server projects (frontend/backend)
-WebApi Set up Clean Architecture and add a Web API project
-Help Show usage instructions and exit.
-DefaultFilesRoot <path> Optional path to a custom source for default files.
-SolutionFile <file> Optional custom solution file name.
-Framework <version> Optional .NET target framework (default: net10.0).

Examples:

# Default setup: directories, files, and Clean Architecture projects
./setupSolutionCleanArchentectureCSharp.ps1
# Only create directories and copy default files
./setupSolutionCleanArchentectureCSharp.ps1 -Files
# Only set up Clean Architecture projects (no file copying)
./setupSolutionCleanArchentectureCSharp.ps1 -Arch
# Set up Clean Architecture and add Blazor frontend/backend
./setupSolutionCleanArchentectureCSharp.ps1 -Blazor
# Set up Clean Architecture and add Web API backend
./setupSolutionCleanArchentectureCSharp.ps1 -WebApi
# Show help
./setupSolutionCleanArchentectureCSharp.ps1 -Help
# Use a custom default files source and solution file name
./setupSolutionCleanArchentectureCSharp.ps1 -DefaultFilesRoot "../MyDefaults" -SolutionFile "MySolution.slnx"
MyBlazorApp/
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ Domain/ # Business logic and entities
β”‚ β”‚ β”œβ”€β”€ Entities/ # Domain entities
β”‚ β”‚ β”œβ”€β”€ Interfaces/ # Domain interfaces
β”‚ β”‚ └── ValueObjects/ # Domain value objects
β”‚ β”œβ”€β”€ Application/ # Application services and use cases
β”‚ β”‚ β”œβ”€β”€ Services/ # Application services
β”‚ β”‚ β”œβ”€β”€ Helpers/ # Application helpers
β”‚ β”‚ β”œβ”€β”€ Managers/ # Application managers
β”‚ β”‚ β”œβ”€β”€ Mappers/ # Application mappers
β”‚ β”‚ β”œβ”€β”€ DTOs/ # Data transfer objects
β”‚ β”‚ └── Interfaces/ # Application interfaces
β”‚ β”œβ”€β”€ Infrastructure/ # Data access, external services
β”‚ β”‚ β”œβ”€β”€ Persistence/ # Database context and repositories
β”‚ β”‚ β”‚ └── Configuration/ # Database configuration files
β”‚ β”‚ └── Repositories/ # Repository implementations
β”‚ β”œβ”€β”€ Web/ # Web UI projects (if selected)
β”‚ β”‚ β”œβ”€β”€ MyBlazorApp.Web/ # Blazor project
β”‚ β”‚ └── MyBlazorApp.Web.Client/ # Blazor WebAssembly project
β”‚ └── WebApi # Web API project (if selected)
β”œβ”€β”€ docs/ # Documentation and design files
β”œβ”€β”€ tests/ # Test projects
└── .github # GitHub configuration files

Customizing

  • Edit configuration files as needed (e.g., global.json, Directory.Build.props).
  • Add or update environment variables for your setup.

Default Files Included

  • global.json: .NET SDK version management
  • Directory.Build.props / Directory.Build.targets: Solution-wide build settings
  • .gitignore: Standard ignore rules
  • nuget.config: Custom NuGet feeds
  • Example scripts for setup and build

Why use <tt>ci-cd.ps1</tt>

The ci-cd.ps1 script automates essential CI/CD safety and consistency checks for your repository. It ensures:

  • You do not accidentally run deployments from the main branch.
  • There are no uncommitted changes before running CI/CD steps.
  • All git-tracked text files have consistent LF (Unix) line endings, preventing cross-platform issues.
  • Optionally, it can start required containers, run build and test stages, and commit line ending fixes automatically.

Using this script helps maintain a clean, reliable, and reproducible development and deployment workflow, especially in collaborative or cross-platform environments.

How to use <tt>ci-cd.ps1</tt>

  1. Ensure all your work is committed and you are not on the main branch.
  2. Open a PowerShell terminal in the repository root.
  3. Run the script:
    ./ci-cd.ps1
  4. The script will:
    • Check your branch and uncommitted changes.
    • Convert all git-tracked file line endings to LF.
    • Optionally, start containers and run build/test stages (uncomment in the script as needed).
    • Commit any line ending fixes if changes are detected.
    • Push changes to the remote repository.

Note:

  • You can customize which stages are active by commenting/uncommenting lines in the script (e.g., to enable build or test stages).
  • The script requires Docker and Git to be installed and available in your PATH.

For more details, see the comments in ci-cd.ps1.

πŸ“‚ The <tt>.github</tt> Folder

The .github directory contains configuration, automation, and documentation resources that support development workflows and code quality:

  • Copilot Instructions & Agents:
    • .github/copilot-instructions.md defines repository-wide rules for Copilot agents, including Clean Architecture conventions, folder structure, and documentation standards.
    • .github/instructions/ contains detailed instructions and prompts for Copilot agents, such as how to generate or validate domain models, documentation, and code artifacts.
    • Agent prompt files (e.g., dm-artifact.agent.md) provide reusable templates for generating domain model documentation and other artifacts.
  • Workflow & Community Files:
    • GitHub Actions workflows (if present) automate CI/CD, testing, and other tasks.
    • Issue and pull request templates help standardize contributions.
    • Configuration files for repository settings and community standards.

These resources ensure consistency, automate repetitive tasks, and provide guidance for both humans and AI agents working in the repository.

For more details, see the .github/ directory and referenced documentation.

Best Practices

  • Keep source code in src/, tests in tests/.
  • Use environment variables for sensitive data.
  • Update README.md with any new setup or usage instructions.

For more details, see the Microsoft documentation and Clean Architecture guides.

🌐 GitHub Pages & Google Site Verification

If you use GitHub Pages to publish documentation or a project site, you can add a google*.html file (such as googleXXXX.html) to the repository root or the docs/ folder. This file is used by Google for site verification and enables Google Search Console or Analytics to collect statistics about your site.

How to add Google verification:

  • Download the HTML verification file from Google Search Console (it will be named like googleXXXXXXXXXXXX.html).
  • Place the file in the shared/github-pages/ folder.
  • Commit and push the file to your repository.
  • Google will then be able to verify your site and collect statistics.

This is useful for tracking site traffic, indexing, and using other Google webmaster tools with your GitHub Pages site.

πŸ€– Copilot Agents, Instructions and Prompts

The repository also includes Copilot agents, instructions and prompts to assist developers in generating artifacts, code and documentation. These resources can be found in the .github/ directory and are designed to enhance productivity and ensure consistency across projects.

Agent Examples:

Domain Model Agent

Generates, validates, and maintains domain model (DM) documentation in markdown, following strict content, structure, and naming conventions for clarity and consistency. It analyses business case, identifies domain entities and relationships, and produces DM artifacts that align with the project’s domain language and requirements. The agent ensures that DM files are correctly named, versioned, and structured according to the instructions, and it validates the content for completeness and clarity without evaluating quality criteria.

Example Usage:

#dm-artifact.agent.md
Create DM

πŸ“„ License

Distributed under the AGPL-3.0 License.

πŸ“¬ Contact

Jens Tirsvad Nielsen - LinkedIn

Acknowledgements