1

I would like to have "File.CopyRelativePath" as an option in the Context Menu of Solution Explorer when I right click a file.

I am using Visual Studio 2022

I have managed to put the command in the menu by adding it at: Tools - Customize - Commands - Context menu - Project and Solution Context Menus | Item

enter image description here

There I have added File.CopyRelativePath and given it a shortcut too.

enter image description here

But when I see it in the context menu it is disabled.

My new custom Context Menu item is disabled :(

How do I enable the menu item so I can start using it?

1 Answer 1

1

TL;DR: You can't force the command handler to be enabled. However, you could implement your own handler for this command (or a brand new command with the same label).

More details:

There's a lot of documentation about how commands work in VS, but to quickly paraphrase: command handlers implement an Execute method to do the operation and optionally a QueryStatus method to determine if the command is currently able to execute. In this case, QueryStatus is determining that the command should not be enabled.

The implementation of this command's QueryStatus (I peeked) looks at the currently active WindowFrame, and requires that it be associated with an open document. Once the focus is in Solution Explorer, it would determine that the command should not be enabled as Solution Explorer is not a document window.

(The implementation, similarly, uses properties of the frame that are only set for a document instance. It wouldn't understand an input from another type of window.)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your reply. Well basically I just want to be able to copy the relative paths of the files in my project. This is a normal feature of other IDEs, but for some reason I have not yet been able to do it in Visual Studio 2022. Seems like a bit of a venture if I should implement my own command handler, I will take some look at your link and re-read your answer.
Also, it's totally a good feature to file as a suggestion! It really does seem lacking, and in many ways would make as much if not more sense if it were exposed on the Solution Explorer item. ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.