visual-studio Visual Studio:无法识别代码中的引用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1039072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:42:19  来源:igfitidea点击:

Visual Studio: references in code not recognized?

visual-studio

提问by Chris

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?

我在 VS2008 (C#) 中有一个包含多个项目的解决方案。我刚刚为我们的构建过程重组了一些 .csproj 文件,突然间,在编码项目 B 时无法识别类代码中项目 A 的引用......想想我创建的变量类型下的红色波浪线。但是,构建解决方案不会产生错误。为什么会有这样的行为?

回答by womp

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

我建议您清除 Visual Studio 临时文件 - 它经常会对项目结构感到困惑,需要重新开始。

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.

首先,完全退出VS并重新启动它。如果问题仍然存在,请找到您的VS缓存文件夹并将其删除,然后进行重建。

For help finding your cache folder, check this post.

如需查找缓存文件夹的帮助,请查看此帖子

回答by rlbond

In your Project Properties from B, make sure Project A is checked under dependencies.

在 B 的项目属性中,确保在依赖项下选中项目 A。

回答by Yoopergeek

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.

当 VS 开始表现得很奇怪并且我找不到逻辑修复时,我会杀死 Visual Studio,并通过删除所有 bin/obj 文件夹手动执行“清理”。

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

回答by Matthew Whited

Make sure both projects are being built in the Configuration Manager

确保两个项目都在配置管理器中构建

(right click on the solution and then click “Configuration Manager”)

(右键单击解决方案,然后单击“配置管理器”)

You might also hover over the redline or just build again to see if you get anymore details. C# and VB are both pretty good at telling you why they not happy.

您也可以将鼠标悬停在红线上或重新构建以查看是否获得更多详细信息。C# 和 VB 都非常擅长告诉你为什么他们不开心。

回答by Anastasiya Mazheika

I've removed the reference from the project which classes were not recognized and re-added this reference. Everything got fixed.

我已经从项目中删除了无法识别类的引用,并重新添加了这个引用。一切都搞定了。

回答by Reap

Another solution

另一种解决方案



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

如果有关清除Visual Studio 缓存.NET 缓存和确保引用有效的其他答案,请尝试这个。

Based on the source, and trying this solution, I've had success.

基于来源,并尝试这个解决方案,我已经成功了。

  1. Close out of all instances of visual studio
  2. Locate the .vshidden folder within your solution.
  3. Delete the entire hidden .vsfolder.
  4. Rebuild the solution
  1. 关闭所有 Visual Studio 实例
  2. 找到.vs解决方案中的隐藏文件夹。
  3. 删除整个隐藏.vs文件夹。
  4. 重建解决方案

-- Source

--来源