所以基本上我只想在我右键单击名为“example.cs”的文件时显示命令。由于我使用的是 Visual Studio 2019,我不能使用旧的 BeforeQueryStatus
道路。而是使用 ProvideUIContextRule
我的 Package 类上的属性。目前看起来像这样:
[ProvideUIContextRule(_uiContextSupportedFiles,
name: "Supported Files",
expression: "CSharp",
termNames: new[] { "CSharp" },
termValues: new[] { "HierSingleSelectionName:.cs$" })]
对于文件本身的扩展名,这完全看起来不错。那么有什么方法可以将其限制为
example.cs
?顺便说一下,我正在使用这个 Guide .
最佳答案
所以对于和我有同样问题的其他人。解决方案相当简单,关于 MSDN:
(...) The term evaluates to true whenever the current selection in the active hierarchy has a name that matches the regular expression pattern(...)
所以基本上改变
{ "HierSingleSelectionName:.cs$" }
至 { "HierSingleSelectionName:Program.cs$" }
只会显示以 Program.cs
结尾的文件.这导致分号之后的所有内容都包含正则表达式。
关于visual-studio - 仅在特定文件名(+扩展名)的上下文菜单中显示命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57166170/