DotnetMinimalHostingModelGenerator
is a command-line tool designed to help developers transition their ASP.NET Core applications to the modern minimal hosting model. This tool reads a traditional Startup.cs
file and generates a new Program.cs
file that adheres to the minimal hosting model introduced in .NET 6 and later.
- Transform
Startup.cs
: Converts the contents of a traditionalStartup.cs
file to a minimal hosting model format. - Customizable Output: Allows specifying the directory where the new
Program.cs
file will be saved. - Validation: Ensures the specified
Startup.cs
file and output directory exist before proceeding.
-
Clone the Repository
git clone <repository-url> cd DotnetMinimalHostingModelGenerator
-
Build the Tool
dotnet build
-
Install as a Global Tool (Optional)
dotnet pack dotnet tool install --global --add-source ./nupkg DotnetMinimalHostingModelGenerator
Or launch the script "tool_install.sh" available in the folder.
-
Open a terminal.
-
Run the tool with the following syntax (if installed globally):
minimal-hm-generator transform --startup-file <path-to-Startup.cs> --output-file-path <output-directory>
Example:
minimal-hm-generator transform --startup-file ./Startup.cs --output-file-path ./Output/
Option | Description | Example |
---|---|---|
--startup-file |
The path to the Startup.cs file to transform. |
--startup-file ./Startup.cs |
--output-file-path |
The directory where Program.cs will be saved. |
--output-file-path ./Output/ |
- The specified
Startup.cs
file must exist. Otherwise, an error will be shown:Startup file './Startup.cs' does not exist.
- The specified output directory must exist. Otherwise, an error will be shown:
Output file path './Output/' does not exist.
Running the tool successfully will output a message like:
Successfully transformed ./Startup.cs
The generated file will be called "NewProgram.cs" and will be located in the specified output directory.
- 0: Successful operation.
- 1: Errors during validation or transformation.
Contributions are welcome! Please submit issues or pull requests to improve the tool.
This tool is open source and distributed under the MIT License. See the LICENSE
file for details.