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!
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).
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.
My job forces me to work in Visual Studio and .NET. I'm attempting to streamline the experience, somewhat successfully. (TFS still thwarts me.)
Right now, I want to work with multiple Solution Explorers, as we have a Visual Studio solution containing a multitude of csproj files. Creating a new Solution Explorer view for each commonly-used project would be great, except for this - all of the tabs and titles say "Solution Explorer".
Is there any way to change the title of the Solution Explorer window and tab? Is there any way to set the title to the title of the root solution or project file? (If there's an extension that will do this, I will happily install it.)
Thank you.
Edit: It looks like my question wasn't understood very well. The project conforms to regular standards - it's one Solution with multiple Projects, with a highly-nested directory structure. Basically, instead of having to scroll a lot, and constantly open and close nodes in the tree view, I'd like to have multiple Solution Windows to help facilitate this. Visual Studio provides an option called New Solution Explorer View in the context menu, which will open a new Solution Explorer window with a target object at its root. I want to do this for the commonly-used projects in my solution, but I want each Explorer instance to be named so that I can keep them in a single pane and click between them. Make sense?
Hope I've appeased the VS enthusiasts.
Double Edit: This is the feature I'm looking for. Is this possible through an extension?
There exists a visual studio-extension named Multiple Solution Explorer Tools, which extends the default behavior of the New Solution Explorer View-command:
Multiple Solution Explorer Tools Visual Studio Extension
New Solution Explorer instances gets persisted across solution unload and load.
The toolbar provides an icon () to rename the current solution explorer view.
The extension currently supports Visual Studio 2017 and 2019.
I've got a Visual Studio 2013 package written in C# where I need to make some changes in the items and their attributes in a C++ project file while Visual Studio 2013 is running and has the project loaded. Actually, it could also be OK to save the project file at the point when the whole solution is being saved.
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="Test">
<MyItemToChange Include = "TestItem">
<MyMetadata1ToChange>Value1</MyMetadata1ToChange>
<MyMetadata2ToChange>Value2</MyMetadata2ToChange>
</MyItemToChange>
</ItemGroup>
<!-- The rest of the file -->
</Project>
In previous Visual Studio versions I used the Microsoft.Build.Evaluation.Project class to change the items and the metadata of the project. When you have the reference to the project, you can either accessed the XML structure of the project directly through Project.Xml property or get a hold on different Microsoft.Build.Evaluation.ProjectItem and use the interfaces found there.
However, since Microsoft has changed the structure of Visual Studio in their 2013 release, though the Microsoft.Build.Evaluation.Project is not deprecated, you can't access the C++ projects any more through Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadedProjects as the collection is empty. However it still works if you want to access C# projects. (As a matter of fact, browsing deep into the objects while debugging you can find that they still use the same Microsoft.Build.Evaluation namespace for inner representation.)
Since I can't access the Microsoft.Build.Evaluation.Project any more, I need an alternative to
access the project otherwise than using the
Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadedProjects
write project items and metadata while Visual Studio 2013 is running.
Unless I've missed something, the following are not good for my purposes:
Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage.SetItemAttribute sets only attributes to items that are displayed in the Solution Explorer. "MyItemToChange" is not displayed in the Solution Explorer
Opening the file and manually editing and saving it. Unless you know how to suppress Visual Studio's warning about a changed project and how to auto reload it, it is not a way to go.
Note: You can close the solution, open the project file manually, edit then save it and reopen the solution. It would work fine, the data is there, unless the files are under source control. Now it opens up a whole lot of new issues (why EnvDTE.DTE.SourceControl.CheckOutItem() doesn't work, etc.) So I still think I would be better off if Visual Studio would handle writing data to the project file.
Reflection. Yes, as I mentioned before, I could dig into internal classes to get a hold on the "original" Microsoft.Build.Evaluation.Project, and Microsoft.Build.Evaluation.ProjectItem, but first of all, it is quite unsafe for future uses and as far as I remember, you cannot be sure that if you modify these now internal classes, the project will know that it is dirty and has to be saved.
I'm glad to have any suggestions as I'm really running out of options.
Thanks.
Well, I have worked out a workaround, not a real solution for the problem.
What I do right now is the following:
Ask the user whether they're OK with closing the whole solution and saving everything. If not, I cancel the whole procedure: EnvDTE.DTE.ItemOperations.PromptToSave
Try to ask Visual Studio 2013 to check out the project file for me in source control using EnvDTE.DTE.SourceControl.CheckOutItem() method. If it throws an exception (NotImplementedException), I use a bodge to check out the project file. That is, I write a custom property into the project file using Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage.SetProperty() method.
Close the whole solution. EnvDTE.DTE.Solution.Close()
Open the project file using the System.Xml.XmlDocument class. Edit. Save. Oh, and remove my silly property written in the 2. point (the one used to force Visual Studio 2013 to check out the file in source control.)
Reopen the solution. EnvDTE.DTE.Solution.Open() At this point the user might be asked again to confirm some source control options.
Why is it just a workaround not a proper solution?
It's ugly. :)
Methods are abused for things they are not meant to be used (writing a random property into a project just to force source control checkout)
It wouldn't work if closing the solution / project is not an option. E.g.: if you need to save something during build or while they are editing the solution / project / source files; or if you have to do it often not just once during the lifetime of a project.
I'm still looking for the proper solution for the problem. But until someone could tell me how it is done, I have to live with this current implementation.
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.