Is there a tool for Visual Studio that will automatically format source code (C#) on saving it? This would be useful for my multi-developer team to keep the code looking uniform, especially before the code is checked into the source control repository.
CodeRush or ReSharper come to mind.
PowerCommands for Visual Studio: http://code.msdn.microsoft.com/PowerCommands
If you install the addin and look for PowerCommands under the Tools->Options menu, there's two tick boxes for "Format document on save" and "Remove and Sort Usings on save". It's one of my favourite addins for that exact functionality.
Many (and me) use StyleCop and set it to analyse files on a build and I set it to flag warnings as errors so issues must be resolved prior to a successful build.
I prefer this method as obfuscating the responsibility to a third party which automatically styles the code without developer intervention I feel loses something, over reliance on this method could lead to a developers code becoming worse and worse without them even knowing it.
It seems more preferable that the developer be notified of issues and forced to fix them, so as to hopefully overall improve their coding skills.
EDIT: I know this is an old post I just thought my thoughts could be helpful to somebody happenning accross this page.
Related
We work on a large legacy application. The oldest code base is between 20 and 30 years old. Many developers have worked on it over the years and different architectures and programming styles were used.
Most code is C#, some C++ and very little VB6. My concern for this question is the C# code.
As a group of architects, we would like to clean up the code and make it more maintainable. We use ReSharper with Visual Studio 2013 (soon VS 2015). Some developers are keen on "making ReSharper happy" and have it show no warnings for a source code file, while others don't even use ReSharper or ignore any warnings signaled.
So we figured, the only way to have the whole team adhere to the same rules is to have it checked in the Continuous Integration build and fail if there are still ReSharper warnings.
That works very well on new solutions, but in legacy code it can show dozens if not hundreds of warnings in every class.
If we turn on all the rule checking on all files at once, our software would not build for month.
Fully automated code refactorings in ReSharper are dangerous in my experience because it can change the logic in some cases.
Question 1:
So how can one go about introducing the rule checking for a large legacy application?
We use TFS2013. I learned that Team City has a ReSharper plugin that allows to leave old code alone and only check what was modified in a check-in. Unfortunately we don't have the liberty to change our Build-Server.
Question 2: But does anyone know how that Team City plugin works? Question 3: Are the entire files of changed classed checked, or just the lines that were touched? Question 4: How about rules that apply to the structure of the class (like the order of public, protected and private members)?
I would love to have something similar like the difference checking of the ReSharper Plugin for TeamCity for TFS, but I could not find anything. If you know of anything like that, let me know.
I would be happy to hear how any of you have mastered to introduce rule checking.
I found a description of what TeamCity allows you to do: TeamCity
The important part concerning my question is this: TeamCity can be configured to compare the issues found per source file with the issues from the last build. If there are more issues of type warning or error, you can make the build fail.
To my knowledge, TFS does not have this capability and I am not aware of any add-ons that would accomplish something similar.
However, I believe that this difference issue checking is one of the most promising to improve legacy applications.
I'm not sure if the title is accurately describing what I'm trying to ask...
Basically, how does Visual Studio look at a code file in a CSPROJ and determine references for a method or variable, or if a using statement is not being used in the code? Obviously it's not just doing simple text parsing, and it seems to work before ever doing a build so I don't think it's referencing the assembly/CLR.
Is there an API that I can tie into from an external app, if I have the user select their CSPROJ or SLN file and be able to report on unused using statements in files, or methods/vars that aren't being called anywhere in their code?
I'm asking because I'm considering building some sort of reporting tool to show areas where code cleanup could occur, but I'm not really sure where to begin.
Thanks!
EDIT: As a followup question, is there a similar tool already out there?
Visual Studio does compilation on the fly, in order to determine many of the things like this, in addition to providing functionality like Intellisense.
Right now, the compilers are all a "black box" and not directly usable. The Roslyn project has the goal of changing this, allowing the full breadth of code analysis being done to be usable. It's currently in a CTP, and could be used now.
EDIT: As a followup question, is there a similar tool already out there?
Many third party extensions, such as Resharper, provide much of this functionality (such as their Safe Delete refactoring and Solution Wide Inspections).
Is it possible to get style cop to fix any issues? Or any other tool to fix the style cop issues?
I understand that some of the issues may be complicated to code for but this one "SA1101: The call to UpdateButtonLocations must begin with the 'this.' prefix to indicate that the item is a member of the class." looks like it should be fairly trivial to fix.
From reading around I think Resharper can be integrated so that it warns you of any issues as you code, and while this is useful it won't help me on an existing project with 100s of warnings similar to the one above!
There is a style cop addin for ReSharper available (Look here). With that you can have the option to clean it manually or within the "Clean Code" functionality of ReSharper do it automatically.
Resharper does have a clean solution that will do this to all files in the solution. Good idea or bad idea is up to you :)
There are many refactoring options built into Visual Studio 2010, and add-ons like Resharper (commercial) add many more.
These are mostly automatic and will speed up fixing such issues.
I am using tortoise SVN with Ankh. I really have spent too much time tweaking and cleaning mess from time to time and I lost hope in educating each every developer on how to use things properly. I am sorry but I am fed up and tired restoring the repository/reverting/fixing merges manually, sometimes even having to write some code again.
So here's my question : Is there a chimpanzee-friendly solution for source control privileging Simplicity over Flexibility ? Projects and teams are small and I figured out that we just need VERY simple and basic chekout/checkin mechanisms, with no flourish, and limited functionality and features. That would help me stop being paranoid about projects integrity.
I know that there is no easy way to do this and there is minimum techinicity and discipline required, but I ended up wondering if we Really needed all that in our case, as in the long run, it causes more trouble than it helps.
Your problem sounds like it has more to do with process and branching strategies than anything else.
If your developers know to always get the latest code before checking in and resolving conflicts locally, running all tests etc, you will already have a leg up.
Educate your developers instead of trying to use a dumbed down SCM (that in the future will probably not be adequate to your needs).
As for branching strategy - I had found that branch per feature is the most natural way to work and mostly avoids merge conflicts.
Changing SCMs will not help with your issues if you don't tackle process and branching.
First, I would suggest that you force developers to clean up their own messes, not do it for them. By doing it for them, you are only encouraging them to stay ignorant. By all mean, be a resource and provide help for them, but make them do it themselves. They will quickly learn what they have to.
Second, there are few options that have the kind of integration with VS that most developers would like. SVN is one of them. Team System is another (but a much more expensive and complciated solution). Visual Source Safe is also an option, but it's really an old, out of date system that hasn't been updated since 2005 (and even that, that was largely a patch job to a system that hadn't been updated in 7 years before it).
If you want free, there is nothing worth using that is simpler than Subversion. Everything else will be ancient technology (like CVS) that will have even more problems. There are several free SCM's that are more powerful, like git and Mercurial, but you would have even more problems. If you're willing to pay, then many third party tools have better merge and visualization tools. One I like is AccuRev.
There are also some better commercial SVN plug-ins for visual studio that may help as well. I've not used any of them, but they may improve the developers use of SVN.
Try the combination of Mercurial and Tortoisehg as GUI.
You can also use it from Visual Studio with VisualHG.
Every developer is free to clone and manage her own repository.
Once you reach an agreement you can push up to a colleague's repository or a central location.
To aid with adoption, you might convince others to watch the DVCS video on the FogCreek Kiln page.
See what-makes-merging-in-dvcs-easy and similar SO discussions regarding the relative ease of merging.
I would say that every developer that works in a team should have a strong understanding of source control principles. Maybe you should get better developers! :-)
To answer your question I have always found Team System wonderful and very flexible. With such good IDE integration, it can be configured to ensure best practice in source control. However, it is quite a big source control system so may be over the top for your purposes.
I believe the issues is more of process than product.
Strict written documentation and process might work
Keep it as simple as possible.
You might make adherence to the process a contractual obligation.
That said I have had very good luck with Visual SVN for Visual Studio.
It is easy to use and integrates well.
If that is too hard, might revert to TortoiseSVN which is pretty idiot proof.
As for an alternate super simple product I know not of such a product, but
if you really need something lightweight, then datestamped and named zip
files is a the poor and ignorants form of source control. Merging and
restoring is a bitch though.
Both Developer Express' CodeRush and Whole Tomato's Visual Assist X are excellent tools. I've found that CodeRush has a prettier UI, and it's "marker" mechanic is extremely useful, and it has a larger palette of refactorings available. On the other hand, CodeRush occasionally makes mistakes with it's refactorings, particularly when working with C++ projects. Therefore I usually disable CR there. VAX doesn't have near the number of refactorings as CR does, but they all consistently work. VAX is also much better at unobtrusively making Visual Studio better -- doing things like improving features that already exist, instead of CR's method of almost building an IDE inside of an IDE.
Long story short, I like both tools, and would like to use both tools. The problem is that they do a few things that conflict. I would like to set things up such that whenever there is a conflict between a CodeRush command and a Visual Assist command, the VAX command "wins". Is there an easy way to do this?
What ReSharper does is that when it has an option that conflicts with the default Visual Studio settings, it installs a marshal that when you choose the option, asks you which one you want to win. That gives us an option.
The option would be to find out what options conflict between these two tools and do one of the following:
Implement a marshal that asks you which option to choose or, the one you probably prefer
Force the action of this option to the tool you prefer.
It may be possible to device a macro that performs this job. To implement such a script, it's important to know what type of options are conflicting. Are you talking about shortcuts, menu options, toolbar options? With this information and your Visual Studio installation, it should be possible to automatically update all the options and pick the one you want.