313

I searched this problem but none of the solutions worked. I have Visual Studio Professional 2015 installed and I am using TFS. My NuGet version is 3.1.6. This problem is happening only in my C# Web API/MVC project.

I am getting the below error:

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\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props

  1. I do not have .nuget folder in my solutions.
  2. I have a packages folder in the solution and when I delete it, it seems like NuGet does rebuild the dependencies but the project still has the above error.
  3. I tried removing the project from TFS and it didn't fix it.
  4. Along with the above error, all the references in the project have yellow warning signs and say they are missing.
  5. When I checked the NuGet Package Manager for the project, everything that is "missing" has a green tick next to it, including Microsoft.Net.Compilers.
  6. I tried adding a new Web API/MVC project and it faced a similar problem where most references such as Owin were "missing" with the yellow warning sign.
Ques Tion
  • 3,125
  • 2
  • 8
  • 10
  • votes to close this question due to the shear amount of low quality posted answers by new users. – ZF007 Apr 16 '19 at 08:39

36 Answers36

371

I solved my issue by removing this code from .csproj file:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <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}.</ErrorText>
  </PropertyGroup>
  <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
DKR
  • 4,758
  • 1
  • 15
  • 19
  • 5
    Accepted answer would not work since I am referencing the project in multiple separate solutions. This was the only fix. Commented it out and it worked like a a charm. – Levi Fuller Apr 12 '16 at 16:55
  • 1
    I also removed these lines, but I'm more wondering, why are those lines there. Its not than my code won't run. Also why are those nugets so special that they must be included? Why was a normal broken reference not enough?? – Maarten Kieft Sep 27 '16 at 08:53
  • 32
    I could be wrong, but I believe this is "swatting the fly with the hammer". If, for whatever reason, the published location loses any other required nuget package, it will *not* error, giving you a false positive (i.e. deployment succeeds, but system fails). Not a fan, but I'm not going to downvote it because there are aspects of nuget I'm still not familiar with. – HeyZiko Oct 06 '16 at 23:04
  • 4
    This also worked for me. Odd that the error message was hard-coded in the proj file itself ... – Ryan Peters Mar 15 '17 at 11:04
  • 8
    Confirmed this issue still exists in VS 2017. I migrated a project from visual studio 2015 to 2017 and got this error message upon first compile in 2017. This fixed the bug. – Tom McDonald Apr 28 '17 at 18:18
  • 2
    Why delete functionality, risk your project breaking etc by doing this? As @HeyZiko points out this can lead to problems later on. I could just do what the error states "Enable package restore". See my answer somewhere on this page... – Nicow May 09 '17 at 11:13
  • 2
    I think this is not a good answer, it is something like if any testcase is not passing then comment that and you task is done. But that is not a way.. You must have find the root cause and resolve it, rather than commenting or removing such code.. – Sachin Jul 01 '17 at 11:17
  • This answer didn't help at once but given me right direction. Additionally to – alehro Jul 14 '17 at 07:38
  • 2
    This may be "swatting a fly with a hammer", but in my case, my project had ZERO nuget packages (one other project in the solution did, though, if that makes a difference, but that project compiled fine) and the options to "Enable package restore" were, in fact, checked. – CodeHxr Jan 03 '18 at 14:51
  • Rather than delete this entry in .csproj, I edited it to correct the path to the `packages` folder and it worked. – codecypher Jan 03 '18 at 17:28
  • Just FYI, I upgraded the compiler via nuget and it left these pointed to the old version. So, my fix was to leave the paths along and update the version numbers. The correct paths were at the top in tags – Zephryl Jan 23 '18 at 20:02
  • I just restore whole nudget packages multiple times but problem resolved by removing these line of hard-coded error. – Umair Anwaar Aug 11 '18 at 07:59
  • Saved my day. Thank you – Matheus Miranda Dec 20 '18 at 03:57
  • I did this, but i only remove the dot.compiler reference, which we dont really need in production neither on the test env. – CyberNinja May 17 '19 at 13:07
288

I had the same error (missing exactly the same package) today. I also created a MVC + Web API project.

It happened because I moved the app files (including the .csproj) file to another location. I manually updated the .sln file but all packages dependencies are now (Visual Studio 2015) stored in .csproj file.

Editing the .csproj file and correcting the relative path to the solution folder (which contains the packages folder) solved the problem for me.

Lee Taylor
  • 6,091
  • 14
  • 26
  • 43
Tiberiu Craciun
  • 3,071
  • 1
  • 10
  • 12
  • 2
    Copying the Microsoft.Net.Compilers... folder from the old packages folder to the new packages location after a move if it is missing may be a final step required. – Justin Wignall Nov 06 '15 at 14:14
  • 3
    I just removed that ONE package from my computer and it worked. – SpoiledTechie.com Mar 13 '16 at 17:13
  • 1
    I also got the error when physically moving a project to a different location in the Visual Studio solution. None of the solutions on this page worked, so I made a copy of the project (on the file system) and completely removed all reference to the original project in VS. I then recreated the project and copied the bits and pieces into it (from the copy I made). Laborious, but it worked. – Andrew Jens Aug 25 '16 at 00:05
  • 2
    I also had the same issue after moving project from one location to another. Fixing path of the packages in the ".csproj" file fixed the issue. – Nirman May 08 '17 at 13:50
  • Instead of doing it manually, I suggest doing it via Package Manager console: 'update-package -ProjectName {ProjectName} -Reinstall' . This works like a charm :) – Miłosz Wieczorek May 25 '17 at 17:04
  • 2
    @MiłoszWieczorek I tried running the command in Package Manager Console and it did not solve the issue. It reloaded all packages, but the references are still not found. – Francisco d'Anconia Jul 05 '17 at 21:17
  • I had this problem because my file path was too long for package Microsoft.CodeDom.Providers.DotNetCompilerPlatform. My fix was to move the entire solution closer to the root C:\. Error message: Install-Package : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters – Dan Csharpster Dec 13 '17 at 20:18
  • 1
    I had a problem where I moved the project files to the level of the .sln file, and I had to change the "..\packages\etc" references to ".\packages\etc", so it wouldn't climb up one directory. – Károly Ozsvárt Jul 03 '19 at 09:39
  • No edit is need it, edit the csprog is the evil, is a better idea test to clear the cache of the packages – sgrysoft Jan 12 '20 at 14:54
  • In my case I moved .sln and changed paths to .csproj files, then got this error. Correcting the paths in .csprojs worked for me. – Asiri Dissanayaka Jul 05 '20 at 05:16
  • replace ..\..\........ with $(SolutionDir) – falkb Feb 05 '21 at 08:40
  • I had this exact same issue - .NET 4.7.2 csproj file was moved inside of a "src" subfolder so the references to "packages" were off by one directory. This also corrected a separate issue that prevented me from installing various NuGet packages. Specifically Autofac v6.2.0, which reported "Failed to add reference. The package 'System.Numerics.Vectors' tried to add a framework reference to 'System.Numerics' which was not found in the GAC. This is possibly a bug in the package." – 4e 69 63 6b May 28 '21 at 19:48
45

BEWARE - this updates packages for the entire solution not just the project.

If you have one more missing nuget package that giving your error while building your solution use following command using Nuget Command Console from Tools > Nuget Package Manager > Package Manager Console. It will reinstall your all current packages.

Update-Package –reinstall

Update:

You can pass specific project name as a parameter.

Update-Package –reinstall -ProjectName SampleApp
Community
  • 1
  • 1
Shyam Bhagat
  • 668
  • 6
  • 5
  • 1
    This worked for me. The error popped up after for me after pushing changes through git on one system and pulling them on another. Maybe my .gitignore is not properly configured for nuget packages. – Patrick Borkowicz Jan 18 '16 at 20:44
  • 16
    Beware ... this updates packages for the entire solution not just the project. – SO User Feb 12 '16 at 04:30
  • 1
    This worked for me. NuGet kept complaining about missing packages, but Visual Studio would not auto-resolve. It took a couple minutes to run completely, but this command fixed my problem. – Nick Alexander Sep 07 '16 at 03:55
  • 8
    You can add -ProjectName parameter to make it only for specific project, not entire solution. – Miłosz Wieczorek May 25 '17 at 17:06
  • Didn't read Rashmi's comment about it updating packages for the entire solution until it was too late. BEWARE – Richard Moore Mar 08 '18 at 13:28
  • 2
    VS2017 crashed half way through this and it broke everything – rolls Apr 11 '18 at 06:37
  • I removed all the nuget packages from the packages folder, and then tried redownloading all packages at build received a build error. I then just had to reinstall the https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/ package and everything worked perfectly – Nick Aug 12 '19 at 12:20
  • Just says "No package updates are available from the current package source for project " and doesn't do anything in my case. – ssmith Nov 23 '20 at 16:56
19

I had this exact frustrating message. What finally worked for me was deleting all files and folders inside /packages and letting VS re-fetch everything the next build.

Ryan Russon
  • 961
  • 8
  • 15
19

this way solved my error : To open .csproj file for update in Visual Studio 2015+ Solution Explorer:

Right-click project name -> Unload Project

Right-click project name -> Edit .csproj

Remove the following lines :

<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\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
    <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
    <Error Condition="!Exists('packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
    <Error Condition="!Exists('packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
  </Target>

Right-click project name -> Reload Project

Finally Build your solution.

Abdullah
  • 634
  • 7
  • 17
  • After fixing manually the paths in csproj I removed the section EnsureNuGetPackageBuildImports and it worked perfectly. thanks – willyMon Apr 15 '19 at 19:44
  • Worked for me. A bit overkill but other options didn't fix the issue. – ssmith Nov 23 '20 at 16:58
16

Tiberiu is correct. I had to edit my .csproj file as the files were moved and caused this issue

 <Import Project="..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />

I changed at top of the file and at the bottom

<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
<Error Condition="!Exists('..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.1\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
Tom Stickel
  • 16,699
  • 6
  • 102
  • 108
  • what did work for me in the end was to edit only the line at the end of the file, but not at the top – ISAE Feb 16 '16 at 22:05
11

I solved this issue by removing the following code from .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('..\..\..\Assemblies\NuGet\SpecFlow.Plus.Excel.1.4.2\build\SpecFlow.Plus.Excel.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\Assemblies\NuGet\SpecFlow.Plus.Excel.1.4.2\build\SpecFlow.Plus.Excel.targets'))" />

Mohsin Awan
  • 1,148
  • 2
  • 10
  • 28
9

A combination of the 2 answers worked for me. First I modified the .csproj file to remove the reference to 1.0.0 version

< Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild" >

  ----Error---

< /Target>

and then did

Update-Package -Reinstall

from the and it worked.

innoSPG
  • 4,268
  • 1
  • 24
  • 40
Prakrithi
  • 101
  • 1
  • 1
6

For me, the problem was that when I copied the solution to a new folder and opened it, it was missing the Nuget folder as shown below. I copied this folder over and everything worked. Note: This same folder was in our source control but not in this solutions project, it was up one directory.

enter image description here

JWP
  • 5,969
  • 3
  • 39
  • 65
6

To expand on a few of the answers here, yes you could remove the following block from your .csproj file:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

and this fixes the issue, however in my case, I noticed that I had additional references to the .NET.Compilers and .CodeDom.Providers with different versions:

<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\

<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.2.0.1
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.3\

When my packages.config only referenced the following:

<package id="Microsoft.Net.Compilers" version="2.0.1"
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.3"

Removing the 1.0.0 items from the .csproj file fixed the issue.

Brian Vander Plaats
  • 2,187
  • 22
  • 28
6

Just enable NuGet Package Restore. Right click your solution > choose 'Enable NuGet Package Restore'.

Right click your solution > choose 'Enable NuGet Package Restore'

This will create the .nuget folder with NuGet.Config file and fixed my problem.

Caspar Kleijne
  • 20,134
  • 11
  • 65
  • 99
Nicow
  • 387
  • 3
  • 7
5

I am using VS2012 and facing the same error. I removed the following Target tag from the .csproj file and it started compiling without any error.

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  -- Error messages within Target Tag
</Target>
MAK
  • 484
  • 1
  • 8
  • 20
5

I solved the same issue with the following steps

  1. Removed package <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net46" /> from package.config file.
  2. Edit the .csproj project file and removed the below settings. <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\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />   </Target>

    1. Go to package manager console and run the command Update-Package –reinstall

Point # 2 and 3 were given by other users and I appreciate those users. Point # 1, removing the Microsoft.CodeDom.Providers.DotNetCompilerPlatform from package.config file is more important. Also, after running the command mentioned in point #3, the issue resolved. All unwanted packages removed and required package reference updated.

Hope this helps someone.

Karthik
  • 346
  • 3
  • 6
2

For anyone who stumbles here with the issue I had (some but not all packages being restored on a build server), the final piece of the puzzle for me was adding a NuGet.config in the root of my solution, sibling to the .SLN file as David Ebbo explained here: http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html.

From Ebbo's blog post, the file contents for me are simply

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
</configuration>

UPDATE:

The NuGet API URL has changed for v3 (current as of Sept 2016). From https://www.nuget.org/

<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
madannes
  • 423
  • 1
  • 7
  • 13
1

The error message is completely correct. I tried all the tricks and none worked. The project (simple MVC Web App test) moved from Windows 8.1 VS 2015 Community to my new test box on Windows 10. All the latest updates to VS 2015 applied. I could not even install any newer version of the compilers package.

Loop:
<LOOP>This seems to be a Ground Hog Day phenomena.</LOOP>
GoTo Loop

I finally just copied Microsoft.Net.Compilers.1.0.0 from the old project into the new one and it worked. I could then start to update other packages to newer version. Looks like a nuget project upgrade process bug to me.

NOTE: The original project was created in VS 2015 and does not have any legacy nuget methodologies.

Peter Ennis
  • 351
  • 3
  • 4
1

Solution that works in my case - Visual Studio 2015 Enterprice, project .NET 4.6.1

  1. Upgrade to Update 3
  2. Install Web developer tools

Visual studio installation wizzard

Community
  • 1
  • 1
Norbert Rozmus
  • 620
  • 1
  • 6
  • 8
1

For me, the packages were there under the correct path, but the build folders inside the package folder were not. I simply removed all the packages that it said were missing and rebuilt the solution and it successfully created the build folders and the .props files. So the error messages were correct in informing me that something was a miss.

Ian Hale
  • 11
  • 1
1

I had this issue as a failed build in Azure, when deployed from Git.

Turns out my .gitignore was excluding the build folder from ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.0\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props.

Once the build folder was (force) committed to Git, the issue was solved.

Neil Thompson
  • 6,116
  • 2
  • 25
  • 50
0

I couldn't find any solutions to this so I added a copy of the nuget.exe and a powershell script to the root directory of the solution called prebuild.ps1 with the following content.

$nugetexe = 'nuget.exe'
$args = 'restore SOLUTION_NAME_HERE.sln'
Start-Process $nugetexe -ArgumentList $args

I called this powershell script in my build in the Pre-Build script path enter image description here

Nick Rubino
  • 725
  • 6
  • 9
0

Mine worked when I copied packages folder along with solution file and project folder. I just did not copy packages folder from previous place.

user1429899
  • 288
  • 5
  • 14
0

You can also use the suggested error message as a hint. Here's how, find the Manage Packages for Solution, and click on the resolve missing nuget package.

That's it

Parama Dharmika
  • 98
  • 1
  • 3
  • 8
0

Comment the Compiler Option in WebConfig:

<!--<system.codedom>
<compilers>
  <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>-->

Update the Latest Version of Packages in Package Config File

  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.4" targetFramework="net452" />

Rebuild if all ok, no need to proceed, else Right-click the project, click 'unload project' Right-click the project again and edit .csproj file

Validate the path of Codedom, it was not having net45 in previous paths, add that manually, save, load, rebuild. It should work.

<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.4\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.4\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />
Anurag Sharma
  • 2,823
  • 1
  • 21
  • 38
0

As many suggested removing the <Target> tag may make it compile-able. Yet, beware of the fact that it has a side effect when you do it for test projects.

I got error related to MSTest.TestAdapter nuget package while compiling. Resolved that issue by removing <Target> tag. Though it made build successful, test methods became non discover-able. Test explorer won't list down the test methods in that project and Run Test or Debug Test won't work as well.

I encountered this while using Visual Studio 2017 and .Net framework 4.7, it can very well happen in other versions

Saravanan
  • 792
  • 8
  • 22
  • 1
    I've exactly that problem using VS2017, .Net4.7 and a unit testing project. That project is added to multiple solutions. The automatic restore works but to the wrong place. Replace with `$(SolutionDir)` work but update failes. I asked that [here](https://stackoverflow.com/q/46773763/2729609). Do you have any solution found? – Sebastian Schumann Oct 17 '17 at 09:11
0

The issue for me was that NuGet couldn't automatically get/update the packages because the full file path would be too large. Fixed by moving my solution to a folder in my Documents instead of a deeply nested folder.

Then can right-click on solution and select "Restore NuGet Packages" (which probably isn't necessary if you just build it and let it do it for you), and then select "Manage NuGet Packages for Solution" to get all the packages updated to the latest version.

This was for a solution of a sample ASP MVC application downloaded from Microsoft's web site.

pkr
  • 1,592
  • 4
  • 22
  • 41
0

For DevOps/build engineers, you can probably fix this running nuget restore against the affected SLN, or project if you lack a SLN. I have to do this for our CI/CD builds for all our UWP projects.

  1. Make sure nuget is installed on the build slave either in Visual Studio or standalone. If it's the latter, make sure it's in PATH and skip step 2.
  2. Either open the VS Dev CMD console, or load it via an already open one, which you can do with the instructions below:
    VS2015 call "%VS140COMNTOOLS%VsDevCmd.bat"
    or
    VS2017 call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
  3. call nuget restore MyStuff.SLN or call nuget restore MyStuff.csproj if there's no SLN.
kayleeFrye_onDeck
  • 5,531
  • 5
  • 56
  • 62
0

Not sure if this will help anyone, but I had this issue come up when I deleted the source code from my local machine without having ever saved the solution file to TFS. (During initial development, I was right-clicking and checking in the project in Solution Explorer, but forgot to ever check in the solution itself.) When I needed to work on this again, all I had in TFS was the .csproj file, no .sln file. So in VS I did a File --> Source Control --> Advanced -- Open from Server and opened the .csproj file. From there I did a Save All and it asked me where I wanted to save the .sln file. I was saving this .sln file to the project directory with the other folders (App_Data, App_Start, etc.), not the top level directory. I finally figured out that I need to save the .sln file up a directory from the project folder so it's on the same level as the project folder. All my paths resolved and I was able to build it again.

0

For me my gitignore file was ignoring my packages folder. The following gitignore line was causing the issue -

**/packages/*

Removed and it restored my packages folder. Hope this helps someone else.

bsod_
  • 750
  • 7
  • 20
0

I got a fix around this error, actually I was having a different version of MSTest.TestAdapter(1.3.2) in my packages folder and in .csproj file references were pointing to MSTest.TestAdapter(1.1.0). I have replaced all the MSTest.TestAdapter(1.1.0) to MSTest.TestAdapter(1.3.2), and this resolved my issue.

0

I realize this question is old, however I ran into this same situation today and wanted to throw in my 2 cents for anyone recent finding this issue. An ASP MVC project I had manually moved to a subfolder in my solution and then removed and readded to the solution, using Visual Studio 2017, was giving the error mentioned. Moving the "lib" and "packages" folders to the root of the same subfolder as the MVC project fixed my issue.

0

I was having the same issue, it turns out one of the projects I was referencing was outside the solution directory (and therefore didn't share the same '/packages' folder). The solution that worked for me was to open the reference project's solution and build it there. Once that project built, the errors went away.

bmontalvo
  • 19
  • 2
0

The folder in my solution was named ".NET Project". By renaming it to "NET Project" everything worked fine. So the dot at the beginning was a bad idea.

Juan Carlos Puerto
  • 2,353
  • 22
  • 21
0

In my case there was missing <RestorePackages>true</RestorePackages> in *.csproj file. It was not necessary to delete snippets of code I see in previous answers.

Michal
  • 420
  • 4
  • 18
0

A different user name is the common cause for this, Nuget downloads everything into: "C:\Users\USER_NAME\source\repos" and if you had the project previously setup on a different user name the .csproj file may still contain that old user name there, simply open it and do a search replace for "C:\Users\_OLD_USER_NAME\source\repos" to "C:\Users\NEW_USER_NAME\source\repos".

paul-2011
  • 565
  • 7
  • 22
0

There seem to be multiple causes for this.

For mine, it was that the .csproj file contained references to two different versions of Microsoft.Bcl.Build.targets:

<Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
    <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="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=317567." HelpKeyword="BCLBUILD2001" />
    <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
</Target>


<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
<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\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets'))" />
</Target>

I removed the old reference, and it solved the problem.

Jeff Dege
  • 9,556
  • 21
  • 74
  • 132
0

You also get this error if you use package.config together with this build command

MSBuild.exe /t:Restore MySln.sln

In this case either switch to nuget restore command or use PackageReference.

testing
  • 17,950
  • 38
  • 208
  • 373
-2

Comment out the following code from .csproj

<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\Costura.Fody.2.0.1\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.2.0.1\build\Costura.Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.3.1.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.3.1.3\build\Fody.targets'))" />

Ethan
  • 9
  • 1
    You are reporting the traceback error and no answer to the question how its solved (regardless the hint of MS in that error-log). You posted information and the real answer are posted multiple times. Therefore unfortunately low quality answer and thus no answer. – ZF007 Apr 16 '19 at 08:24