if (File.Exists(targetAssembly))
{
var name = AssemblyName.GetAssemblyName(targetAssembly);
Assembly.Load(name);
}
instead of Assembly.LoadFrom.
LoadFrom is not great because it loads into the LoadFrom context and has other repercussions. You almost always want to load assemblies using the trick above.
Here:
https://github.com/Microsoft/MSBuildLocator/blob/master/src/MSBuildLocator/MSBuildLocator.cs#L75
consider using:
instead of Assembly.LoadFrom.
LoadFrom is not great because it loads into the LoadFrom context and has other repercussions. You almost always want to load assemblies using the trick above.
GetAssemblyName stashes the full path to the assembly in the _Codebase field:
http://referencesource.microsoft.com/#mscorlib/system/reflection/assemblyname.cs,45
It is then used as a hint to the loader to load it from that location.
cc @davkean