Skip to content

Instantly share code, notes, and snippets.

@Deneas
Created November 12, 2020 22:29
Show Gist options
  • Select an option

  • Save Deneas/aae3a25e96b74d2b2f9797e1698f65a5 to your computer and use it in GitHub Desktop.

Select an option

Save Deneas/aae3a25e96b74d2b2f9797e1698f65a5 to your computer and use it in GitHub Desktop.
Merges all .cs files of a project into a single one. Quick and dirty, but it should be enough for programming competition like on Codingame
<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="EnvDte" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="System" #>
<#@ output extension=".generated.cs" #>
namespace SingleFile {
<#
var root = Host.ResolvePath("");
var outputFile = Host.TemplateFile.Substring(0,Host.TemplateFile.Length - 3) + ".generated.cs";
var fileNames = Directory.EnumerateFiles(root, "*.cs", SearchOption.AllDirectories)
.Where(f => !(f.StartsWith(root + "\\bin") || f.StartsWith(root + "\\obj") || f.EndsWith(outputFile)))
.ToList();
foreach(string fileName in fileNames)
{
var text = File.ReadAllText(fileName);
WriteLine(text);
}
#>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment