简体   繁体   English

缺少 Nuget.targets

[英]Missing Nuget.targets

I'm net with C# and Visual Studio 2017. It seems that VS says that Nuget packages are missing.我很熟悉 C# 和 Visual Studio 2017。似乎 VS 说缺少 Nuget 包。 When I'm trying to build the solution the console outputs the following:当我尝试构建解决方案时,控制台输出以下内容:

"This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105 . The missing file is D:\\xxxx\\xxxx\\Desktop\\Koodipohjaa\\trunk\\.nuget\\NuGet.targets" “此项目引用了此计算机上缺少的 NuGet 包。启用 NuGet 包还原以下载它们。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkID=322105 。丢失的文件是D:\\xxxx\\xxxx\\Desktop\\Koodipohjaa\\trunk\\.nuget\\NuGet.targets"

The project is copied from the original location to the desktop (because reasons).项目从原始位置复制到桌面(因为原因)。 In /trunk/ I have a folder called "packages" but no ".nuget" folder.在 /trunk/ 中,我有一个名为“packages”的文件夹,但没有“.nuget”文件夹。 I've tried the "restore nuget packages" from the solution level and it says that there is nothing to update.我已经尝试了解决方案级别的“恢复 nuget 包”,它说没有什么可更新的。 When I open the references from the project, there is this very cute little yellow triangle with all the packages.当我打开项目的参考资料时,有一个非常可爱的黄色小三角形,里面有所有的包。

I've tried to update packages, remove them all and reinstalling them automatically etc. In "nuget package manager" I have tried all possible in package restore.我尝试更新包,将它们全部删除并自动重新安装等。在“nuget 包管理器”中,我尝试了所有可能的包恢复。

Please try:请尝试:

1.In VS2017,go Tools menu=>Nuget Package Manager=>Package Manager settings, make sure you've checked these two options like this: 1.在VS2017中,进入Tools menu=>Nuget Package Manager=>Package Manager settings,确保你已经勾选了这两个选项,如下所示:

在此处输入图片说明

2.Right-click the project in Solution Explorer=> Unload Project => Right-click the project name and Edit the xx.csproj , you will find a EnsureNuGetPackageBuildImports target in this format: 2.在解决方案资源管理器中右键单击项目=> Unload Project =>右键单击项目名称并Edit the xx.csproj ,您将找到以下格式的EnsureNuGetPackageBuildImports目标:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\xxx')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\xxx'))" />
  </Target>

Delete the target and save files.删除目标并保存文件。 Then right-click the project to reload the project and run a rebuild.然后右键单击该项目以重新加载该项目并运行重建。

I assume you may have such target in your project file(xx.csproj), which tries to find the nuget.targets file, delete the target to check if it helps.我假设你的项目文件(xx.csproj)中可能有这样的目标,它试图找到nuget.targets文件,删除目标以检查它是否有帮助。 Similar issue see here .类似问题请参见此处

This is issue was resolved quite easily.这个问题很容易解决。 As .nuget folder is mandatory, I managed to get a copy of the folder and pasted it in the right place.由于 .nuget 文件夹是强制性的,我设法获取了该文件夹的副本并将其粘贴到了正确的位置。 I tried a lot of tips and tricks with VS 2017 and 2019 and none of them worked.我在 VS 2017 和 2019 上尝试了很多技巧和窍门,但没有一个奏效。 Now that the .nuget folder is there, all is working.现在 .nuget 文件夹在那里,一切正常。

The .nuget/nuget.targets was an old "integration" of NuGet with Visual Studio between Visual Studio 2010 to Visual Studio 2013. Visual Studio 2015 onwards no longer has the feature to create this file, because NuGet's integration is more direct. .nuget/nuget.targets是 Visual Studio 2010 到 Visual Studio 2013 之间 NuGet 与 Visual Studio 的旧“集成” .nuget/nuget.targets Studio 2015 以后不再具有创建此文件的功能,因为 NuGet 的集成更直接。 Since you copied the project, and not the whole solution, you didn't copy the .nuget/ folder.由于您复制了项目,而不是整个解决方案,因此您没有复制.nuget/文件夹。 You said there's no .nuget folder in the source repo, but then I don't see how the original solution could possibly compile successfully.您说源代码库中没有.nuget文件夹,但是我看不到原始解决方案如何成功编译。

I suggest you follow the instructions on how to migrate to automatic package restore .我建议您按照有关如何迁移到自动包恢复的说明进行操作 It's just undoing what "enable package restore" did in VS2013 and earlier.它只是撤消了在 VS2013 及更早版本中“启用包还原”所做的事情。

As you said that you copy the project from other location to desktop, I am assuming that you don't copy the sln file.正如您所说,您将项目从其他位置复制到桌面,我假设您没有复制 sln 文件。 try adding a sln file at desktop and add the project to that sln after that try restor the nuget.尝试在桌面上添加一个 sln 文件,然后在尝试恢复 nuget 之后将项目添加到该 sln。 One thing to remember please try to make sure the folder structure hierarchic relative to the sln file and project location.要记住的一件事请尝试确保文件夹结构相对于 sln 文件和项目位置是分层的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM