“Go To Definition” in Visual Studio only brings up

2019-01-16 08:02发布

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 Meta data file instead of going to the source.

Some Points:

  • All the source code is C#, there is no VB.Net
  • All the projects are in the same solution
  • Yes, everything is a project 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).

Has anyone else seen this behavior and/or know how to fix it?

24条回答
Lonely孤独者°
2楼-- · 2019-01-16 08:10

After deleting dll files from Visual Studio first and adding them back manually from Solution Explorer --> Website --> Add --> Reference and enabling 32-bit Applications in IIS fixed it for me.

查看更多
何必那么认真
3楼-- · 2019-01-16 08:14

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.

查看更多
你好瞎i
4楼-- · 2019-01-16 08:14

I figured out how to solve my problem from this post, maybe it will also work for some of you.

I followed these steps:

  1. Close the solution.
  2. Delete the intellisense database file for the solution: .ncb
  3. Open the solution.
  4. Rebuild the solution.

(I believe either step 3 or 4 regenerates the intellisense database file when it is missing)

Intellisense, "go to defintion" and "find all references" should be working again.

查看更多
相关推荐>>
5楼-- · 2019-01-16 08:14

I had a circular reference between the two projects involved (which is a no-no). Had to restructure my code a bit in order to solve it as both projects were truly dependant on each other. Removing one of the references solved the intellisense problem. It was logically flawed and I probably wouldn't have noticed without this error!

查看更多
Melony?
6楼-- · 2019-01-16 08:17

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.

However, if you install ReSharper, you'll go to source code even if you added your reference to a dll/exe using Browse tab.

查看更多
何必那么认真
7楼-- · 2019-01-16 08:24

I just ran into this problem on VS 2013. Something I could (did?) not isolate was changing the GUID in the CSPROJ file. Since the CSPROJ files are checked into SVN, I could not simply change the GUID on my local dev. Instead, I was constantly SVN reverting the local change each time it happened.

First, I had to solve the changing GUID problem.

  1. Revert the CSPROJ to the checked-in version.
  2. Open the CSPROJ via a text editor, NOT VS.
  3. Extract value from the pristine CSPROJ file.

    {B1234567-5123-4AAE-FE43-8465767788ED}

  4. Open the SLN file via a text editor, NOT VS.

  5. Locate the Project reference in the solution.

    Project("{FAE12345-3210-1357-B3EB-00CA4F396F7C}") = "Some.Project", "....\assemblies\Some.Project\Some.Project.csproj", "{B7654321-5321-4AAE-FE3D-ED20900088ED}" EndProject

  6. The first GUID listed is the Solution GUID. For every project referenced in your SLN, you should see this value repeated at the first argument. The GUID following the .csproj is the one you want to replace with the pristine GUID.

This should solve the first problem, but the "Go to Definition" landing in meta data is not solved. In our SLN file, there is a master project (our web site), so its entry in the SLN file should contain a ProjectSection entry with multiple GUID values. Here is an example:

ProjectSection(ProjectDependencies) = postProject
{AC50D230-24C4-4DCA-BAAD-355E6AF5EFBD} = {AC50D230-24C4-4DCA-BAAD-355E6AF5EFBD}
EndProjectSection

Notice the missing GUID in this collection is the one from my pristine project.

  1. Add the missing GUID as the last entry between ProjectSection and EndProjectSection. The format appears to be per-line, and it is {GUID} = {GUID}.
  2. Save the file.
  3. Open your solution.
  4. Right-click a reference in the newly-added project and "Go to Definition."
查看更多
登录 后发表回答