How can I programmatically get the path of "System.Core.dll" using VB.NET?
Is there is a way 开发者_Go百科to get the path of "System.Core.dll" assembly or any other assembly rather than the executing one?
If you know of a type that exists in the assembly, you could use Type.Assembly
to get a reference to the containing assembly. Then it's just a matter of getting its Location
property.
In this specific case, you could do (sorry that this in C#):
//The Enumerable class is in System.Core
typeof(System.Linq.Enumerable).Assembly.Location
A more general solution for an assembly for which you do not know of a particular contained-type but do know has been loaded into the current AppDomain would be something like (untested):
AppDoman.CurrentDomain
.GetAssemblies()
.Single(assembly => assembly.GetName().Name == mySimpleName)
.Location
Otherwise, there's no easy solution. You've got to figure out where to probe for the assembly of interest.
EDIT: Fully qualified Enumerable
for clarity.
精彩评论