7

I'm net with C# and Visual Studio 2017. It seems that VS says that Nuget packages are missing. 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"

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. I've tried the "restore nuget packages" from the solution level and it says that there is nothing to update. 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.

Aimery
  • 1,559
  • 1
  • 19
  • 24
  • More imformation: - The whole solution and sub projects were all copied - Originally the solution is made with Visual Studio 2017 professional, I am using the 2017 Community - All development has been made with Visual Studio 2017 –  Aug 08 '19 at 05:13
  • Hi friend, any update for this issue? Please let me know if this issue still persists or not :( – LoLance Aug 21 '19 at 10:16

4 Answers4

16

Please try:

1.In VS2017,go Tools menu=>Nuget Package Manager=>Package Manager settings, make sure you've checked these two options like this:

enter image description here

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:

<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. Similar issue see here.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Thank you so much. This is the only solution that has worked for me. That target was messing up the entire process no matter what I did. I was moving from VS2015 to VS2019. This should be marked as the answer. – John G Apr 09 '21 at 19:28
3

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. I tried a lot of tips and tricks with VS 2017 and 2019 and none of them worked. Now that the .nuget folder is there, all is working.

  • Hi friend, thanks for your sharing and please mark your reply as answer and that will help other community members who easier search this useful information. See [this](https://stackoverflow.com/help/self-answer), it just a reminder :) – LoLance Aug 28 '19 at 03:53
1

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. Since you copied the project, and not the whole solution, you didn't copy the .nuget/ folder. 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.

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.

zivkan
  • 12,793
  • 2
  • 34
  • 51
  • I copied the solution and all sub projects within that solution as they were in the original location. Also the solution is made with VS 2017 that I am currently using. –  Aug 08 '19 at 05:11
  • Visual Studio 2017 never had the functionality to create the `.nuget/nuget.targets` file, so it couldn't possibly have been created there. Either create new projects in VS2019 and copy all the other files into the new projects, or follow the instructions in the instructions in the docs i linked to and delete the referenes to nuget.targets from your csproj. – zivkan Aug 09 '19 at 11:14
  • [Here is a comment](https://github.com/NuGet/Home/issues/7657#issuecomment-452928076) I wrote when helping other customers with a different issue, where I listed exactly what gets written into the csproj when you use the VS2010-VS2013 feature, so you can see exactly what would be good to remove from your csproj. – zivkan Aug 09 '19 at 11:19
0

As you said that you copy the project from other location to desktop, I am assuming that you don't copy the sln file. try adding a sln file at desktop and add the project to that sln after that try restor the nuget. One thing to remember please try to make sure the folder structure hierarchic relative to the sln file and project location.

mak rony
  • 21
  • 3