0
是否可以使用程序集属性将信息添加到AssemblyInfo.cs
assembly:MyProjectAssembly,
托管的可扩展框架和AssemblyInfo.cs
因此,当MEF扫描rutime文件夹中的程序集时,它只会扫描用MyProjectAssembly
装饰的程序集。
是否可以使用程序集属性将信息添加到AssemblyInfo.cs
assembly:MyProjectAssembly,
托管的可扩展框架和AssemblyInfo.cs
因此,当MEF扫描rutime文件夹中的程序集时,它只会扫描用MyProjectAssembly
装饰的程序集。
我不认为MEF具有此功能。但我不是100%确定的。
你可以做的是使用Mono.Cecil,一个非常强大的替代System.Reflection。 Mono.Cecil
允许你检查(并重写,但这是另一个故事).NET程序集没有加载它们。这意味着你可以轻松地添加你正在寻找的功能。例如:
public static bool AssemblyIncludesCustomAttribute(string assemblyPath, string customAttributeName)
{
if (assemblyPath == null) throw new ArgumentNullException("assemblyPath");
if (customAttributeName == null) throw new ArgumentNullException("customAttributeName");
AssemblyDefinition assemblyDef = AssemblyDefinition.ReadAssembly(assemblyPath);
return assemblyDef.CustomAttributes.Any(ca => ca.AttributeType.FullName == customAttributeName);
}
然后使用它是这样的:
var catalog = new AggregateCatalog();
string dirPath = @".\Extensions";
foreach (string assemblyFile in Directory.EnumerateFiles(dirPath, "*.dll"))
{
if (AssemblyIncludesCustomAttribute("Blah.dll", "System.Reflection.AssemblyConfigurationAttribute"))
{
catalog.Catalogs.Add(new AssemblyCatalog(assemblyFile));
}
}