Skip to content

EnsureNuGetPackageBuildImports Target Always Causes Errors #3320

Closed
@maartenba

Description

@maartenba
Contributor

From @MelbourneDeveloper on August 16, 2016 1:8

There are many project types created by Visual Studio that add a "EnsureNuGetPackageBuildImports" target element to csproj files. In this case the element is defined in a Xamarin Forms project. It was newly minted in the last week or so from a standard VS template. The target looks something like this in the csproj file:

<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\Xamarin.Forms.2.3.0.107\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Xamarin.Forms.2.3.0.107\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets'))" />
  </Target>

The element is usually benign until you move the project to a different location on the hard drive, or another developer tries to compile the code. When this happens, you get:

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 packages\Xamarin.Forms.2.0.0.6482\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets.

This error message is very misleading and untrue. I've wasted countless hours in many projects trying to get Visual Studio to refresh the packages, but the error just keeps coming up even though there are no other compilation problems in the project. I don't know if the element is useful or not, but the various teams that create the templates need to either remove this element from the templates, or correct the element so that it doesn't cause errors. I can't even count how days I sat there scratching my head over this error until I finally found the error text in the csproj file. Yesterday, my colleague experienced it when she opened up an ASP MVC app. The whole point of NuGet is supposed to be that if the other person doesn't have the libraries, the libraries are silently downloaded and compilation ensues.

Other people can recreate this problem, and there are people reporting this problem all over the place. Here is my original MSDN thread on the topic:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/300b0549-58c9-4c50-bd64-7c82516495a9/nuget-error?forum=visualstudiogeneral&prof=required

Copied from original issue: NuGet/NuGetGallery#3195

Activity

MelbourneDeveloper

MelbourneDeveloper commented on Aug 18, 2016

@MelbourneDeveloper

Has anyone looked in to this?

I just got the issue today. I created a sample SignalR project. I then moved it to another folder and immediately the compilation error comes up. So, I went in and deleted the text from the csproj and the problem was fixed.

This is such a major headache for so many people. Do you have any idea how many new programmers follow a "how to" guide, finish the process of creating a working project, and then move the folder and suddenly it won't compile anymore?

This bug is super easy to reproduce.

rrelyea

rrelyea commented on Sep 7, 2016

@rrelyea
Contributor

Sorry, this is a general limitation of "packages.config".
Our new model, providing Transitive Restore (Project.json or PackageRef in VS "15", solves this.)

Workaround: In Package Manage Console, type: "Update-package -reinstall"

We will improve the error message.
https://github.com/NuGet/NuGet.Client/search?utf8=%E2%9C%93&q=EnsureNuGetPackageBuildImports

added this to the 3.6 Beta2 milestone on Sep 7, 2016
MelbourneDeveloper

MelbourneDeveloper commented on Sep 7, 2016

@MelbourneDeveloper

@rrelyea thanks for looking at this, but I don't think you've grasped the magnitude of the problem. This problem may not rest solely with your team.

I'm not mentioning this problem simply because the problem exists - I am mentioning it because it affects nearly every recently created project template in Visual Studio. It happens with Xamarin and ASP .NET Core projects for a start. Many people will be getting this issue across the board, and will be completely stumped as to why this is happening.

The error message isn't really the issue. I was able to work around the problem by deleting the "EnsureNuGetPackageBuildImports" element from the csproj file.

The issue is that even when the new model is created, you will need to go back and update the Visual Studio project templates so that when people create new projects, they are not left with the old structure that has this issue.

ryanabbott22

ryanabbott22 commented on Apr 13, 2017

@ryanabbott22

Agreed! this is a major headache and took me a long time to figure out why my projects weren't building when the references in my .csproj were correct.

pamela032709

pamela032709 commented on Jul 19, 2017

@pamela032709

I have the same issue over and over , no matter what project I tried to open.
it was working just fine last week , so I thought it may be my project . then I started downloading other project or templates and I got the same issue.
is this a bug that once you find it you can get rid of it?


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}.


pamela032709

pamela032709 commented on Jul 19, 2017

@pamela032709

How did you fix it ? it is driving me crazy

dagostinelli

dagostinelli commented on Nov 20, 2017

@dagostinelli

I'm having this too. It's wasted 3 hours this morning for me. And a total of 3 days across the past couple of months.

EricDahlvang

EricDahlvang commented on Mar 2, 2018

@EricDahlvang

+1

I installed NuGet version 4.5.1 and this issue is still occurring. Error Condition lines are not removed from .csproj under EnsureNuGetPackageBuildImports for previous .props package references. Currently, the only solution I've found is to manually remove these lines. Is there any way to to have NuGet.exe removing the old package reference lines from the .csproj file while updating packages?

satiekue

satiekue commented on Apr 9, 2018

@satiekue

Any progress on this? Removing the EnsureNuGetPackageBuildImports workaround didn't work because then they were missing at runtime, also the Update-package -reinstall workaround didn't help at all.

pamela032709

pamela032709 commented on Apr 9, 2018

@pamela032709
removed this from the Future-1 milestone on Feb 22, 2019

15 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area:ErrorHandlingwarnings and errors/log messages & related error codes.Priority:3Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog.Style:Packages.ConfigType:Bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bklooste@maartenba@lukos@dagostinelli@nkolev92

        Issue actions

          EnsureNuGetPackageBuildImports Target Always Causes Errors · Issue #3320 · NuGet/Home