В ASP.NET MVC 5 я использовал метод BuildManager.GetReferencedAssemblies()
, чтобы получить все сборки в папке bin и загрузить их до начала зависимости, чтобы все dll были доступны для сканирования и внедрения.
Есть ли альтернатива в ASP.NET Core?
https://docs.microsoft.com/en-us/dotnet/api/system.web.compilation.buildmanager.getreferencedassemblies?view=netframework-4.7.2
Я попробовал этот код, но он запустился, выдает ошибки загрузки, например, исключение файла не найдено.
foreach (var compilationLibrary in deps.CompileLibraries)
{
foreach (var resolveReferencePath in compilationLibrary.ResolveReferencePaths())
{
Console.WriteLine($"\t\tReference path: {resolveReferencePath}");
dlls.Add(resolveReferencePath);
}
}
dlls = dlls.Distinct().ToList();
var infolder = dlls.Where(x => x.Contains(Directory.GetCurrentDirectory())).ToList();
foreach (var item in infolder)
{
try
{
Assembly.LoadFile(item);
}
catch (System.IO.FileLoadException loadEx)
{
} // The Assembly has already been loaded.
catch (BadImageFormatException imgEx)
{
} // If a BadImageFormatException exception is thrown, the file is not an assembly.
catch (Exception ex)
{
}
}