Quellatalo.CombineCode.CSharp
0.3.1
See the version list below for details.
dotnet add package Quellatalo.CombineCode.CSharp --version 0.3.1
NuGet\Install-Package Quellatalo.CombineCode.CSharp -Version 0.3.1
<PackageReference Include="Quellatalo.CombineCode.CSharp" Version="0.3.1" />
<PackageVersion Include="Quellatalo.CombineCode.CSharp" Version="0.3.1" />
<PackageReference Include="Quellatalo.CombineCode.CSharp" />
paket add Quellatalo.CombineCode.CSharp --version 0.3.1
#r "nuget: Quellatalo.CombineCode.CSharp, 0.3.1"
#:package Quellatalo.CombineCode.CSharp@0.3.1
#addin nuget:?package=Quellatalo.CombineCode.CSharp&version=0.3.1
#tool nuget:?package=Quellatalo.CombineCode.CSharp&version=0.3.1
Quellatalo.CombineCode.CSharp
A library to combine multiple written CSharp source files into one file.
Author: Quellatalo Nin
Overview
The project is still in early stage. It does not scan the local folders as much as IDEs/compilers do.
Please see the requirements to follow the expected code style.
Usage
const string TransformedFile = "Transformed.cs";
CSharpSourceInfo sourceInfo = CSharpSourceInfo.ReadFromFile("Path/To/File.cs");
// combine the targeted source file and its dependencies to one string.
string combinedCode = sourceInfo.CompileToOneSource();
// remove unused methods, xml comments
var trimmedSyntax = await CSharpSyntaxTree.ParseText(combinedCode).TrimUnusedCodeAsync().ConfigureAwait(false);
// compile the code
SimpleCSharpCompiler compiler = new();
var emitResult = compiler.Compile(TransformedFile, out memoryStream);
// utilize the diagnostics to identify unused using directives
var unusedSpans = emitResult.Diagnostics.Where(d => d.Id == "CS8019")
.Select(d => d.Location.SourceSpan.Start)
.ToHashSet();
// remove the unused using directives
trimmedSyntax = trimmedSyntax.RemoveMembers(unusedSpans);
// write to file
await File.WriteAllTextAsync(TemporaryCodeFile, trimmedCode.ToFullString()).ConfigureAwait(false);
// open the newly written file by using the OS's default behavior
FileUtils.OpenFile(TransformedFile);
Please visit the project repository to see some examples.
Requirements
It's just some standard styling rules:
- SA1402FileMayOnlyContainASingleType
- SA1649FileNameMustMatchTypeName
- IDE0130: Namespace does not match folder structure
Basically, namespaces should have matching folders, and types should have matching .cs files.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 5.3.0)
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 | |
|---|---|---|---|
| 0.3.2 | 23 | 5/7/2026 | |
| 0.3.1 | 112 | 4/28/2026 | |
| 0.3.0 | 548 | 12/9/2025 | |
| 0.2.1 | 281 | 10/28/2025 | |
| 0.2.0 | 409 | 3/21/2025 | |
| 0.1.4 | 282 | 2/18/2025 | |
| 0.1.3 | 212 | 1/20/2025 | |
| 0.1.2 | 177 | 1/17/2025 | |
| 0.1.1 | 241 | 1/11/2025 | |
| 0.1.0 | 275 | 12/17/2024 | |
| 0.0.9 | 226 | 12/10/2024 | |
| 0.0.8 | 215 | 11/13/2024 | |
| 0.0.7 | 200 | 11/1/2024 | |
| 0.0.6 | 256 | 10/16/2024 | |
| 0.0.5 | 197 | 10/14/2024 | |
| 0.0.4 | 198 | 10/14/2024 | |
| 0.0.3 | 204 | 10/14/2024 | |
| 0.0.2 | 192 | 10/11/2024 | |
| 0.0.1 | 218 | 10/8/2024 |
**Changed**
- Improved TrimUnusedCodeAsync
- Provide RemoveMembers method