Keeping Up With Castle
Posted on August 6, 2008I've gotten used to building off of the trunk. However, I can never remember every single assembly that Castle.ActiveRecord.dll and NHibernate.dll need nearby. If I create new projects using those tools, I usually put the required assemblies in a lib folder within the solution I'm building, then any project in the solution references the assemblies in lib(and not the gac or anywhere else).
To help me just copy all referenced assemblies those two assemblies require, I wrote a little snippet to help(you can run this straight out of snippetcompiler):
public void RunSnippet(){
string sourceDir = @"C:\svn\castle\trunk\build\net-3.5\debug\";
string[] targetAssemblies = new String[]{ "Castle.ActiveRecord.dll", "NHibernate.dll" };
List<string> baseFileNames = new List<string>();
//add the two assemblies we're starting with
baseFileNames.Add("Castle.ActiveRecord");
baseFileNames.Add("NHibernate");
//get a distinct list of referenced assemblies for all targetAssemblies
foreach(string targetAssembly in targetAssemblies){
Assembly asses = Assembly.LoadFrom(Path.Combine(sourceDir, targetAssembly));
foreach(AssemblyName ass in asses.GetReferencedAssemblies()){
if (ass.Name.StartsWith("System"))
continue;
if (File.Exists(Path.Combine(sourceDir, ass.Name + ".dll")))
baseFileNames.Add(ass.Name);
}
}
//get a list of file names that match the ref assemblies regardless of file extension; so
//basically we want not only .dll, but .xml and .pdb files as well(and anything else that matches)
List<string> files = new List<string>();
foreach(string baseFileName in baseFileNames){
foreach(string f in Directory.GetFiles(sourceDir, baseFileName + ".*")){
if (!files.Contains(f))
files.Add(new FileInfo(f).Name);
}
}
//copy everything from source to destination, overwriting if we need to
string destDir = @"C:\dev\Awish.Security\lib";
foreach(string file in files){
File.Copy(Path.Combine(sourceDir, file), Path.Combine(destDir, file), true);
}
}
| |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|