Kros.SingleCsFileGenerator 1.0.2

dotnet add package Kros.SingleCsFileGenerator --version 1.0.2
                    
NuGet\Install-Package Kros.SingleCsFileGenerator -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kros.SingleCsFileGenerator" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Kros.SingleCsFileGenerator" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Kros.SingleCsFileGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Kros.SingleCsFileGenerator --version 1.0.2
                    
#r "nuget: Kros.SingleCsFileGenerator, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Kros.SingleCsFileGenerator@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Kros.SingleCsFileGenerator&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Kros.SingleCsFileGenerator&version=1.0.2
                    
Install as a Cake Tool

Kros.SingleCsFileGenerator

MSBuild task that merges standard C# project with multiple files into a single file compatible with .NET 10's file-based apps feature.

.NET 10 introduced the ability to run single C# files directly using dotnet run app.cs, but these single files cannot reference other source files. This tool allows you to develop a more complex multi-file project, then generate a single file from it. This can be used in DevOps pipelines, automation scripts, or anywhere you need a single-file C# script.

Installation

Add the NuGet package to your project:

dotnet package add Kros.SingleCsFileGenerator

Usage

Enable the task in your .csproj file:

<PropertyGroup>
  <GenerateCSharpSingleFile>true</GenerateCSharpSingleFile>
</PropertyGroup>

The task runs automatically after compilation and generates a single file containing all your C# source files with namespaces removed and using statements consolidated.

By default, the output file is created at bin/SingleFile/{ProjectName}.cs. For example, project Kros.App will create bin/SingleFile/Kros.App.cs.

Custom output location

You can customize the output folder and/or filename:

<PropertyGroup>
  <GenerateCSharpSingleFile>true</GenerateCSharpSingleFile>
  <CSharpSingleFileOutputFolder>custom/path</CSharpSingleFileOutputFolder>
  <CSharpSingleFileOutputFileName>MyScript.cs</CSharpSingleFileOutputFileName>
</PropertyGroup>
Property Default Value Description
CSharpSingleFileOutputFolder bin/SingleFile Output folder for the generated file.
CSharpSingleFileOutputFileName MyScript.cs Name of the generated file.

Development

NuGet package of Kros.SingleCsFileGenerator is generated automatically during build in the nupkg thisfolder at the solution level. This folder is also set as local NuGet source. Project Kros.SingleCsFileGenerator.Demo references Kros.SingleCsFileGenerator NuGet and is configured to reference latest version including prereleases. If you (re)build solution, single files app Kros.SingleCsFileGenerator.Demo.cs is generated in Kros.SingleCsFileGenerator.Demo/bin/SingleFile folder.

To make changes to Kros.SingleCsFileGenerator and test them in the demo project, you have always use new version of the generator. The simplest way is temporarily change version in Kros.SingleCsFileGenerator.csproj file:

<PropertyGroup>
	<VersionSuffix>$([System.DateTime]::UtcNow.ToString('yyyyMMdd.HHmmss'))</VersionSuffix>
</PropertyGroup>

This way, you will have new version of NuGet for every build and demo project will automatically restore and use it.

If you want to test just the generation of single file without creating new NuGet package, you can use Kros.SingleCsFileGenerator.Runner – and you can run it as single file application. 😉 It has two mandatory arguments. First is path to project (.csproj file) to generate single file from and second is output path for generated single file. You can use any project you want, not just demo project in this solution.

dotnet run ./Kros.SingleCsFileGenerator.Runner.cs ../Kros.SingleCsFileGenerator.Demo/Kros.SingleCsFileGenerator.Demo.csproj ../test.cs
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 208 12/14/2025