vb.net 转到定义并查找所有引用在 Visual Studio 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21692694/
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-09-17 16:44:30  来源:igfitidea点击:

Go to definition & Find all references do not work in Visual Studio

c#vb.netvisual-studio

提问by 404compilernotfound

I have a Windows Forms solution in VS 2013 Pro that has several projects in both VB and C#. One of the dependencies looks like this:

我在 VS 2013 Pro 中有一个 Windows 窗体解决方案,它在 VB 和 C# 中有几个项目。依赖项之一如下所示:

Startup Project, SP (VB)
    Custom Controls Library, CL (C#)
       Utils/Constants Library, UL (VB)
    UL (again, referenced directly from SP)

My problem is that when I Go To Definition from SP to CL, it takes me to the Object Browser. When I Go To Def from CL to UL, it brings up metadata. But when I Go To Def from SP to UL, it works fine. Also, when I Find All References of a control in CL, it doesn't show the SP references, but when I do it from SP, it shows references in both SP and CL.

我的问题是,当我从 SP 转到定义到 CL 时,它会将我带到对象浏览器。当我从 CL 转到定义到 UL 时,它会显示元数据。但是当我从 SP 转到 Def 到 UL 时,它工作正常。此外,当我在 CL 中查找控件的所有引用时,它不会显示 SP 引用,但是当我从 SP 中查找时,它会同时显示 SP 和 CL 中的引用。

I have searched on StackOverflow, MSDN, and several other forums, and tried all suggestions I've found: I have removed all references and rebuilt them (I am 100.0% sure they are all project references, not file references). I have completely deleted my solution file and added the projects from scratch. I have ensured that the GUID in the references matches that of the references. They are all being built with the same framework, and all for the same processor type. All projects are producing pdb and xml debug files. I assume that VS2013 did away with IntelliSense database files, as I cannot find any of them on my disk to delete (or I would have tried it!).

我在 StackOverflow、MSDN 和其他几个论坛上搜索过,并尝试了我找到的所有建议:我已经删除了所有引用并重建了它们(我 100.0% 确定它们都是项目引用,而不是文件引用)。我已经完全删除了我的解决方案文件并从头开始添加了项目。我已确保参考文献中的 GUID 与参考文献的 GUID 匹配。它们都使用相同的框架构建,并且都用于相同的处理器类型。所有项目都在生成 pdb 和 xml 调试文件。我假设 VS2013 取消了 IntelliSense 数据库文件,因为我在磁盘上找不到任何要删除的文件(或者我会尝试删除!)。

Another interesting (I'm assuming related) detail is that method/property renames in CL are not reflected in SP. Not only are the SP subclasses' symbols not renamed, but Visual Studio doesn't even alert me to this error until I have rebuilt. So, it seems as if IntelliSense is corrupt, or there is something else I'm missing.

另一个有趣的(我假设相关的)细节是 CL 中的方法/属性重命名没有反映在 SP 中。不仅 SP 子类的符号没有重命名,而且在我重建之前,Visual Studio 甚至不会提醒我这个错误。因此,似乎 IntelliSense 已损坏,或者我还缺少其他东西。

I am really at a loss. As far as I can remember, this functionality has worked. I can't say for sure whether it worked since upgrading from 2012 to 2013. Is anyone having the same experience? I have disabled add-ons, rebuilt solution, re-added project dependencies… and I would reinstall Visual Studio, but don't really want to lose several hours of development doing that if there is a simpler method.

我真的很茫然。据我所知,此功能有效。从 2012 年升级到 2013 年,我不能确定它是否有效。有人有同样的经历吗?我已经禁用了加载项、重建了解决方案、重新添加了项目依赖项……我会重新安装 Visual Studio,但如果有更简单的方法,我真的不想浪费几个小时的开发时间。

回答by Craig

Have recently upgraded to VS2013 and can tell you that when you click on a function name where it is defined the "Find All References" option used to show all the places in the solution where the function was called. All it does now is show you the one you're already looking at.

最近升级到 VS2013 并且可以告诉您,当您单击定义它的函数名称时,“查找所有引用”选项用于显示解决方案中调用该函数的所有位置。它现在所做的只是向您展示您正在查看的内容。

In front of me now I have line 218: Public Shared Function MyNewFunction(ByVal test As String)

现在在我面前我有第 218 行:公共共享函数 MyNewFunction(ByVal test As String)

If I right click on MyNewFunction and select "Find All References" the output window says "Find Symbol Results - 1 match found" and it's the same function name, file and line number as above. So it is effectively useless.

如果我右键单击 MyNewFunction 并选择“Find All References”,输出窗口会显示“Find Symbol Results - 1 match found”,它与上面的函数名称、文件和行号相同。所以它实际上是无用的。

Unless of course, there is some hidden setting that we haven't seen yet?

当然,除非有一些我们还没有看到的隐藏设置?

回答by Martin

Currently I only have an Express Edition available. I tried it with VS2013 Express with newly created empty projects the way you described them (i.e. VB -> C# -> VB). I see all of the behavior you described, butVS2012 Express shows exactly the same behavior.

目前我只有一个 Express Edition 可用。我用 VS2013 Express 尝试使用新创建的空项目,如您描述它们的方式(即 VB -> C# -> VB)。我看到了您描述的所有行为,VS2012 Express 显示了完全相同的行为。

Thus, I fear reinstalling won't help.

因此,我担心重新安装无济于事。

I usually work with solutions that contain several projects, and Go To Definition etc. work very smoothly across projects, but I never worked with a solution containing projects using more than a single language.

我通常使用包含多个项目的解决方案,Go To Definition 等跨项目工作非常顺利,但我从未使用包含使用多种语言的项目的解决方案。

I guess the feature you are missing, "smoothly working IntelliSense across projects using different .NET languages", has never been implemented.

我猜您缺少的功能“在使用不同 .NET 语言的项目之间顺畅地运行 IntelliSense”从未实现过。

Update:VS2010 behaves the same way.

更新:VS2010 的行为方式相同。

回答by Roland

I had the same problem of trying to find the Find All Refsoption, and found it has nothing to do with multiple languages or the version of VS, but just with excluded files. In the Solution Explorer you might see a vague, dotted, file icon, like with my file CenterConverter.cs:

我在试图找到该Find All Refs选项时遇到了同样的问题,发现它与多种语言或 VS 版本无关,而只是与排除的文件有关。在解决方案资源管理器中,您可能会看到一个模糊的、点状的文件图标,就像我的文件CenterConverter.cs

enter image description hereWhile normal files have a right-mouse-click menu option for Exclude From Project, the dotted-icon source file has one for Include In Project.

在此处输入图片说明普通文件有一个用于 的鼠标右键单击菜单选项Exclude From Project,而虚线图标源文件有一个用于Include In Project.

Looking at the Properties for an excluded file, you will see that the Build Action(Compile or not) and the Copy To Output Directoryproperties are missing.

查看排除文件的属性,您将看到Build Action(编译与否)和Copy To Output Directory属性丢失。

By including the file in the project, it will be compiled, and options like Go To Definitionand Find All Referencesstart to make sense.

通过在项目中包含该文件,它将被编译,并且选项像Go To DefinitionFind All References开始有意义。

回答by Tydaeus

I encountered a similar issue in VisualStudio 2010, where the "Find All References" command disappeared after quite a while of normal usage.

我在 VisualStudio 2010 中遇到了类似的问题,在正常使用一段时间后,“查找所有引用”命令消失了。

Using the shortcut keys would display a message along the lines of "not currently available", while attempting a "Go To Definition" would display an error dialog.

使用快捷键会显示一条“当前不可用”的消息,而尝试“转到定义”会显示一个错误对话框。

Exiting and re-opening Visual Studio did not fix the issue, and I couldn't find any settings that would change the situation.

退出并重新打开 Visual Studio 并没有解决问题,而且我找不到任何可以改变这种情况的设置。

Oddly, the issue was restricted to one source code file, and not the other.

奇怪的是,问题仅限于一个源代码文件,而不是另一个。

Out of curiousity, I closed the effected source code file, then re-opened it by double-clicking the file in solution explorer, and this fixed the issue.

出于好奇,我关闭了受影响的源代码文件,然后通过在解决方案资源管理器中双击该文件重新打开它,这解决了问题。

My best guess is that something corrupted the cached index on the file, and doing a close and re-open prompted Visual Studio to refresh this cache.

我最好的猜测是文件上的缓存索引损坏了,关闭并重新打开会提示 Visual Studio 刷新此缓存。