错误 NETSDK1004 找不到资产文件 project.assets.json,错误MSB4036 找不到"GetReferenceNearestTargetFrameworkTask"任务



我在这台计算机上在相同的dotnet项目上工作了2-3个月,只有在安装了JetBrains Rider之后,我才感到惊讶。运行dotnet restore没有输出任何内容,运行dotnet builddotnet watch build或类似的东西输出错误,内容如下:

error NETSDK1004: Assets file project.assets.json not found. Run a NuGet package restore to generate this file.

最糟糕的是dotnet build因错误而失败,但msbuild在同一项目上运行,成功地构建了该项目(弄清楚尝试msbuild也花费了相当长的时间(。这似乎很疯狂,并不能解释任何事情。

通过重新安装累积的所有 10 个左右的 .NET Core SDK 版本进行摆弄后,没有任何变化。但我认为卸载 Rider 后我开始收到另一个错误:

C:Program Files (x86)Microsoft Visual Studio2019BuildToolsMSBuildCurrentBinMicrosoft.Common.CurrentVersion.targets(1655,5): error MSB4036: The "GetReferenceNearestTargetFrameworkTask" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:Program Files (x86)Microsoft Visual Studio2019BuildToolsMSBuildCurrentBin" directory. 

tl;博士: 删除了此环境变量:

MSBUILD_EXE_PATH
C:Program Files (x86)Microsoft Visual Studio2019BuildToolsMSBuildCurrentBinMSBuild.exe

所有dotnetCLI 命令都再次开始工作。 它是如何到达那里的——我不知道,可能是 Rider 把它添加到那里的。但是我打开了两个CMD窗口,直到您重新启动CMD,它才具有相同的环境变量。

设置MSBUILD_EXE_PATH的那个有错误,没有设置的那个没有错误并且工作正常。

我希望这能帮助人们不要因为到处寻找而不了解正在发生的事情而浪费一天半的工作。

相关内容

最新更新