Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio doesn't load project references

I have a Visual Studio (Community 2013) solution with many c# projects on my pc and I've just upgraded to Windows 10 from 7. The project uses .Net Framework 4.0 Client Profile. On win7 everything worked fine, but now one of the projects doesn't seems to load references. There are yellow triangles near the referenced items, what are not items referenced from the same solution (so system and references downloaded by NuGet not loaded).

references...

The Resources is another project in the solution, the others not. When I open the properties tab for a system reference, the Path field is empty, and so the Resolved field is False...

empty path

Besides, in the .csproj file everything seems to be ok, there are <HintPath> nodes where needed, with relative (or absolute, if the reference is on another drive), and correct, existing paths.
Another weird thing: in the Object Browser all of the references are (seemingly) loaded:

Object Browser seems to be ok

So, what should I do:

  • re-create the project file (by creating new project and add all files and references again);
  • change something in the configuration of the project;
  • use a newer version of .Net;
  • change something in the configuration of VS;
  • use another VS (eg. Community 2015) or reinstall the current one?
like image 209
nvi9 Avatar asked Sep 06 '15 16:09

nvi9


1 Answers

I also had this problem and it took me some time to figure it out. The problem is that NuGet changed how the packages are restored. The "old way" needed the ".nuget" folder with 3 files (nuget.config, nuget.exe, nuget.targets) and some settings in the project file like:

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

This caused the project to be broken.

To fix this, copy the missing directory to the project (get it with an older version of Visual Studio/NuGet or from a co-worker who has it) or just simply delete the aforementioned part from the project file.

For best results, also remove:

<RestorePackages>true</RestorePackages> 

and

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

from the project file!


Find more on the subject here:

http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

http://docs.nuget.org/consume/package-restore/migrating-to-automatic-package-restore

https://docs.microsoft.com/en-us/visualstudio/ide/troubleshooting-broken-references

like image 185
Uszkai Gyula Avatar answered Oct 25 '22 15:10

Uszkai Gyula