visual-studio 强制解决方案资源管理器在 Visual Studio 2005 的编辑器中选择文件

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

Forcing the Solution Explorer to select the file in the editor in visual studio 2005

visual-studio

提问by Jeffrey

In Visual Studio 2005, whenever I would view a file in the main editor, the Solution Explorer would find and highlight that file. Some time ago, this stopped working and the Solution Explorer would do nothing.

在 Visual Studio 2005 中,每当我在主编辑器中查看文件时,解决方案资源管理器都会找到并突出显示该文件。前段时间,这停止工作,解决方案资源管理器什么也不做。

This has become quite a pain since following a chain of "Go To Definition"s can lead you all over your solution. Where is the setting to turn this back on?

这已经变得非常痛苦,因为遵循一系列“转到定义”可以引导您完成整个解决方案。重新开启此功能的设置在哪里?

回答by OwenP

Click on the Tools → Options menu. Select the Projects and Solutions → General option page.

单击工具 → 选项菜单。选择项目和解决方案 → 常规选项页面。

Make sure "Track active item in Solution Explorer" is checked. That should do it.

确保选中“在解决方案资源管理器中跟踪活动项目”。应该这样做。

回答by Owen

I like to keep this option turned off (especially when working with a big project), but it's useful to be able to find the file in the tree now and then. I found a way to do this here.

我喜欢关闭此选项(尤其是在处理大型项目时),但能够不时在树中找到文件很有用。我在这里找到了一种方法。

I hope I'm not being too verbose here, but here's the guide to making this work that I wrote for my work's wiki:

我希望我在这里不会太冗长,但这是我为我的工作 wiki 编写的完成这项工作的指南:

  1. Go to Tools->Macros->Macro Explorer.
  2. In the Macro Explorer tree that comes up, right-click MyMacros, and then New Module....
  3. Call the new module SyncItem (if you want).
  4. Right-click the new module, then Edit.
  5. Paste this into the code window. (I don't know or care if the Imports lines are necessary; they're just there by default.)
  1. 转到工具->宏->宏资源管理器。
  2. 在出现的宏资源管理器树中,右键单击 MyMacros,然后单击 New Module...。
  3. 调用新模块 SyncItem(如果需要)。
  4. 右键单击新模块,然后单击编辑。
  5. 将其粘贴到代码窗口中。(我不知道也不关心是否需要导入行;默认情况下它们就在那里。)

code:

代码:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module SyncItem

    Sub SyncSolutionExplorer()
        DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
        DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
    End Sub

End Module

The macro is most useful if you bind it to a keystroke. Here's how to do that:

如果将宏绑定到击键,则该宏最有用。以下是如何做到这一点:

  1. Go to Tools->Options, then select Environment->Keyboard.
  2. Find the new macro in the list (start typing "syncitem" or similar in the search box).
  3. I choose Alt-Shift-T(which this dialog box likes to call Shift-Alt-T) for, um, "Tree," I guess? If you're a fan of Edit.LineTranspose, whatever that is (I think it swaps the current line with the following one), then you might like to pick a different shortcut.
  1. 转到工具->选项,然后选择环境->键盘。
  2. 在列表中找到新宏(开始在搜索框中键入“syncitem”或类似内容)。
  3. 我选择Alt- Shift- T(这个对话框喜欢称之为Shift- Alt- T),嗯,“树”,我猜?如果您是 的粉丝Edit.LineTranspose,无论那是什么(我认为它会将当前行与下一行交换),那么您可能想选择不同的快捷方式。

回答by Sub-Star

I just discovered that ReSharpercan do what Owen suggests. I have disabled the "Track active item in Solution Explorer"-setting, and when I'm working in a source-file I press Shift + Alt + L and the file is selected in the Solution Explorer. I haven't changed the binding, so I guess that is the default. The upside to this is that you don't have to create a macro and then bind it to a keystroke (although not very difficult, it still has to be done). The downside is that ReSharper isn't free, so it's probably not a solution for everybody.

我刚刚发现ReSharper可以按照 Owen 的建议行事。我已禁用“在解决方案资源管理器中跟踪活动项目”设置,当我在源文件中工作时,我按 Shift + Alt + L 并在解决方案资源管理器中选择该文件。我没有更改绑定,所以我想这是默认设置。这样做的好处是您不必创建宏然后将其绑定到击键(虽然不是很困难,但仍然必须完成)。缺点是 ReSharper 不是免费的,因此它可能不是适合所有人的解决方案。

回答by Trumpi

  1. Navigate to Tools -> Options
  2. Select "Projects and Solutions" in the tree view on the left
  3. Select "Track Active Item in Solution Explorer"
  1. 导航到工具 -> 选项
  2. 在左侧的树视图中选择“项目和解决方案”
  3. 选择“在解决方案资源管理器中跟踪活动项目”

回答by brendan

Tools->Options->Project and Solutions->General

工具->选项->项目和解决方案->常规

Check the box "Track Active Item in Solution Explorer"

选中“在解决方案资源管理器中跟踪活动项目”框

回答by rob

Tools -> Options -> Environment -> Keyboard

工具 -> 选项 -> 环境 -> 键盘

Assign the command

分配命令

View.TrackActivityinSolutionExplorer

View.TrackActivityinSolutionExplorer

(I use Alt+L)

(我使用 Alt+L)

then to use always hit Alt+L followed by Alt+L

然后使用总是按 Alt+L 然后按 Alt+L

which turns on the feature and locates the file in the source tree and then turns it off again to stop the location bouncing around when you do not want it to.

这会打开该功能并在源树中定位该文件,然后再次将其关闭以阻止该位置在您不希望它时跳动。