有一个相当大的项目,将近十几个程序集添加到 shell 中,其他程序集通过配置添加
试图找到一种更好的方法来添加项目中引用的程序集
目前的代码是这样的
Dictionary<string,string> dict = new Dictionary<string,string>(); // to avoid duplicate parts
foreach (Assembly an in AppDomain.CurrentDomain.GetAssemblies())
addAssembly(an, dict);
foreach (AssemblyName an in Assembly.GetEntryAssembly().GetReferencedAssemblies())
addAssembly(an, dict);
foreach (AssemblyName an in GetAsmInConfig())
addAssembly(an, dict);
即便如此,并非所有在设计时引用到 Shell 的程序集都添加到目录中
想知道除了将所有程序集添加到配置中是否还有其他方法可以解决问题
更新
void addAssembly(Assembly a, Dictionary<string, string> dict)
{
if (a.IsDynamic || dict.ContainsKey(a.FullName))
return;
dict.Add(a.FullName, a.FullName);
AggregateCatalog.Catalogs.Add(new AssemblyCatalog(a));
}
最佳答案
编译器将删除对未实际使用的引用,因此您不能依赖它作为枚举程序集的机制。 您的选择是:
- 使用配置文件
- 使用目录目录
关于c# - 使用 MEF 将程序集添加到目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9654930/