Reputation: 2717
How to extract all source code from a single c# project to a single file? Preferably not by copy-paste?
Upvotes: 4
Views: 1194
Reputation: 8129
a very simple approach with the command line
for %f in (*.cs) do type %f >> result.txt
EDIT:
With recursion & file info
for /R %f in (*.cs) do echo ----- %f ----- >> result.txt & type %f >> result.txt
Upvotes: 3
Reputation: 2832
Simply pass in the path to the solution directory from the command line.
class Program
{
static StringBuilder builder = new StringBuilder();
static void Main(string[] args)
{
if (args.Length == 0)
return;
string directory = args[0];
ProcessDirectories(directory);
// Save file here
}
static void ProcessDirectories(string root)
{
ProcessDirectory(new DirectoryInfo(root));
var subDirectories = Directory.GetDirectories(root);
if (subDirectories.Length == 0)
return;
foreach (var subDirectory in subDirectories)
{
ProcessDirectories(subDirectory);
}
}
static void ProcessDirectory(DirectoryInfo directory)
{
foreach (var file in directory.EnumerateFiles())
{
builder.AppendFormat("----- {0} -----", file.FullName);
using (var reader = file.OpenText())
{
builder.AppendLine(reader.ReadToEnd());
}
}
}
}
Hope it helps!
Upvotes: 1