I am trying to search a large solution for any usages of a given namespace or its members, say, System.IO.
Resharper's Find Usages allows me to find references to System.IO, but only when used explicitly. If a file declares using System.IO; then uses any of the namespace's members without the full name, only the using reference is found. I need to find any usage of any member of the namespace in each file as well.
Can this be accomplished in Visual Studio, Resharper, or any other plugin do this search for me?
Place cursor on keyword using of line using System.IO. Then you can use the normal Find Usages (Shift+F12).
This works with ReSharper only.
As of ReSharper 2019.2.2 (2019/08/28), a solution wide Show Usages of Symbol feature still does not exist.
Workaround:
Search Everywhere for namespace: Ctrl+T, then enter using System.IO
Save results in new windows: Alt+Enter
You may wish to pin the window so that it stays open.
For each result, Show Usages of Symbol:
Place cursor on the using keyword.
Ctrl+Shift+Alt+F12
This is definitely not ideal, but it is a systematic way to get the job done.
Update: October 2, 2019
JetBrains has confirmed that this feature is not currently supported by ReSharper, but they are considering adding it to the road map.
Feature Request: solution wide "Show Usages of Symbol"
Update: October 17, 2019
JetBrains has just confirmed that they have added this feature to ReSharper, and it will be available as of 2019.3 EAP1.
See: Feature Request: solution wide "Show Usages of Symbol"
To Show Usages of Symbol, use the Find Dependent Code option which will enable you to:
look for project references
look for NuGet packages
search at project level
search at solution level
Related
I am using Visual Stuido 2022 to code my C# project.
Is there a way to configure VS using (.editorconfig file) where a new line is added before and after the namespace?
So my class will look like this
using System;
namespace ProjectName.Tests;
public class Test
{
}
instead of
using System;
namespace ProjectName.Tests;
public class Test
{
}
I'm not sure there is a Visual Studio native way of doing this.
There is definitely not a way to do this in .editorconfig with Visual Studio alone (meaning no plugins). About halfway down Namespace declaration preferences, it talks about csharp_style_namespace_declarations, and the code formatting sample when that value is file_scoped looks like
// csharp_style_namespace_declarations = file_scoped
using System;
namespace Convention;
class C
{
}
which appears to get you part of the way there (blank line after using). When you look at the supported formatting rules, the list is pretty brief.
If you have ReSharper there is a way. These settings in .editorconfig will do what you want:
resharper_blank_lines_after_file_scoped_namespace_directive = 1
resharper_blank_lines_after_imports = 1
If ReSharper is not an option, here are 3 possible paths to take, none all that great. They certainly aren't simple solutions.
try to find something in the Visual Studio Marketplace
write a .NET Analyzer that is configured via .editorconfig (ref. this page)
raise an issue on Developer Community, and hope they get to it.
Like the other guy said,
No, not with editor config (out of the box).
Resharper can do this; you can build a custom format for your code and tell it, for example, where you want certain sections like imports below the class for some weird reason ;) ...of course, with that spacing around those sections.
But now you have to get ReSharper licenses for all your devs. The Resharper devs are very cool, and Jetbrains has been building quality software for a few decades. Maybe I'm sentimental.
Well, there is another option if you don't want to pay...
In DevOps roles of the past, I've used Roslyn to build extensions for custom formatting.
Build a custom Rosyln analyzer.
https://learn.microsoft.com/en-us/visualstudio/code-quality/roslyn-analyzers-overview?view=vs-2022#severity-levels-of-analyzers
You can build a custom code suggestion with this of configurable severity.
It's pretty easy, too, thanks to Rosyln, but you must think a little backward. Let me know if I can help more.
StyleCop.Analyzers has a bunch of formatting related rules that you can enforce and, in some cases, automatically fix across your codebase.
Unfortunately it looks as though there is not yet support for file-scoped namespace formatting in the way you want. There's a PR to add it here, so if you really wanted to have this you could get that PR across the finish line, or make your own build:
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3512
This issue might also be worth a look:
https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3578
On the internet (Microsoft website, e.g.), there's plenty of information on how to create a visualizer.
However, I'd just like to know, which visualizer is currently used by my debugger?
For Native code, that question is very simple:
Menu "Tools", "Options", "Debugging", "Output window", "General Output Settings", "Natvis diagnostic messages", set to "Verbose".
In the Watch-window, enter .natvisreload
Verify the "output" window: all native visualisers are mentioned.
However, now I'm working with managed code, and in my watch-window, I see entries like:
{User Info: 12 User(s), 6 Group(s)
{VDX File Change Info (117 files)}
…
Those entries give me the impression that for this managed code, a/some visualiser(s) is/are used, and I'd like to customise, expand or modify it/them, but therefore I need to know where it/they is/are (sorry for the bad sentence, I just want to emphasize that I have no clue of the whereabouts of the visualiser(s)).
How can I know which managed visualizers are used in my Visual Studio session?
Thanks in advance
Dominique
You'd have to integrate with the debugger and see what types are being evaluated in the watch/autos/locals windows.
From there you can find those types in the list of modules loaded (using debugger apis) and then search for the attributes that Leo mentioned.
There's no debug output anywhere about which type visualizers are loading for managed code. It's actually stored on the types themselves.
How can I know which managed visualizers are used in my Visual Studio session?
According to the document Create custom views of managed objects:
In C# and Visual Basic, you can add expansions for custom data using DebuggerTypeProxyAttribute, DebuggerDisplayAttribute, and DebuggerBrowsableAttribute.
In .NET Framework 2.0 code, Visual Basic does not support the DebuggerBrowsable attribute. This limitation is removed in more recent versions of the .NET Framework.
DebuggerTypeProxy Attribute
DebuggerDisplay Attribute
Hope this helps.
So I thought I'd run this out there, and see if I was missing something idiotic.
I developed a small my-use-only VSIX extension, and in one of my toolwindows, I'm using the code to set the foreground/background color:
Foreground="{DynamicResource {x:Static vsfx:VsBrushes.ToolWindowTextKey}}"
Background="{DynamicResource {x:Static vsfx:VsBrushes.ToolboxBackgroundKey}}"
The vsfx: namespace is referenced as:
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0"
I see the 10.0 referenced there, and for me, that's expected as I originally did this up in VS2010. Now that my work has made me upgrade to VS2012, the XAML designer is giving me the following error on those two SynamicResources. The error reads 'The resource {x:Static vsfx:VsBrushes.ToolWindowTextKey} could not be resolved.' and like for the second one.
Now, note that the project still builds and runs, and can be loaded into VS2012. However, the colors are all off (standard, don't match the theme that VS is set to.)
Any thoughts on what to check or look for?
Cheers -
Mike.
I ran into the same question as you guys do, and found out the follow facts:
[VsBrushes/VsBrush] v.s. [EnviromentColors]:
VsBrushes and VsBrush are basically the same thing, supported in VS2010/2012/2013;
EnviornmentColors is only in VS2012/2013, not supported in VS2010;
EnvironmentColors is still envolving, more colors will be added in for new themes; VsBrushes/VsBrush are relatively static.
[VsBrushes] v.s. [VsBrush]:
Good thing about “VsBrushes” is that it checks whether a specific color name exists during building.
Bad thing about “VsBrushes” is that is has to specify the VS namespace and assembly version in the XAML file head, which is inconvenient. (e.g. xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0")
Thanks.
Use EnvironmentColors class as it's stated here:
http://msdn.microsoft.com/en-us/library/vstudio/jj991932.aspx
In Intellij or Eclipse, when I start typing a class that I haven't imported yet, I will get suggestions. For example if I type 'Lis' I will most likely get a load of suggestions of various List classes that are in my classpath. If I don't know how to spell the class properly or don't know exactly what I'm after I can work it out quickly just by typing. In VS 2012 even with Resharper, I can't reproduce this behavior. It really does make a difference, is it not possible in VS?
I use the Import Symbol Completion feature for this.
Just write part of the name (or camel case initials) and press: Shift+Alt+Space (VS shortcuts) or Ctrl+Alt+Space (IntelliJ shortcuts)
This works even for types/symbols whose namespaces have not yet been imported (ReSharper will add them).
Is it possible somehow to color specified code in specified color in any version of visual studio? For example, make background of
if( VERIFY( ... ) )
green and background of
if( ! VERIFY( ... ) )
red? Maybe some addon exists or some version of visual studio has such functionality?
NO PLUGIN NEEDED
According to MSDN and this tutorial, you can set user-defined keywords for syntax highlighting in a
usertype.dat file, which you should save in the same directory as Visual Studio's msdev.exe, or devenv.exe for VS.NET.
Now restart Visual Studio.
Then in VS you can set the font properties for those keywords.
Edit: BTW, see the download here for a predefined usertype.dat with a lot of keywords ready to use.
You can use Resharper's "ToDo Items" to accomplish this.
Resharper -> Options
Create a pattern.
Here you can specify the color, pattern, icon etc. This should already give you colorized code, the rest is optional, but makes it easier to find the patterns.
(look at existing patterns for the syntax, or check the docs)
You can use filters to find the patterns, and combinations of patterns
You could create a filter that contains both your patterns for instance.
use Resharper -> Tools -> ToDo-Items to search for the patterns
I don't know of an existing addin that does anything like that but I do know that Developer Express, the company that makes CodeRush, makes the addin engine freely available as a product called DxCore. This makes is much easier to create an addin that decorates the Visual Studio text editor. In Visual Studio 2010, a lot of the extremely difficult code that DxCore abstracts is no longer necessary as there is an official extensibility model for decorating the editor.
Here's a link to some DxCore plugin samples on Google Code.
No, but you may be interested in FxCop, it's more elaborate, but it should allow you the ability to detect the case you're talking about (via a custom rule, if it doesn't exist). It may be more work to set up, but it's worth it (especially if work in a team, and/or, have an existing CI system).
According to the VS Extensibility form Moderator, Ed Dore, it is not possible:
http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/93fc6d61-cfdb-432d-8541-d7dce498cef5/
Unfortunately, no. The code implementing the document tabbing was developed with native Win32 code, and currently doesn't have any VS SDK or automation hooks into it.
It is too bad as this would be beyond useful. (Keep track of different types of files and such.)