如何从单个c#项目中提取所有源代码到单个文件?最好不要通过复制粘贴?
答案 0 :(得分:3)
使用命令行
的一种非常简单的方法for %f in (*.cs) do type %f >> result.txt
修改强>
随着递归&档案信息
for /R %f in (*.cs) do echo ----- %f ----- >> result.txt & type %f >> result.txt
答案 1 :(得分:1)
只需从命令行传递解决方案目录的路径。
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());
}
}
}
}
希望它有所帮助!