How can I get an assembly that isn't referenced in my project?
I'm trying to get a list of assemblies for NHibernate to scan. I'm using some s开发者_C百科ample code from a tutorial application:
IEnumerable<AssemblyName> enumerable = GetType().Assembly.GetReferencedAssemblies()
.Where(name => name.Name.StartsWith(assemblyPrefix));
foreach (var assemblyName in enumerable)
x.Assembly(assemblyName.Name);
So there are 3 projects: ProjectName, ProjectName.Services, and ProjectName.Data.
The problem is that the assembly that is configuring NHibernate doesn't actually use the Services project. I thought just adding a project reference would work, but it doesn't.
Is there any way to make my project reference Services, or should I just hardcode the assembly names in the configuration?
How about AppDomain.CurrentDomain.GetAssemblies()
(docs)? That should return all the loaded assemblies, which would include ProjectName.Services even if the assembly you're calling this from doesn't use it, as long as it's used somewhere else (I think it additionally must already be loaded too).
精彩评论