public string ResolveAssemblyReference(string assemblyReference)
{
var relative = ResolveFilePathPrivate(assemblyReference);
if (File.Exists(relative))
{
return relative;
}
// try to load the assembly
try
{
// Well yes it's obsolete, but see http://stackoverflow.com/questions/11659594/load-latest-assembly-version-dynamically-from-gac
// for the alternatives
// - use all versions -> not possible here
// - PInvoke -> bad and not cross plat
// - Specifying the GAC directories directly -> bad
var ass = Assembly.LoadWithPartialName(assemblyReference);
if (ass != null && !string.IsNullOrEmpty(ass.Location))
{
Source.TraceEvent(TraceEventType.Verbose, 0, "Could resolve the given string to an assembly: {0}", ass.Location);
return ass.Location;
}
throw new ArgumentException(Resources.VisualStudioTextTemplateHost_ResolveAssemblyReference_we_could_load_the_given_assembly_but_cannot_resolve_it_to_a_path_);
}
catch (Exception e)
{
Source.TraceEvent(TraceEventType.Verbose, 0, Resources.VisualStudioTextTemplateHost_ResolveAssemblyReference_Error__Could_not_load_Assembly___0_, e);
return assemblyReference;
}
}