That aspnetcorev2.dll is actually ASP.NET Core 2.0 Module, commonly called ANCM. This module needs some setup and configuration if the ASP.NET Core 2.0/2.1/2.2 is going to be run on top of IIS and use IIS as the main proxy before going to ASP.NET Core original Kestrel engine, and it's also called out-of-process model.
This is important, on other platforms other than Windows, all request goes directly to Kestrel and served by Kestrel directly. Therefore on IIS, a special configuration setup need to be done to use Kestrel on IIS.
For more information about ANCM on IIS, please consult this official Microsoft Docs:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-2.2
NOTE: although that page is for .NET Core 2.2, it's still applicable for .NET 2.0/2.1.
Based on your error, there's a chance that the ANCM DLL is not within the reach of the resulting DLL of your app. Ensure that the ANCM dll files are within your resulting compiled folder, not outside. Also ensure that you're using RTM or official release version of .NET Core 2.0/2.1/2.2 runtime instead of daily build, because using daily build of .NET Core 2.0/2.1/2.2 may bring some strange errors because their full distribution of runtime DLLs may not be fully coherent.
For more information about troubleshooting ANCM in ASP.NET Core 2.x, please consult this official MS Docs:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.2
UPDATE #1:
Based on comment below, I add this additional info:
you should clear all nuget caches on your machine, restore and run MSBUILD again. If you use .NET Core 2.1 as the platform for your ASP.NET Core 2.1 app, then if you install .NET Core 2.2 without updating references of your app to v2.2, there's a chance that references still mixed up.
Or for better practice, use global.json
file to strict your compilation of your app to always use .NET Core 2.1 SDK with specific version, regardless what is the latest version of .NET Core SDK you have on your machine.
This is also important, because by default compiling .NET Core app will always try to use the latest SDK available on your machine, and previous existing older version will be ignored.
Setting up global.json
is documented here:
https://learn.microsoft.com/en-us/dotnet/core/tools/global-json