visual-studio Visual Studio 中的“转到定义”仅显示元数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/837037/
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
"Go To Definition" in Visual Studio only brings up the Metadata
提问by pfunk
I am working in a Web Project in Visual Studio 2008. When I hit F12 (or right-click and select Go To Definition) Visual Studio is consistently going to the Metadata file instead of going to the source.
我正在 Visual Studio 2008 中的 Web 项目中工作。当我按 F12(或右键单击并选择转到定义)时,Visual Studio 始终转到元数据文件而不是转到源文件。
Some Points:
一些要点:
- All the source code is C#, there is no VB.Net
- All the projects are in the same solution
- Everything is a project reference as opposed to a file reference (checked and double-checked)
- I have tried the Clean/Rebuild Solution approach (even to the point of clearing out the Temp directory, Temporary ASP.NET Files directory, etc).
- 所有源代码都是C#,没有VB.Net
- 所有项目都在同一个解决方案中
- 一切都是项目参考,而不是文件参考(检查和双重检查)
- 我已经尝试过清理/重建解决方案方法(甚至清除临时目录、临时 ASP.NET 文件目录等)。
Has anyone else seen this behavior and/or know how to fix it?
有没有其他人看到过这种行为和/或知道如何解决它?
采纳答案by pfunk
Well, another developer found the answer. The specific project we had an issue with was originally added as a file reference, then removed and added as a Project Reference. Visual Studio however, kept both in the csproj file for the web site, causing the issue. He went in and manually edited the csproj file to remove the file reference to the problem project and all is fixed now
好吧,另一位开发人员找到了答案。我们遇到问题的特定项目最初作为文件引用添加,然后删除并添加为项目引用。但是,Visual Studio 将两者都保存在网站的 csproj 文件中,从而导致了问题。他进去手动编辑了csproj文件,删除了对问题项目的文件引用,现在一切都解决了
回答by Vadim
It happens when you don't add reference as a project but point to a dll or exe using Browse tab in Add Reference dialog. If you add reference using Projects tab you should go directly to the source code when you select Go To Definition.
当您不将引用添加为项目而是使用“添加引用”对话框中的“浏览”选项卡指向 dll 或 exe 时,就会发生这种情况。如果使用“项目”选项卡添加引用,则应在选择“转到定义”时直接转到源代码。
However, if you install ReSharper, you'll go to source code even if you added your reference to a dll/exe using Browse tab.
但是,如果您安装ReSharper,即使您使用浏览选项卡添加了对 dll/exe 的引用,您也会转到源代码。
回答by Jeson Martajaya
回答by Ali Sadri
1.close your solution.
1.关闭您的解决方案。
2.delete hidden <name of the solution>.suo file in folder where your solution's <name of the solution>.sln file exists.
2.删除<name of the solution>解决方案的<name of the solution>.sln 文件所在文件夹中的隐藏.suo 文件。
3.open your solution.
3.打开您的解决方案。
4.rebuild your solution.
4.重建您的解决方案。
回答by BCA
For those using VS 2017 (I'm at version 15.3.4 at this moment) here are the simple steps:
对于那些使用 VS 2017(我现在是 15.3.4 版)的人,这里是简单的步骤:
- Open your solution in Windows Explorer and close down Visual Studio
- In the explorer menu, select View and ensure that the "Hidden items" checkbox is marked
- Navigate to the subfolder
.vs\[your solution name]\v15 - Delete the
.suofile - Restart VS and build your solution
- 在 Windows 资源管理器中打开您的解决方案并关闭 Visual Studio
- 在资源管理器菜单中,选择查看并确保选中“隐藏项目”复选框
- 导航到子文件夹
.vs\[your solution name]\v15 - 删除
.suo文件 - 重新启动 VS 并构建您的解决方案
That fixed it for me: F12 opened the actual source file, not the "from metadata" version.
这对我来说修复了它:F12 打开了实际的源文件,而不是“来自元数据”的版本。
回答by Andrew
Visual studio often suffer from a problem of going to metadata rather than your project if you shift location where you are building the project, ie you may have several versions to test things out.
如果您移动构建项目的位置,Visual Studio 通常会遇到转到元数据而不是您的项目的问题,即您可能有多个版本来测试。
Simply delete the reference and immediately add it back and everything will be sorted out.
只需删除引用并立即将其添加回来,一切都会得到整理。
回答by Rich
The marked solution does not always work. You must make sure that the referenced project GUID in the project files is the correct GUID for the project you are trying to reference. Visual Studio does allow them to get out of synch in some circumstances. You can get the project GUID from the project file with a text editor. So if project A reference project B. Open up project B.csproj in text editor, copy out project GUID from the tag. Then open up project A.csproj in text editor, and make sure that you are using the correct GUID. Search for project name "B" in this case. It should be at . Replace the GUID in the tag with the correct one. Save and reload. Of course also make sure file based references to your projects are removed. You only want project references.
标记的解决方案并不总是有效。您必须确保项目文件中引用的项目 GUID 是您尝试引用的项目的正确 GUID。Visual Studio 确实允许它们在某些情况下不同步。您可以使用文本编辑器从项目文件中获取项目 GUID。因此,如果项目 A 引用项目 B. 在文本编辑器中打开项目 B.csproj,从标签中复制项目 GUID。然后在文本编辑器中打开项目 A.csproj,并确保您使用的是正确的 GUID。在这种情况下搜索项目名称“B”。它应该在 。将标记中的 GUID 替换为正确的 GUID。保存并重新加载。当然,还要确保删除对项目的基于文件的引用。您只需要项目引用。
回答by clement
I've kill all VS instances, deleted the SUO, launch sln and it worked for me...
我已经杀死了所有 VS 实例,删除了 SUO,启动了 sln 并且它对我有用......
回答by Shinigami302
Remove the reference dll, Build (will get errors), ADD THE reference (you removed) then build again ... F12 on your function should then work (worked for me).
删除引用 dll,构建(将得到错误),添加引用(已删除)然后再次构建......然后你的函数上的 F12 应该可以工作(对我有用)。
回答by jiangping
I figured out how to solve my problem from this post, maybe it will also work for some of you.
我从这篇文章中找到了解决我的问题的方法,也许它也适用于你们中的一些人。
I followed these steps:
我按照以下步骤操作:
- Close the solution.
- Delete the intellisense database file for the solution: .ncb
- Open the solution.
- Rebuild the solution.
- 关闭解决方案。
- 删除解决方案的智能感知数据库文件:.ncb
- 打开解决方案。
- 重建解决方案。
(I believe either step 3 or 4 regenerates the intellisense database file when it is missing)
(我相信第 3 步或第 4 步会在缺少智能感知数据库文件时重新生成它)
Intellisense, "go to defintion" and "find all references" should be working again.
Intellisense,“转到定义”和“查找所有引用”应该再次起作用。


