Tool to automatically reformat whole C# source tree in VS2008? - c#

I have inherited a large source tree, C#, Visual Studio 2008.
It has many quality issues, one of them is that the code is generally badly formatted.
I am looking for a tool, preferably a plugin for Visual Studio, that will go over the whole solution and apply the same basic formatting that Visual Studio itself applies when, for example, you close a curly brace around a block of code.
Any suggestions?

In vs2005, you can do Edit->Advanced->Format Document for a single file, which will (I believe) do what you're asking. I assume vs2008 has a similar function somewhere.

ok, so why not try a macro, if you want to do the entire solution, there is a vb example here
http://blogs.msdn.com/kevinpilchbisson/archive/2004/05/17/133371.aspx
it opens each file and applies the same formatting that VS does, but the macro will work across an entire solution (may not be that wise to run it if your solution is huge), beyond reflecting the internals of the format document code in VS and inling it into some sort of stream, this appears to be the easiest way to make use of what i consider to be a very useful feature in visual studio

ReSharper should do what you're looking for. Have a look at their Code Cleanup Feature. This can be applied to multiple files including the whole solution.

if you have already set your preferences in the vs editor options, you should be able to hit CTRL K, CTRL D which will tidy the code based upon your preferences

Here's the simple way (for me)...
I have my Visual Studio set to reformat on "Paste"
Tools | Options | Text Editor | C# | Formatting
**Automatically format on paste** (checked)
When I hit an ugly file, I do CTRL-A, CTRL-X, CTRL-V -- poof, instant format :)
Hope this helps.
Kevin

Related

How to copy code from Visual Studio to MS Word with EVERY highlight exactly as it is?

I am making a report about my program and I need copy all the code to an MS document. The problem is that I need to keep every colour as it is. I've tried using Notepad++ for this and online converters but it didn't seem to work as some colours got lost. For example if I have something like this:
public void SomeFunc(String someArg){}
The type "String" seems to lose its colour (the language is C# btw). I also don't want static images in the document (like screenshots of the code or when using the "Insert object" method in MS Word). Is there any way to accomplish this?
So I was looking for an answer to this and this is what i found.
Go to Extensions (manager) -> look for: Productivity Power Tools -> install & restart VS.
Now when i copy/paste from VS to Word, literally all syntax colors are being copied over 1:1. even the background color is matched.
I use VS 2019 preview these days.
Visual Studio | Tools | Options | Text Editor | Advanced
Check box “ Copy rich text on copy/cut", and
Check box “ Use accurate classification” this keep the color for Classes, enums, etc...
it did work for me.
For those stumbling upon the same problem, the answer from #siggi_pop worked well for me but I had to perform a Paste Special > Formatted Text (RTF) into MS Word.
A simple Copy / Paste left the code unformatted .
VS2019: It seems like there is a limitation for number of lines you can copy with formatting.
Something like around ~300 lines each time.
Search for same file in "file manager"
Rright click on the file
Choose "open with" option then choose "wordpad"
Your cpp file is now open in formatted text
Copy it to MS word

Is there a Visual Studio add-in for populating resource files from strings in a code file?

I'm maintaining a WinForms application which was not written using any development patters conducive to localizing the classes in the project which were not directly associated with forms, or the code-behind partials of the forms.
Thus, there is MessageBox() code with English text in it in almost every code file. I'd like to find a tool which will "scrape" those strings from the code, insert the strings in a resource file, and substitute a call to the resource with the substituted string in a comment.
Does such a tool exist?
See ReSharper 5 Internationalization Features
When ReSharper finds a localizable
string, it helps you move it to a
resource file with only a couple of
clicks. You can optionally search for
identical strings and refactor them to
use the new resource item.
Hope it helps.
The Visual Localizer projects focuses on this very issue and is free.
Resharper can do it. There is a Resharper plugin called RGreatEx that has a lot of localization refactorings for strings. I'm guessing you are looking for something free though, and both of these cost money. RGreatEx also hasn't seen updates in more than two years.
EDIT: Did some more searching, and found this tool on CodePlex. It doesn't supporting pulling strings into resources, but it does have side-by-side editing of multiple resource files to ease writing string translations.
ReSharper is of course the best in this field, as it can scan all strings in your code base and let you know which can be placed into resources.
But if you intend to use a free tool, Microsoft does have an open source one here,
http://resourcerefactoring.codeplex.com/
You have to manually scan all files using this tool as it is not as smart as ReSharper.
You can also use T4 templates to do this kind of thing. They're built into Vis Studio as of 2005 I think.

format ugly c# source code

I found a C# game http://www.codeproject.com/KB/game/BattleField.aspx that does what I need to learn. The source code is poorly formatted and hard to follow. I used Visual Studio's format document, but the format is still bad. How do I reformat the source code to make it easer to read?
Visual Studio's format document should help.
That being said, if you want more elaborate reformatting, you'll need a third party tool. Resharper, for example, has the option of reformatting the code, but also of doing code cleanups (where small refactorings are done on the fly to make the code itself nicer).
They provide a temporary free trial - you can see if it works for your case and this project.
That codes requires refactoring and commenting. Visual Studio can help, but this work is not fully-automated as you understand :)

Navigate files with VisualStudio 2008

I am currently developing with VisualStudio 2008. I find it increasingly difficult to find files when the number of files and projects increase. The situation become so bad that I literally have to spend 10-20 seconds to find code I want to work on when switch between files. Sounds like not a lot of time, but this can be very annoying because it breaks the "coding flow".
I believe this is a general problem with all IDEs. But I still find it easier to work with Eclipse. One particular example is that in Eclipse, I could apply some key shortcut to find implementations defined in an Interface.(I have forgotten which key shortcut though, after not working with it for about 1 year.) Another example is that in VS 2008, rightclick->Find all references will find all occurrences containing the selected text(Update: This accusation is incorrect. Thanks for pointing it out); while similar operation in Eclipse will find all occurrences where the selected class/variable are referenced. Personally, I find the Eclipse way is better for file navigation.
This could be due to my inexperience with VS IDE. So, I am looking for suggestions to improve the file navigation experience so that I can get some more time for actual coding.
I have used the navigate buttons but they are only useful for small number of files.
Thanks.
I agree wholeheartedly about ReSharper. If you don't want a "paid" solution though, a useful Visual Studio shortcut is
CTRL + ,
it gives a list of recently edited files.
CodeRush is a free alternative to ReSharper which you might find useful too.
Kindness,
Dan
Have a look at Jetbrains Resharper. Ctrl N or Ctrl Shift N. To jump quickly to files by type name or by file name. Also you can control Click Classes to navigate to them instantly.
I can't even work in visual studio without it anymore. It virtually eliminates the need for the solution explorer
SamTools for Visual Studio 2005/2008 (and I have a build for 2010 if someone needs it). The particular feature that's handy here is the Solution File List.
You can right click the tab of any open document and Find In Solution Explorer or Show In Windows Explorer
You can right click in the Solution File List for the same
Unlike other solutions to this problem, this is a properly docking tool pane so it fits in great. Ctrl+Alt+F places you in the Filter box with the current text selected, so it's very easy to work with.
Oh and it's free/GPL. :)
Solution File List http://wiki.pixelminegames.com/images/8/88/SamTools_SlnFileList.png
Dpack is also a free alternative with some nice file navigation shortcuts, but Resharper is the bomb.
BTW, they should have some more of this stuff in vs2010, which is in beta right now (I think)

Which (third-party) debug visualizers for Visual Studio 2005/2008 do you use?

I guess this topic is often overseen, but is rather useful when debugging your code. Just today I have stumbled across this simple yet effective visualizer that visualizes images (it's on a german blog, but I guess the code content is self-explanatory):
link text
I would like to know which debug visualizers you use in your daily work with VS2005/2008.
I use Mole.
Mole was designed to not only allow
the developer to view objects or data,
but to also allow the developer to
drill into properties of those objects
and then edit them. Mole allows
unlimited drilling into objects and
sub-objects.
Also check out Xml Visualizer v.2 (http://codeplex.com/XmlVisualizer)
There was a sample on an MSDN blog for the Microsoft.Xna.Framework.Matrix, I think it was. I later made my own, but it was still good.
Since I do a lot with Graphics and GDI, I found the Graphic Debug Visualizer invaluable. The Bitmap Visualizer it is based on is good too, however I had to recompile it for Visual Studio 2008 (and change the references to the various VisualStudio extension dll's).

Categories

Resources