Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio cannot find any references for a new project

This is a weird one.

I have Visual Studio 2013 installed. If I create a new project, Visual Studio immediately complains that it cannot find any of the references:

The project does however compile and run correctly, even though there are warnings in the error list:

If I look at the properties of any of these references, their paths are empty. If I load an existing project, Visual Studio can find its references and doesn't complain, even though it is targeting the same version of the .Net framework as the broken project (I've even had them both in the same solution with the same behaviour).

How can I fix this, and what could have caused it? Any suggestions welcome, as it is baffling me.

like image 456
adrianbanks Avatar asked Apr 14 '14 22:04

adrianbanks


People also ask

How do I fix missing references in Visual Studio?

To fix a broken project reference by correcting the reference path. In Solution Explorer, right-click your project node, and then select Properties. The Project Designer appears. If you're using Visual Basic, select the References page, and then click the Reference Paths button.

How do I enable references in Visual Studio?

Press Shift + F12 to find all references.

How do I enable find all references in Visual Studio code?

You can use the Find All References command to find where particular code elements are referenced throughout your codebase. The Find All References command is available on the context (right-click) menu of the element you want to find references to. Or, if you are a keyboard user, press Shift + F12.


2 Answers

I had a problem with an existing project, and by creating a new one and comparing the csproj files I had to add missing import lines like those: one at the beginning of the project element and one at the end.

    <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

...
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
like image 120
Ronen Festinger Avatar answered Oct 06 '22 00:10

Ronen Festinger


This happens to me from time to time and I always suspect VS corruption, but it always turns out to be user error. It typically happens when I add a new project to a solution and try to reference earlier projects in the newly added project. In this case and in general, you can only add a reference if it targets the same or earlier .NET Framework version. In my case, inconsistent target framework versions caused the project to not recognize references and not allow compilation. Double checking consistency or proper target framework versions solved this problem for me.

like image 30
Jim K Avatar answered Oct 06 '22 01:10

Jim K