开发者

Easier way to copy the path to a file or directory to the clipboard in visual studio?

To accomplish this I've been right-clicking the file or directory and then selecting Show in Windows Explorer, and then copying the path out of the address bar.

Is there an add-on or macro that can make this task easier?

I'm aware that you c开发者_运维知识库an drag a file from Solution Explorer into the editor and it will write out the path, but when doing web development I don't always want the server path, sometimes I want the local path.


Look at PowerCommands extension

http://visualstudiogallery.msdn.microsoft.com/e5f41ad9-4edc-4912-bca3-91147db95b99?SRC=Home

Among others, it contains "Copy Path" command for files and folders

UPD: Also, another option: right-click the tab of open document and there will be "Copy Full Path" command. It's built-in, no extensions needed


You can just select the file in the 'Solution Explorer' file list and hit CTRL+C. It automatically copies the file path to your clipboard.


I've found one more option of how to solve it without plugins (for VS 2015 and above; not certain about previous versions) Go to "Tools" -> "Customize..." -> "Commands" tab. Choose "Context menu:" and "Project and Solution Context Menus | Item" and you can add any existing Command.

In order to copy path, choose Category "File" and "Copy Full Path" command. Will add button only for files in Solution Explorer. This works for projects as well but you should choose "Project and Solution Context Menus | Project" (copy path of .vcxproj file).

It doesn't work for solutions and I don't understand actually why.


Tools > Options > Environment > Keyboard

You can set your own shortcut keys for anything. The two that are most relevant to this post are "File.CopyFullPath" and "File.CopyRelativePath". I created my shortcut to just be used in "Text Editor" and it has worked great.

This was asked for VS2010 and I'm using VS2019, so it is an old question, but still relevant. I knew about the file header right click menu, but for some reason I didn't think about the shortcut keys until I read this question. Posting in case this results in a quicker fix for anyone else.


The CTRL+C doesn't work for me on MSVS 2017. Use the copy as path extension here. Then right click on file in solution explorer -> Copy as path (or assign a shortcut). I find that it works very well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜