简体   繁体   English

复制 Visual Studio 的文件扩展名

[英]Copy filename extension for visual studio

Is there any extension in Visual Studio to copy file name of a selected file to clipboard or code? Visual Studio 中是否有任何扩展名可以将选定文件的文件名复制到剪贴板或代码? There are extension available in Visual Studio Code like this but not for Visual Studio. 像这样的 Visual Studio Code 中有可用的扩展,但不适用于 Visual Studio。

You can use the following command (Language C#) with my Visual Commander extension to copy the file name of a selected file to clipboard:您可以使用以下命令(语言 C#)和我的Visual Commander扩展名将选定文件的文件名复制到剪贴板:

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
{
    System.Windows.Clipboard.SetText(System.IO.Path.GetFileName(DTE.ActiveWindow.Document.FullName));
}

To insert it in code:要将其插入代码中:

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
{
    EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
    ts.Text = System.IO.Path.GetFileName(DTE.ActiveWindow.Document.FullName);
}

Sergey's answer is a workaround, and another is that you can also try to use Copy Full Path to get what you want. Sergey 的回答是一个解决方法,另一个是你也可以尝试使用Copy Full Path来获得你想要的。

Right-click on the file under Solution Explorer --> Copy Full Path and it will copy the full path of the file.右键单击解决方案资源管理器下的文件->复制完整路径,它将复制文件的完整路径。 Although this method includes the path, you can remove it manually, after all, this is the closest way to vs. comes.这个方法虽然包含了路径,但是可以手动去掉,毕竟这是最接近vs的方式来了。

If the two solutions do not meet your requirements, you could suggest a feature on the DC Forum .如果这两种解决方案不符合您的要求,您可以在 DC 论坛上推荐一个功能 And if you do it, share the link here and anyone who is interested in it will vote it to help improve this ticket.如果您这样做,请在此处分享链接,任何对此感兴趣的人都会投票以帮助改进这张票。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM