【发布时间】:2010-08-25 14:20:10
【问题描述】:
所以我最近一直在做的事情是在我的代码解决方案中添加一个额外的项目,并在其中以编程方式完成我的后期构建工作。此项目最后构建,然后自行启动。
我可以在那里做的很酷的事情是运行我创建的 ILMerge 自动化类,如果我只是给它一个项目文件夹、在我的程序集信息中增加版本号、将文件复制到我想要的任何位置等等等等,它就会自动执行合并。在我看来,这里的可能性是无穷无尽的。
我现在正在使用的一个示例——我有一个相当大的框架库,我将与我们的一个应用程序一起部署它,但我们不想单独包含所有 dll(有20个)。此外,对于这个应用程序,我不需要库中的每个类,所以修剪它是有意义的。在图书馆的后期构建项目中,我正在这样做......
outputDirectory = new DirectoryInfo(@"...postbuildmerges\output");
solutionDirectory = new DirectoryInfo(@"...mainSolutionDirectory");
#region Web Lib
List<string> webLibraryNames = new List<string>
{
"Lib.Configuration",
"Lib.Web",
"Lib.Data",
"Lib.Utilities",
"Lib.Threading"
};
List<string> AllNeededAssemblies = new List<string>();
webLibraryNames.ForEach((libname) =>
{
foreach (string assembly in GetLibraryAssemblies(libname))
if (AllNeededAssemblies.Exists((assemblyName) => Path.GetFileName(assemblyName) == Path.GetFileName(assembly)) == false)
AllNeededAssemblies.Add(assembly);
});
SharpMergeAutomator.Merge(
@"...path to primary assembly...",
AllNeededAssemblies.ToArray(),
"...desired output file...",
//merges xml documentation
true);
#endregion
那么这个后期构建项目是一个好方法吗?它是不必要的复杂吗?有没有更好的办法?人们通常会做这样的事情吗?
【问题讨论】:
标签: c# .net visual-studio build-process