10

I have a solution/team project set up in visual studio 2013 and for some time have had a working NuGet Microsoft.Bcl Async Package installed for NET Framework 4.0. Today when opening the project all of the default .NET system library references cannot be found, They just have a warning symbol next to them. I have 49 warnings when building the project all saying 'The referenced component 'System.X' could not be found. Or 'The referenced component 'Microsoft.X' could not be found. Yet references to other projects in the solution remain intact.

If it is of any significance I have been using the built in version control system to keep backups of my code and access it from my other pc with the same configuration.

Looking at the other questions on stackoverflow with similar issues people seem to point towards NuGet as potentially causing the problem but without any solution that seems to work for me. I have tried the obvious solution of removing and re-adding the reference using both the file browser and the Framework tab but neither has worked so far.

I cannot currently compile the project as I get this warning, undoubtedly caused by the missing references in the first place.

Error 31 The "EnsureBindingRedirects" task could not be loaded from the assembly C:\Users...\Visual Studio 2013\Projects\AlgorithmToolsTFVC\AlgorithmToolsSuite\AlgorithmTools\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.Tasks.dll. Could not load file or assembly 'file:///C:\Users...\Visual Studio 2013\Projects\AlgorithmToolsTFVC\AlgorithmToolsSuite\AlgorithmTools\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. AlgorithmTools

Edward J Brown
  • 333
  • 1
  • 5
  • 17

6 Answers6

36

A possible solution: If you are seeing yellow triangles over most of your System references, edit your .csproj file (back it up just in case), scroll to the bottom of the file, and delete these lines...

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

Like many others, I've been using a centralized .packages folder outside of source control. This is done by having the following lines in your NuGet.Config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="..\..\..\.packages" />
  </config>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
</configuration>

One of the steps in achieving this, is to check your project file does not use the old NuGet.targets file anymore (the only file in your .nuget solution folder should be NuGet.Config).

When NuGet thinks it should check the NuGet.targets file, and it's not there, it will fail checks to basic references too (like System.Core, WindowsBase and PresentationCore).


Update: See this related topic/answer on how to completely do away with .nuget folders in your solution! It can be set at user-profile level in your AppData.

Community
  • 1
  • 1
Riegardt Steyn
  • 5,431
  • 2
  • 34
  • 49
  • `Microsoft.Net.Compilers.1.0.0` and `Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0` were giving me troubles... I think it's the same issue (Packages outside of solution). Disabled these options > Reloaded project > restored nuget packages > unloaded project > reenabled these options > changed the nesting level to match the rest of the packages (from ..\..\ to ..\..\..\..\) and success. – WernerCD Oct 28 '15 at 03:15
  • Pure magic. It seems to be the most common problem and solution when just copy pasting projects from one solution to a different one. – j riv Oct 23 '17 at 06:23
  • thanks, it worked. Incidentally, I found that switching the project output type to another version of the .net framework (4.7.2) then back to 4.8 also removed those Target lines from the project file, and fixed the issue. – NDUF Dec 16 '20 at 03:41
1

I was able to solve this issue by first running an update on all NuGet packages in the solution and then removing and re adding references to the libraries included or overridden by the package.

Edward J Brown
  • 333
  • 1
  • 5
  • 17
  • I had a similar problem after VS froze on me and I had to kill it. I uninstalled NuGet packages and installed them again. That solved the problem. – Leon Havin Dec 16 '16 at 03:46
0

Just had the same problem. The reason for me was that all the files inside the Nuget package, suddenly become 0 byte size. I mean DLLs, nupkg file etc.

I reinstalled the package and it worked for me.

Alex Klunniy
  • 125
  • 1
  • 8
0

I had exactly the same problem with my project on team foundation server. I had the error saying "EnsureBindingRedirects" task could not be loaded from the assembly C:\Users...\Visual Studio..." and many warnings saying "The referenced component 'Microsoft.X"

The solution was very easy. All I had to do was copy my entire project folder into another location and it worked.

6134548
  • 95
  • 1
  • 3
  • 15
0

Had a similar problem. After wasting 2.5 hours trying to find a solution, I fixed it simply by opening the project in VS 2013, enabling NuGet package restore and rebuilding. Fixed immediately and now it works in VS 2015 just fine.

SmoveBB
  • 120
  • 1
  • 6
0

Just had the same issue and solved it by executing the following command in package manager console:

Update-Package -Reinstall

If you want to do this for a specific project you can use:

Update-Package -ProjectName 'ProjectNameGoesHere' -Reinstall

Yan
  • 403
  • 2
  • 20