Disclaimer: this is about using Visual Studio and its GUI. It is not about a VS extension.
Context:
I like to have toolbar buttons to sort and remove using directives in .cs files. In VS 2015 there were two dedicated commands (and hence buttons) to do this, each with their own icon. Now in VS 2017 there's a single command to do that (Remove and Sort Usings) but it has no icon, just text. See pciture below, command is there, but text only:
I remember ages ago, with VS 2010 I believe, you could somehow hack VS existing commands so to show custom icons. I think it was a matter of adding picture files in a special location, and either name them in a special way or reference them from some configuration file. I totally forgot how, but it was doable.
Question:
Does anyone know if this is still possible with VS 2017 and how? After some search I was not able to find an answer.
BTW question is similar to this unanswered one, but in my case it's about a regular VS command, not an external tool command.
TA
Edit: as suggested in comments, this CommandingImage extension used to work on VS 2010. It has not been updated, nor open-sourced, nor ported. Maybe someone as found its successor.
With Visual Studio 2017, it can be done using Visual Studio SDK where you can either write a extension or extend a existing menu command with a icon declared in the .vsct file. A simple example for the your need can be found here.
If you want to go for a simpler way, I would suggest to either use PowerCommands or Resharper to do the same. See here.
Related
I know that I can set up Visual Studio to debug through the .NET framework source code.
But is there a way that I can browse the code while NOT debugging - i.e., being able to press F12 or "Go to definition"?
I thought that if that feature isn't built into Visual Studio then there may be a plug-in that might add it?
There is a very new feature in Visual Studio 2017 version 15.6
You can see decompiled source code without any plugin! Btw, Ref12 doesn't work for VS2017.
Tools > Options , expand Text Editor > C# > Advanced, and enable "Enable navigation to decompiled sources (experimental)".
Ref: https://learn.microsoft.com/en-us/visualstudio/ide/go-to-and-peek-definition?view=vs-2017#view-decompiled-source-definitions-instead-of-metadata-c
With ReSharper it's possible to browse .NET sources by enabling ReSharper -> Options -> Tools -> External Sources -> Navigation to Sources.
After enabling this option new menu item "Navigate To -> Decompiled Sources" appears by right click on type/method/whatever.
Navigation also works with F12 for me.
I just discovered this extension that pretty much addresses my problem. The only thing is that it opens the source in the browser rather than in Visual Studio, but it's no big deal because even in the browser you can click the source code to navigate to types etc.
It was presented on Scott Hanselman's blog a couple of days ago:
Community member and fabulous coder Schabse Laks has created a Visual Studio extension for VS2010, 2012, and 2013! This extension sends calls to Go To Definition (or pressing F12 on a symbol) directly to the code online (when it's .NET Framework code, not yours).
You can download this companion "Ref12" Visual Studio Extension now! Just Goto Definition on any .NET type we have source for and it'll launch your default browser so you can explore the .NET Framework source yourself! Thanks Schabse!
Update:
As per the comments, for VS 2022 and .NET Core, use this fork of the extension: https://marketplace.visualstudio.com/items?itemName=EfreyKong.Ref12-VS2022
I downloaded the .NET Framework source code from here http://referencesource.microsoft.com/netframework.aspx.
Since I am working with .NET 4.0, I chose ".Net/4" from the list. (What is ".NET/8.0" in that list? No idea.)
I wrote some scripts to rearrange the bloody mess they give us:
Into a reasonable hierarchy of directories;
To remove duplicated code (why is every file doubled, or was my install bad?);
Rename all top-level namespaces to not conflict with native ones baked into Intellisense.
Example: System.Windows.Controls -> xSystem.Windows.Controls
Then follow these steps:
Create a new Visual Studio project of type "Class Library"
Remove all references -- yes, even the system ones.
Drag/drop all of your massaged .NET code into the root of your project.
Wait about 30 minutes for VS processing. VS will appear to freeze; be patient.
Intellisense/ReSharper still complains about heaps of problems, but now I can right click and select "Go to Declaration/Implementation".
Visual Studio is about 600MB with this project loaded.
I am using Visual Studio 2013 Ultimate.
1. Choose menu: TOOLS \ Extensions and Updates...
2. Choose Visual Studio Gallery \ Search Results. Search term: Ref12.
3. Download then install.
4. Restart Visual Studio.
5. Try: Click mouse on Class or method, press F12 and see result at http://referencesource.microsoft.com/
I've never tried this but supposedly the code is publicly available:
[Edit]
http://referencesource.microsoft.com/
There is the .NET Mass Downloader, but I think the straightforward answer to your question is, no.
However I now see Microsoft has made the code more easily downloadable.
Nevertheless note that even for your own code, when not debugging, unless you have the project open, VS does not help you locate source code (even though when you find it yourself break points will work when you start debugging again, if the .pdb files correspond).
I am working on documenting a winForms project that isn't completely done being written, meaning there is another programmer who write the code right now. So I've already wrote some importent comments in a copy of the project.
In addition I use sandcastle to bulid the help file.
My question: what is the best way (if there is one) to copy the comments from the old copy of the project to the new version of it?
Maybe sandcastle can do something like import a documentation to a project?
I know it wasn't so smart to do so, still I have to check if there is a way to save the documentation work.
Visual Studio has a built in file difference function you can use to see where the two files are different. It should be then a matter of copy and paste of the changes you have made over to the "gold" copy of the file your other programmer has changed.
This link shows how to Compare two files in Visual Studio 2012
"You can invoke devenv.exe /diff list1.txt list2.txt from the command prompt or, if a Visual Studio instance is already running, you can type Tools.DiffFiles in the Command window"
I want to make a visual studio's add in that has the ability to sort resource files alphabetically every time someone edits a resource file. I'm not looking for a solution, but I have never used the Visual Studio sdk before. I simple want to know if anyone that has experience with the Visual Studio sdk may know if this is possible? Also any suggestions on how to start making an addin are appreciated.
If you have never used visual studio extensibility, I recommend you this page:
Make a solution notebook tool window
There is some useful information about how to interact with visual studio for saving data in sln and suo files, and also you can find information about some attributes you can use to tell visual studio what your package (or plugin) needs to do.
It's a general knowledge thing although, not directly related to what you want to do.
this link is about how to listen to some specific events visual studio fires, it shows you general way of creating listeners in your plugin
this one is actually about what you need to do (it tells you how to catch the event fired before visual studio saves a file)
and the most important one: the source code for creating a custom source control for visual studio, that's where I found most of the info I needed to understand visual studio extensibility
with all these links you should get something to start with, and of course you have the official msdn documentation about extending visual studio
What you'll need to do is creating a plugin that will listen to events fired when an item is about to be saved in visual studio. I don't think there is a specific event for resx files, so you'll probably have to test which file is saved, but that should be all.
Once you have the item, you can find the physical file and sort it.
Another thing, I found out that the events declared in the DTE object don't really work (at least for me it didn't), that's why I recommend you to implement the listener pattern to catch the events you need.
Hope this helps
I actually did exactly that.
You can find the source code for the extension in GitHub. It shows you how the get handles for files from the Solution Explorer, add context menu actions, write to the output menu, etc..
Do you know an add-in for visual studio which adds properties for C# projects?
csproj file format is very powerful but only small amount of options can be changed through the standard properties page. For instance, I want to have several configurations and each of them should include it's own references. Or I just want to change the type of project from winforms to wpf or other one. In order to do stuff like that developer has to edit csproj by hands in text editor instead of using properties.
If you know that such add-in doesn't exist, do you think that it could be popular on codeplex? or only small amount of developers realy need it? what is your opinion?
How is it going?
To edit project files inside of Visual Studio I use PowerCommands, but those things you can change "using properties" are those in Project Menu -> [Project Name] Properties. What PowerCommands does (among other things...) is allow you to easily edit the XML of a project opened inside Visual Studio so you get all the benefits of using Visual Studio to edit XML. Makes sense?
XML is hierarchical, so hardly you can fit it comfortably on a property list better than on a text editor.
About "I want to have several configurations and each of them should include it's own references", try creating templates for your projects, take a look there: Visual Studio Templates.
So... you are looking for addins at codeplex? why not take a look at http://visualstudiogallery.msdn.microsoft.com there are free and paid addins, an some form codeplex too. While you are on it, look for "Productivity Power Tools", "VSCommands 2010", "AllMargins" and "VS10x Code Map". I use them all, and they are certainly worth a look. [Hmmm... I also use CodeRush, you can get CodeRush Xpress for free from http://www.devexpress.com ;)]
Hope of being of help.
A little late to the table but I wanted to remove VSCommands 2010 because all I use it for really is the edit project file and I don't like to just have extensions hanging around if I am not using them. I discovered from this blog:
http://blogs.msdn.com/b/habibh/archive/2009/07/01/the-quickest-way-to-edit-a-visual-studio-project-file.aspx
"There is a quick and easy way of editing your Visual Studio project file. When a project is "unloaded", either because you explicitly chose to unload the project using the "Unload Project" command or Visual Studio failed to load the project for some reason (e.g. project upgrade failed), you can right click on the project in Solution Explorer and select the "Edit " command, as shown below."
It works like a charm!
Visual Studio 2008 got two great features for c#, which is called "sort using directives" and "remove unused using directives".
I'd like to call the "sort using directives" every time I format the code using ctrl+k,ctrl+d.
Or, even better, I would like to be able to reformat all c#-source files in a project, and call "sort using directives" for all source files.
How can I do this? Opening every cs-file by hand and typing these functions before every checkin is tedious!
You can do it all for a solution or project using "PowerCommands for Visual Studio 2008". After installation, you just need to right-click on a project or solution and "Remove and Sort Usings" is in the context menu.
EDIT: As noted in comments, there are also PowerCommands for Visual Studio 2010.
Another option is CodeMaid, a free and open source Visual Studio extension. It allows you to sort usings, remove usings, format document, remove/insert blank lines, remove whitespace, and quite a few more cleanups. It can run on save, solution wide, etc. Follow the link to the visual studio gallery to see more details.
It also lets you conditionally enable/disable individual portions, so with it you can disable remove unused usings and do sort only if you want as you mentioned in the comments.
Disclaimer: I wrote it ;)
ReSharper can do this for you (among other reformatting options) and it allows you to do an entire solution in one go.
I recommend you record a macro of you invoking the feature manually. Then you can just save the macro and put a button for it on the toolbar. This way you'll also have a foot in the door to get started really customizing your IDE.