当你打开一个.net core的项目,Visual Studio 可能无法打开,提示如下错误:
D:\workshop\Github\Ocelot\src\Ocelot\Ocelot.csproj : error : Project file is incomplete. Expected imports are missing.
D:\workshop\Github\Ocelot\test\Ocelot.UnitTests\Ocelot.UnitTests.csproj : error : Project file is incomplete. Expected imports are missing.
D:\workshop\Github\Ocelot\test\Ocelot.AcceptanceTests\Ocelot.AcceptanceTests.csproj : error : Project file is incomplete. Expected imports are missing.
D:\workshop\Github\Ocelot\test\Ocelot.ManualTest\Ocelot.ManualTest.csproj : error : Project file is incomplete. Expected imports are missing.
D:\workshop\Github\Ocelot\test\Ocelot.Benchmarks\Ocelot.Benchmarks.csproj : error : Project file is incomplete. Expected imports are missing.
D:\workshop\Github\Ocelot\test\Ocelot.IntegrationTests\Ocelot.IntegrationTests.csproj : error : Project file is incomplete. Expected imports are missing.
D:\workshop\Github\Ocelot\src\Ocelot\Ocelot.csproj : error : Project file is incomplete. Expected imports are missing.
这个错误的原因是项目通过global.json 指定了项目的SDK版本,比如Ocelot的global.json 指定了2.1.301
{
"projects": [ "src", "test" ],
"sdk": {
"version": "2.1.301"
}
}
我的机器上没有安装这个版本的SDK,解决方法就是安装这个版本的SDK。