VS2017 .NetCore 2.0 API启动报错:无法加载Microsoft.AspNetCore.Hosting.Abstractions
Hey there, let's work through this issue together. That error about missing Microsoft.AspNetCore.Hosting.Abstractions v2.0.2.0 is a classic one with older ASP.NET Core setups, usually stemming from mismatched package versions or stale build files. Here are the steps to resolve it:
Step 1: Clean up build artifacts and rebuild
Stale files in your bin or obj folders can cause version conflicts. Let's wipe them out and start fresh:
- Manually delete the
binandobjdirectories from your project root. - Run these commands in your project directory:
dotnet clean dotnet build
Step 2: Ensure consistent NuGet package versions
All ASP.NET Core-related packages should target the same version (2.0.2 in this case). Open your .csproj file and check:
- If you're using the meta-package, make sure it's set to 2.0.2:
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.2" /> - If you're referencing individual packages, verify every
Microsoft.AspNetCore.*entry has the sameVersionattribute (e.g., 2.0.2).
Step 3: Verify your .NET Core SDK version
ASP.NET Core 2.0.2 requires a compatible SDK. Check which SDKs you have installed:
dotnet --list-sdks
If you don't see a 2.0.x SDK listed, install the matching .NET Core 2.0 SDK (you can grab this from Microsoft's official site).
Step 4: Clear NuGet cache
Corrupted or outdated cached packages can cause this error. Clear the cache and restore packages again:
dotnet nuget locals all --clear dotnet restore
Step 5: Check your launch configuration
Double-check your Properties/launchSettings.json file to ensure there's no hardcoded path to an old version of the assembly, or incorrect environment settings that might be loading the wrong files.
Most of the time, steps 1 and 2 will resolve the issue right away. If not, work through the rest—one of these should get your template API up and running!
内容的提问来源于stack exchange,提问作者Dries

