You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET Core项目改为.NET Framework 4.7后无法运行VS测试

Fixing Test Project Issues for Your .NET Framework 4.7 API

Hey there, I’ve run into this exact scenario before—when you switch your main project from .NET Core to .NET Framework, the test projects need to play by the same rules to work properly. Let’s break down the fixes step by step:

  • Match the target framework in your test project
    The biggest mistake here is keeping the test project targeted at .NET Core while your main project is on net47. Either create a new test project specifically for .NET Framework (look for options like "NUnit Test Project (.NET Framework)" in the Visual Studio template selector), or edit your existing test project’s .csproj file to set:

    <TargetFramework>net47</TargetFramework>
    

    Make sure this matches the target framework of your API project exactly.

  • Verify NuGet packages for testing frameworks
    For NUnit, you’ll need these packages installed in your test project (compatible with net47):

    • NUnit (v3.x works great with net47)
    • NUnit3TestAdapter (this lets Visual Studio detect and run NUnit tests)
      If you were using xUnit or MS Test, install their respective .NET Framework-compatible packages and adapters too—skip the .NET Core-specific ones.
  • Clean up and rebuild your solution
    Sometimes stale build artifacts cause the test runner to hang. Go to Build > Clean Solution, then delete the bin and obj folders from both your API and test projects manually. Rebuild the entire solution afterwards.

  • Check Visual Studio’s test runner settings
    Head to Test > Settings > Test Settings and make sure you haven’t accidentally excluded .NET Framework tests. Also, if you’re on an older version of Visual Studio, update to the latest stable release—some older versions have bugs with running .NET Framework tests alongside former .NET Core projects.

  • Test via command line to rule out IDE issues
    If clicking "Run Tests" still does nothing, try running tests from the command line. For NUnit, use:

    dotnet test
    

    Or use the Visual Studio test console:

    vstest.console.exe YourTestProject.dll
    

    This will spit out error messages if there’s an underlying configuration problem that the IDE isn’t showing you.

  • Double-check project references
    Ensure your test project has a valid reference to your API project. Sometimes when switching frameworks, the reference can break—remove and re-add it if needed, and confirm the API project builds successfully on its own.

内容的提问来源于stack exchange,提问作者Alex 75

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:12:46