从@ Luaan建议使用预构建步骤创建单个压缩文件夹我创建了一个基本控制台应用程序,将源文件打包到特定位置的压缩文件中。
static void Main(string[] args)
{
Console.WriteLine("Takes a folder of .cs files and flattens and compacts them into a .zip." +
"Arg 1 : Source Folder to be resursively searched" +
"Arg 2 : Destination zip file" +
"Arg 3 : Semicolon List of folders to ignore");
if (args[0] == null || args[1] == null)
{
Console.Write("Args 1 or 2 missing");
return;
};
string SourcePath = args[0];
string ZipDestination = args[1];
List<String> ignoreFolders = new List<string>();
if (args[2] != null)
{
ignoreFolders = args[2].Split(';').ToList();
}
var files = DirSearch(SourcePath, "*.cs", ignoreFolders);
Console.WriteLine($"{files.Count} files found to zip");
if (File.Exists(ZipDestination))
{
Console.WriteLine("Destination exists. Deleting zip file first");
File.Delete(ZipDestination);
}
int zippedCount = 0;
using (FileStream zipToOpen = new FileStream(ZipDestination, FileMode.OpenOrCreate))
{
using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Create))
{
foreach (var filePath in files)
{
Console.WriteLine($"Writing {Path.GetFileName(filePath)} to zip {Path.GetFileName(ZipDestination)}");
archive.CreateEntryFromFile(filePath, Path.GetFileName(filePath));
zippedCount++;
}
}
}
Console.WriteLine($"Zipped {zippedCount} files;");
}
static List<String> DirSearch(string sDir, string filePattern, List<String> excludeDirectories)
{
List<String> filePaths = new List<string>();
foreach (string d in Directory.GetDirectories(sDir))
{
if (excludeDirectories.Any(ed => ed.ToLower() == d.ToLower()))
{
continue;
}
foreach (string f in Directory.GetFiles(d, filePattern))
{
filePaths.Add(f);
}
filePaths.AddRange(DirSearch(d, filePattern, excludeDirectories));
}
return filePaths;
}
需要3个参数为源目录,输出压缩文件和一个“;”要排除的路径的分隔列表。我刚把它建成二进制文件。致力于简化源代码管理,并将其纳入为我希望源代码的项目进行的预生成。
没有错误检查真的,我敢肯定它会失败的失踪参数。但如果有人想要它。这里是!再次感谢@Luaan澄清PDB并不是那么有用!
保留注释和整个源代码是一个目标。我希望围绕这个功能提出任何问题以保证行准确性。所以保持评论/本地人完好是可取的。感谢您澄清PDB不包含任何来源。我知道这是异常代码跟踪所必需的。但认为它被包括在内。 (我完全知道该DLL不包含任何来源:-P) –
@ BenFord它不是必需的异常跟踪本身。你将会看到的主要区别是没有PDB,你会得到一个类似这样的东西:'MyClass.MyMethod + 234',而使用PDB时,你会得到'MyClass.MyMethod:38'。在第一种情况下,数字是一个IL字节偏移量,在第二种情况下,它是一行代码。所以PDB使得调试变得更容易,但在生产中实际上并不需要,特别是如果您保留所有“生产”PDB的备份。我不知道如何轻松地从IL偏移量到行,但我只是使用WinDbg。 – Luaan