109

So I downloaded Twitterizer from http://www.twitterizer.net/downloads/

I try to open it in Visual Studio and get all these nuget errors:

The imported project "C:\Twitterizer\.nuget\nuget.targets" was not found. 
Confirm that the path in the <Import> declaration is correct, and that the file 
exists on disk.

What is going on. How do I deal with this?

1
  • 6
    Just a note in case anyone else runs into this. Nuget 2.7 introduced a new type of package restore. If you try to add a project that used the old style to a solution that uses the new style you'll get this same error. The way to fix it is to migrate the project to the new style: docs.nuget.org/docs/workflows/…
    – Slapout
    Commented Dec 23, 2014 at 21:16

7 Answers 7

174
  1. Install Nuget.
  2. Right click on the solution and select "Enable NuGet Package Restore". In Visual Studio 2013 and later, select "Restore NuGet Packages" instead.
  3. Click Ok on the warning.
  4. Close and re-open the solution.

Should now be hunky-dory.

4
  • 2
    Thanks for this, would be nice if they gave a more helpful error message in VS for that.
    – rossisdead
    Commented Oct 14, 2014 at 17:37
  • 2
    I'm still getting this error even though this no longer applies to nuget 2.7 Commented Apr 30, 2015 at 19:18
  • You need to do the workaround @Slapout mentions (comment on the original question)
    – JasonS
    Commented Oct 19, 2015 at 17:46
  • Still not working here, it says that there is no more dependencies to restore. I have already deleted the package folder and restore it a couple of times :(
    – rodrigorf
    Commented Jan 10, 2018 at 17:26
23

An alternative is to edit the .csproj file with a texteditor and remove or comment out the segment.

3
  • 4
    To expand on this case - if you move a project from a solution with an explicit .nuget\nuget.targets file to a fresh one, you will see this problem (even after restoring NuGet packages.) In this case, either create the nuget.targets or edit the project file manually.
    – ThisGuy
    Commented Jul 18, 2014 at 1:41
  • I also applied this solution since my project used non of the NuGet packages and VS seems to have auto-generated this stuff. Thanks heaven for version control that made it possible to kick-out the added lines from .csproj. Commented Aug 12, 2014 at 8:53
  • Which segment must one remove? Commented May 10, 2017 at 7:07
19

This error normally happens when you are trying to open a .csproj directly, not through the solution file, and the .csproj imports the Nuget targets like this:

<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />

In order to solve it, you can either open the .sln and not the .csproj directly...or remove the import line above.

Notice that the mentioned error will only happen when you are using solution wise package restore, which isn't even recommended anymore.

2
  • 2
    This is the issue that I had. Commented Jan 5, 2017 at 21:41
  • 1
    removal of "the import line above." did the trick for me. Thanks!! Commented Dec 3, 2018 at 13:22
7

Just ran into the same problem, but in my case the issue was a space in the folder name:

Nuget was telling me it couldn't find "C:\git\My Path" but I was able to navigate to "C:\git\My%20Path". Removing the space in the foldername "fixed" the issue.

0
2

I know I'm late to the party but here is a really good tutorial on how to fix this issue. I used this to fix my project.

Close down Visual Studio If the solution you are trying to migrate is open in Visual Studio, then changes may be lost. Visual Studio may overwrite/ignore your changes in some cases and the NuGet extension will also try to re-enable Package Restore when it sees some projects in the solution are missing it.

If you are using TFS Remove the NuGet.exe and NuGet.targets files from the solution's .nuget folder. Make sure the files themselves are also removed from the solution workspace. Retain the NuGet.Config file to continue to bypass adding packages to source control. Edit each project file (e.g., .csproj, .vbproj) in the solution and remove any references to the NuGet.targets file. Open the project file(s) in the editor of your choice and remove the following settings:

true ... ...

<PropertyGroup>
    <ErrorText>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 {0}. If you are not using TFS Remove the .nuget folder from your solution. Make sure the folder itself is also removed from the solution workspace. Edit each project file (e.g., .csproj, .vbproj) in the solution and remove any references to the NuGet.targets file. Open the project file(s) in the editor of your choice and remove the following settings:

true ... ...

<PropertyGroup>
    <ErrorText>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 {0}. Migration Script Many users have requested a migration tool to disable the MSBuild-based package restore and convert to Automatic Package Restore. The NuGet team has decided not to provide a supported tool for this because of the high probability of edge cases that would be unhandled. However, Owen Johnson has authored a PowerShell script that can work in many cases. It's available on GitHub and can be used at your own risk. In other words, be sure to commit to source control before running it, just in case it doesn't work in your scenario.

Nuget.target Fix

0
1

When i get the nuget.targets not found error i use the package manager to uninstall-package one of the packages in the project and then reinstall it using install-package. It seems like it regenerates the nugets.target file then.

1

Easiest solution when you get this error in order to restore the missing NuGet.targets in Visual Studio Solution Explorer is to:

  1. Right click on the solution file
  2. From the context menu click "Enable Nuget Package Restore..." option

this will download the missing files in the ".nuget" folder :)

The above assumes you already have Nuget installed - if not follow the accepted answer above!

UPDATE: Please note for Visual Studio versions beyond 2013 the option is called "Restore NuGet Packages"

2
  • 1
    I don't have the enable nuget package restore option. I just have restore nuget packages. Commented May 10, 2017 at 7:04
  • Updated the answer - this is the new name of the menu option after VS2013
    – Emil
    Commented May 10, 2017 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.