生成 C# 项目时找不到 MSBuild 15,找不到"Microsoft.Common.props"



我目前正在尝试构建一个 C# 项目,但 MSBuild 失败并显示:

C:Program Filesdotnetsdk2.1.401SdksMicrosoft.NET.SdkSdkSdk.props(33,11): error MSB4226: The imported project "C:Program FilesMSBuild15.0Microsoft.Common.props" was not found. Also, tried to find "15.0
Microsoft.Common.props" in the fallback search path(s) for $(MSBuildExtensionsPath) - "C:Program Files (x86)MSBuild" . These search paths are defined in "C:Program FilesMonolibmonomsbuild15.0binMSBuild.d
ll.config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths.

我的.csproj如下所示:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
<AssemblyName>MyProj</AssemblyName>
<PackageId>MyProj</PackageId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>

我在使用 CentOS 中安装的视觉代码时遇到了类似的问题。我尝试了所有方法,但问题没有解决。我所做的只是找到了我的dotnetsdk path,然后尝试在文件夹中找到"Microsoft.Common.Props"。在我的情况下,sdK 文件夹是:

/usr/share/dotnet/sdk

令人惊讶的是,我在/usr/share/dotnet/sdk/2.2.203/Current文件夹中找到了这个文件,而不是/usr/share/dotnet/sdk//2.2.203/15.0/。所以,我所做的只是将文件复制并粘贴到/usr/share/dotnet/sdk//2.2.203/15.0/位置,问题立即消失了!

最新更新