我正在Windows 10计算机上导入.NET核心项目。这是一个带有mvc项目和一个测试项目的解决方案。 omnisharp加载时会引发多个错误。
第一个:
movie-data\imdb_id_retrieval\imdb_id_retrieval.csproj(0,0): Error: Version 2.2.203 of the .NET Core SDK requires at least version 16.0.0 of MSBuild. The current available version of MSBuild is 15.9.21.664. Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.
好的,所以我更新了Visual Studio以确保我拥有MSBuild 16.0。要再次检查,我运行了
C:\Users\mcdonago\source\repos\movie-data> dotnet msbuild -version
Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
16.0.450.56488
PS C:\Users\mcdonago\source\repos\movie-data>
当omnisharp启动时仍然出现此错误。
第二个错误:
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found. c:\Users\mcdonago\source\repos\movie-data\imdb_id_retrieval\imdb_id_retrieval.csproj
人们建议我得到最新的SDK。
PS C:\Users\mcdonago\source\repos\movie-data> dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 2.2.203
Commit: e5bab63eca
Runtime Environment:
OS Name: Windows
OS Version: 10.0.16299
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.203\
Host (useful for support):
Version: 2.2.4
Commit: f95848e524
.NET Core SDKs installed:
2.2.203 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
PS C:\Users\mcdonago\source\repos\movie-data>
只有一个sdk,它是最新的。人们建议我将Project sdk引用更改为“ Microsoft.Net.Sdk”,而不是“ Microsoft.Net.Sdk.Web”。这样可以让omnisharp成功加载问题,但随后我遇到了很多错误,例如
The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) (CS0246) [imdb_data_retrieval_test]
这似乎又是另外一堆问题。
请注意,我的两个项目均已编译并成功运行,所以让我认为这与omnisharp有关吗?另外,在我的带有vs代码的linux计算机上,它也可以正常工作。任何帮助,将不胜感激。我已经花了好几个小时不停地尝试着很多事情,但是无法使用vs代码来解决这个问题。
编辑: 这是我的.csproj文件。
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.9.1" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
</ItemGroup>
</Project>
-
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.0" />
<PackageReference Include="moq" Version="4.10.1" />
<PackageReference Include="nunit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\imdb_id_retrieval\imdb_id_retrieval.csproj" />
</ItemGroup>
</Project>
答案 0 :(得分:1)
我不知道是什么原因引起的,您的设置看起来还不错,只有一些备注
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
不必要,因为Microsoft.AspNetCore.App
应该包括所有依赖项。
另外,您应该not have the version specified in the reference,所以它看起来应该像
<PackageReference Include="Microsoft.AspNetCore.App" />
据我所知,您的主要项目(第一个csproj)是有问题的项目吗?我在更改Net Core版本时遇到了一些麻烦,因为某些库在新版本中无法按预期工作,您还可以创建一个新项目并一次添加一个依赖项,在更改之间进行编译(您可以使用一个简单的空项目来完成此工作),因此您可以丢弃是否是引起问题的某个库。
例如,这是我们的csproj之一
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0" />
<PackageReference Include="Prometheus.Client.AspNetCore" Version="2.2.0" />
<PackageReference Include="Prometheus.Client.HttpRequestDurations" Version="1.2.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="System.Net.Primitives" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\vtae.common\vtae.common.csproj" />
<ProjectReference Include="..\vtae.data\vtae.data.csproj" />
<ProjectReference Include="..\vtae.integrations\vtae.integrations.csproj" />
</ItemGroup>
</Project>
还要检查您是否具有global.json配置文件以及该版本是否正确
答案 1 :(得分:0)
它也可能在您的app.Start.cs服务部分中,请尝试 services.AddMvc()。SetCompatibilityVersion(CompatibilityVersion.Version_2_2);