jeudi 4 novembre 2021

Microsoft libraries missing when compiling .NET5 project

I'm trying to decompile ASP.NET Core WebApi project and gather all methods from all controllers. When my project targeted .NETCore3.1 it worked by running this code:

Assembly assembly = Assembly.LoadFrom(assemblyPath); // assemblyPath pointed to .dll
var types = assembly.GetExportedTypes();

But after updating to .NET5, the second line (assembly.GetExportedTypes()) from above throws an exception that file Microsoft.AspNetCore.Mvc.Core.dll is missing. When I copied that file manually from an old project (compiled as .NETCore3.1), it worked!

On the top of that, when project is more complicated, has EFCore dependency and more... more files are missing when compiling the project under .NET5. These are:

  • Microsoft.Extensions.Hosting.Abstractions.dll
  • Microsoft.AspNetCore.Mvc.Abstractions.dll
  • Microsoft.AspNetCore.Authentication.Abstractions.dll

I have two questions:

  • Why these files are not copied to the output folder?
  • How can I properly read all endpoints/methods in Controllers having complied binaries of the ASP.NET WebApi? Am I doing something wrong?

Steps to reproduce:

  • Create ASP.NET Core WebApi project targeting .NET5.
  • Create other project that targets .NET5 and implement these two lines:
var assemblyPath = "C:\\Projects\\Other\\DotNet5Test\\DotNet5Test\\DotNet5Test.WebApi\\bin\\Debug\\net5.0\\DotNet5Test.WebApi.dll";
Assembly assembly = Assembly.LoadFrom(assemblyPath); 
var types = assembly.GetExportedTypes();
  • Run it

EDIT:

I tried adding Microsoft.AspNetCore.Mvc.Core from nuget, but Microsoft.AspNetCore.Mvc.Core.dll is not being added to the output folder





Aucun commentaire:

Enregistrer un commentaire