Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: references in code not recognized?

I have a solution in VS2008 (C#) that contains multiple projects. I just retooled some of the .csproj files for our build process, and suddenly while coding Project B won't recognize references from Project A in the class code...think the red squiggly lines under a variable type I've created. However, building the solution generates no errors. Why's it behaving like this?

like image 413
Chris Avatar asked Jun 24 '09 15:06

Chris


People also ask

How do I enable references in VS code?

Step 1: From Settings – Type CodeLens and Enable the Editor: Code Lens and JavaScript > References Code Lens to check the references in JavaScript File.

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.


3 Answers

I would suggest that you clear your Visual Studio temp files - it can often get confused about project structures and require a fresh start.

First, quit out of VS completely and restart it. If the problem is still there, find your VS cache folder and delete it, and then do a rebuild.

For help finding your cache folder, check this post.

like image 152
womp Avatar answered Nov 10 '22 08:11

womp


When VS starts acting strangely wonky, and I can't find a logical fix, I kill Visual Studio, and manually do a 'clean' by deleting all of the bin/obj folders.

I have a batch file that does this for me quicker than I could do it manually. I place this in my solution directory, and all my projects are found in subdirectories.

rem "%%~dpa" says: Give me the (d)drive and (p)path of the (a, %%a) file.
rem However, our dir /a:d will result in only listing folders...
rem The final "%%a" is just appending the 'file' (diretory name) to the 
rem drive-and-path string
for /f %%a in ('dir /b /a:d *.*') do call :process "%%~dpa%%a"
pause
goto :eof

:process
echo Looking in %1
cd "%1"
if EXIST "%1\bin" (
   echo    Found 'bin' - it's gone now.
   rd /s /q "%1\bin"
)
if EXIST "%1\obj" (
   echo    Found 'obj' - it's gone now.
   rd /s /q "%1\obj"
)
cd ..
like image 23
Yoopergeek Avatar answered Nov 10 '22 08:11

Yoopergeek


Another solution


If the other answers regarding clearing Visual Studio cache, .NET Cache, and ensuring references are valid don't work, try this one.

Based on the source, and trying this solution, I've had success. Deleting the visual studio solution cache folder

  1. Close out of all instances of visual studio
  2. Locate the .vs hidden folder within your solution.
  3. Delete the entire hidden .vs folder.
  4. Rebuild the solution

-- Source

like image 22
Reap Avatar answered Nov 10 '22 08:11

Reap