Visual Studio

How to split a solution into projects

Yesterday, a colleague of mine asked for some guidance on how to partition a Visual Studio solution into individual projects. Instead of simply answering his email I thought that blogging about it may be useful for others as well, so here are my rules.
 

Published: 11-02-2010 by Dennis Doomen | 0 Comments | 0 Links to this post
 

TFS Development Practices Part 2: Peer Reviews

What is it?

A formal review of all code and artifacts related to a requirement or task by another person than the original developer. Rework because of review comments must be revalidated afterwards.

Why would you do that?

  • Because the average developer
    • introduces 10-50 bugs per 1000 lines of code (at least, according to Moore’s Law)
    • is not always aware of the potential pitfalls of particular code constructs (hence coding guidelines)
    • is not always up to date with all available constructs in a new C# version
    • does not have full awareness of all the out-of-box solutions offered by the .NET Framework, open-source sites or commercial vendors
    • often does not realize that an ingenious and elegant solution may be too complex to understand by others.
    • sometimes loses sight of the overall solution and the initial goal when working on a some piece of code too long.
  • Because it helps improve the awareness of, and the understanding behind your company’s coding guidelines.

Notice that the amount of necessary review work can be reduced by introducing the Pair Programming practice.

What’s the bare minimum you need to do?

  • Find issues in the interpretation of the functional requirements.
  • To verify compliance against your coding guidelines or standards.
  • If you don’t have one, consider the Aviva Solutions C# 3.0 Coding Guidelines. Notice that these are an extension to Visual Studio’s Code Analysis, so the latter is still worthwhile.
  • To find any loose ends such as TODOs or incomplete code. Resharper 4.5 includes a nice tool window that quickly shows an overview of all TODOs in your current solution. Resharper 5.0 even includes solution-wide analysis that finds dead code.
  • To ensure that all code is easy to read and understand. For instance, all members and types have a comprehensive name and non-trivial code is annotated with code comments.
  • To ensure that each and every check-in improves the code base, rather than introducing software rot.

What’s the usual thing to do?

  • To ensure that all naming of code elements matches those of the functional design, preferably using Domain Driven Design’s Ubiquitous Language.
  • To check for the usual pitfalls such as God classes or methods that are way too long.
  • To find any redundant code or code that is unnecessarily complex and requires refactoring.
  • To find any code constructs that may put other developers on the wrong foot and therefore jeopardize future maintenance.
  • To find code constructs that can be replaced with a simple call to a previously developed generic class or .NET Framework construct.
  • To stimulate the use of design principles such as S.O.L.I.D. or the design patterns defined by the likes of Martin Fowler and Eric Gamma so that the overall code quality increases.

 How do you do that?

  • It is important to make sure that all files related to a particular piece of functionality can be easily found. Use a Check-in Policy to associate each and every change with a corresponding work item such as a Scenario, Task or Bug. Since a major change may involve multiple check-ins, especially in a larger team where multiple developers work in the same areas of your code base, Change Sets provide insufficient traceability.
  • Use a logging form or something similar to review every piece of code related to a particular work item and store it on the project’s team site.
  • Alternatively, copy and paste the code into Microsoft Word, and use its reviewing features to annotate the code with comments and improvements.
  • Or even better, install TeamReview and its corresponding Review Response work item and add review comments directly from inside Visual Studio’s code editor, while keeping them together under the associated work item. Also check-out this poster illustrating the underlying review workflow.

Published: 01-02-2010 by Dennis Doomen | 0 Comments | 0 Links to this post
 

TFS Development Practices Part 1: An Introduction

As part of my many assignments, I’m compiling a bunch of best practices into a set of development guidelines for bootstrapping our internal projects using TFS. I’ve decided to share these with the community so that others may benefit from it as well. Beware that these practices are not new nor in any way invented by myself. I'm merely trying to get some good resources together in a nice compact format.

So what are my goals?

  • To provide insight into the benefits of applying well known best practices on software development projects.
  • To provide examples of applying those practices on new and ongoing projects and explain how to gain the most of out them.
  • To help you jumpstart a new project or professionalize running projects.

And what do you gain?

The goal of these posts is to end up with a set of development practices that provide the following benefits:

  • Allows you to more quickly and accurately assess the impact of new requirements.
  • Promotes building well designed software that allows changing functionality with lesser risks (even during a running project).
  • Promotes a consistent code-base that solves similar problems using similar solutions, everywhere.
  • Strives for a functionally consistent software system. For instance, ensuring that date fields look the same all over the application).
  • Attempts to prevent code duplication so that you never have to make changes at multiple locations if you change a particular piece of behavior or logic.
  • Eases the effort for deploying a new release by removing as many human actions as possible.
  • Provides traceability on where a particular piece of functionality has been realized technically.
  • Improves the developer experience when working on an existing or shared code-base (e.g. readability, purpose and goal of a block of code).
  • Provides a safety net that reduces and possible prevents the chance of running into regression problems.
  • Attempts to prevent common mistakes or misinterpretations by introducing common rules and recommendations.
  • Strives to a situation where each and every member of the team is aware of the project’s affairs.
  • Promotes any endeavors that improve the self-education and self-organization of teams.

Published: 04-01-2010 by Dennis Doomen | 0 Comments | 0 Links to this post
 

TFS: Getting all Checked Out files via TF.exe

Edit 13 may 2009 : There is another good alternative. One of my friendly colleagues pointed out  to me you can also install the latest TFS  Power Tools (October 2008).

You will then have a nice UI  with some new features. Some of those features are:
1) “Find in Source Control Explorer”.
It’s possible to show the current checkout status in any folder in Source Control Explorer.
2) A new “Team Member” node in Team Explorer.
For each member you can see for example the “check-in history” or “Pending changes”.

------------------------------------------------------------------------------------------------------------------

When you are working with Team Foundation Server (TFS), sometimes you require an overview of all Checked Out files. For example, you want to be sure your colleague can go on holiday after he/she finished his/her work with a mandatory check-in.

I was unable to see all Checked Out files by any user with Team Explorer, so I started looking at the command line tool TF.exe. After that, it was really simple to get an overview.  You can even integrated the command line tool in Visual Studio. You just add a new "External Tool".

 

First, the TF.exe command line tool:

The location of the command line tool:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\tf.exe

To change/add a local workspace:
tf.exe workspace

All checked out files in $/FavoriteProject:
tf.exe status $/FavoriteProject /user:* /recursive

All files checked out to Tim:
tf.exe status /user:Tim

All checked out files in $/FavoriteProject using Login Credentials:
tf.exe status $/FavoriteProject /user:* /recursive /login:yourDomain\tim,yourdomainpassword

------------------------------------------------------------------------------------------------------------------

Second, a  short walk-through to use the tf.exe command in Visual Studio IDE.

  • - Select from the menu: "Tools / External Tools ..."
  • - In the "External Tools" dialog, click the "Add" button.
  • - Enter a title that will show up in the Tools menu (ie. "Show FavoriteProject Checkouts")
  • - Enter "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\tf.exe" for the command
  • - Enter "status $/FavoriteProject /user:* /recursive for the arguments.
  • - Make sure that the "Use Output Window" check-box is checked.
  • - Make sure that the "Prompt for Arguments" check box is checked. (Optional, if you want to use login-credentials)
  • - Click OK to save.
  • - You can now execute the tool from the menu. The output will be shown in the output window.

example_tf


Published: 12-05-2009 by Tim van der Weijde | 0 Comments | 0 Links to this post
 

We've just passed more than 1000 unit tests

In November 2008, me and some fellow colleagues have started working on a new project where we use Test Driven Development to gain a highly maintainable and highly testable system. Today, we have reached our 1000st unit test,  or better, 'specification'. The term Test Driven is a bit misleading since TDD is really a design process, which has nice little granular unit tests as a side-effect. Anyway, we tried to reach this point before Easter, but obviously we were professional enough not to add some dummy tests :-)
 


Published: 14-04-2009 by Dennis Doomen | 0 Comments | 0 Links to this post
 

Format source code in your blog posts

There is a nice add-in for Visual Studio that allows you to copy your source code as HTML. This can be useful for example when you want to add a code sample to your blog posts.
The add-in is called CopySourceAsHtml (CSAH). It gives you an extra option in your edit- and context menu: 'Copy as HTML...'. The copied HTML reflects your Visual Studio color settings.
 
 
You can also use an online tool at http://www.manoli.net/csharpformat/. There you can paste your source code in a textbox and convert it to HTML. You will need to add an extra stylesheet to your blog website and add a reference to it in the <head> section of your page.

Published: 10-03-2009 by Martin Opdam | 1 Comment | 0 Links to this post
 

Changing the diff- and merge tool for TFS

TFS has it's own tool for comparing and merging different versions of files. If you don't like this default tool and rather use another, this can be configured in TFS. You can configure this in Visual Studio via tools -> options -> source control -> visual studio team foundation server -> configure user tools.

image

James Manning describes in more details how this can be done on his blog. He also mentiones some alternative tools that can be used, and the necessary command arguments. This is the list of tools he mentions:

Compare Tools:

Product Command Arguments
TFS default diffmerge.exe %1 %2 %6 %7 %5 /ignorespace
WinDiff windiff.exe %1 %2
DiffDoc (for Word files) DiffDoc.exe /M%1 /S%2
WinMerge winmerge.exe /ub /dl %6 /dr %7 %1 %2
Beyond Compare bc2.exe %1 %2 /title1=%6 /title2=%7
KDiff3 kdiff3.exe %1 --fname %6 %2 --fname %7
Araxis compare.exe /wait /2 /title1:%6 /title2:%7 %1 %2
Compare It! Wincmp3.exe %1 /=%6 %2 /=%7
SourceGear DiffMerge DiffMerge.exe /title1=%6 /title2=%7 %1 %2
Beyond Compare 3 BComp.exe %1 %2 /title1=%6 /title2=%7
TortoiseMerge TortoiseMerge.exe /base:%1 /mine:%2 /basename:%6 /minename:%7

 

Merge Tools:

Product Command Arguments
TFS default diffmerge.exe /merge %1 %2 %3 %4 %6 %7
KDiff3 kdiff3.exe %3 --fname %8 %2 --fname %7 %1 --fname %6 -o %4
Visual SourceSafe ssexp.exe /merge %1 %2 %3 %4 %6 %7
Araxis compare.exe /wait /swap /a3 /3 /title1:%6 /title2:%7 /title3:%8 %1 %2 %3 %4
Beyond Compare (2-way merge) bc2.exe %1 %2 /savetarget=%4 /title1=%6 /title2=%7
WinMerge (2-way merge) winmerge.exe /ub /dl %6 /dr %7 %1 %2 %4
Guiffy guiffy.exe -s -h1%6 -h2%7 -hm%9 %1 %2 %3 %4
Ellie Computing guimerge.exe --mode=merge3 %3 %1 %2 --to=%4 --title0=%8 --title1=%6 --title2=%7 --to-title=%9
SourceGear DiffMerge DiffMerge.exe /title1=%6 /title2=%8 /title3=%7 /result=%4 %1 %3 %2
Beyond Compare 3 BComp.exe %1 %2 %3 %4 /title1=%6 /title2=%7 /title3=%8 /title4=%9
TortoiseMerge TortoiseMerge.exe /base:%3 /mine:%2 /theirs:%1 /basename:%8 /minename:%7 /theirsname:%6 /merged:%4 /mergedname:%9

Published: 17-01-2009 by Martin Opdam | 2 Comments | 0 Links to this post
 

Vertical guidelines in Visual Studio

Using a maximum length for the lines of code in your source files, makes the files easier to read and maintain. A vertical guideline in the Visual Studio text editor is a useful utility visualise the maximum line length.
The following registry setting will make Visual Studio show a vertical guideline at the specified position (in this case at character 130):
 
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor]
"Guides"="RGB(128,0,0) 130"
 

Published: 07-05-2008 by Martin Opdam | 0 Comments | 0 Links to this post
 

Moving to Visual Studio 2008 and Team Foundation Server 2008

During the Christmas holiday, I started migrating my customer's development environment to the newest set of Microsoft development products. We already planned to do this a bit earlier, but since we had to wait for the first VS2008 CTP of the Patterns & Practices Web Service Software Factory : Modeling Edition, we simply couldn't. We are now two weeks further, so I decided to share some my experiences since then.

General

  • Well, I did not ran into any problems after the upgrade to .NET 3.5 while converting the existing Visual Studio 2005 solutions. I know about the advice to first upgrade the solutions, and then plan the introduction to .NET 3.5, but I couldn't resist.
  • If you choose to upgrade your solution to .NET 3.5 during the automatic conversion, it seems that only the web application projects (or web site projects) are modified to target .NET 3.5. I'm not entirely sure about this, but at least, that is what I've observed. Unfortunately, you have to go through each and every project one by one and change its framework version.
  • Beware that if you upgrade an existing ASP.NET 2.0 web site (or web application) to .NET 3.5, Visual Studio will automatically add an assembly redirect to your web.config that forwards any dependencies on the 1.0.61025.0 version of the System.Web.Extensions assembly to the corresponding .NET 3.5 assemblies. We did not notice any differences (yet), but if you do, you may need look in that area. All our existing control libraries (Obout, Telerik and the ASP.NET Ajax Control Toolkit) kept working without a glitch. There is a .NET 3.5-specific update of the AJAX Control Toolkit though.
  • You can't update existing WCF Service References (the .map files created from within VS2005) anymore. You need to re-add the reference from scratch. See this post for more information.
  • Although the installation of .NET 3.5 should not cause any troubles, we did not notice an anomaly after we installed Visual Studio 2008 next to Visual Studio 2005. The reason for this is that .NET 3.5 installer also installs two service packs on top of .NET 2.0 and 3.0. Apparently, we were using something that was wrong in the first place, but not detected by the compiler. Lucky, we invested heavily in unit tests and this one issue surfaced almost immediately.
  • The best thing you should do after upgrading to Visual Studio 2008 is read about LINQ. We are using Nhibernate in our data access layer and don't need LINQ-to-SQL, but still, LINQ is the best thing since Generics. Even if you don't like the query expression, simply include the System.Linq namespace and enjoy the power of the many extension methods it adds to your arrays, lists and other collection classes.

Add-ins & Tools

  • Beware that the Guidance Automation Extensions installer can only be installed once. You either have to choose to install it on Visual Studio 2005 or on Visual Studio 2008, but not both. Consider that if you're thinking about gradially migrating to 2008.
  • The Web Client Software Factory does not officially work with VS2008 yet, but it appeared that the hack suggested by this knowledge base article works quite well. A more official version is expected in February.
  • I discovered that the same trick also works for the Enterprise Library 3.1 installer. Obviously, EntLib is not compiled to .NET 3.5, but up to now, I did not find any issues related to that. Since the only changes with respect to EntLib is the service pack that the .NET Framework 3.5 installer applies to .NET Framework 2.0
  • The TFS Administration Tool is a beautiful little commodity that allows you to add or remove user accounts from TFS, WSS and SQL Reporting Services in a single click. Unfortunately, if you chose to upgrade Windows Sharepoint Services to 3.0 while upgrading from TFS 2005 to 2008, the tool does not work with WSS 3.0. For the time being, you have to fall back on the WSS Site Settings, but this will change soon.
    Update: TFS Administration Tool 1.3 has been released with full WSS 3.0 support. 
  • After installing the Guidance Automation Extensions of May 2007 and the software factories, some of my colleagues using the Team Developer edition of Visual Studio 2008 ran into multiple occurrences of the "System.IO.FileLoadException: Could not load file or assembly 'Microsoft.VisualStudio.TemplateWizardInterface, Version=9.0.0.0". As explained in this post, removing a single redirect from the devenv.exe.config solved the problem. It did not occur on a Team Suite install.
  • I personally believe that JetBrains' Resharper is the very best tool since Visual Studio. Version 3.1 does work with Visual Studio 2008, but its excellent code analysis features have some trouble with the new C# 3.0 keywords. Until the Early Access Program for Resharper 4.0 opens, I found an acceptable workaround that gives (most of) the best of both worlds.
    Simply disable Resharper's Code Analysis function and let it use Visual Studio's Intellisense . You may have to re-enable the IntelliSense settings under Tools->Options->Text Editor->C#->IntelliSense. Even though Visual Studio's IntelliSense cannot compete with Resharper's, assigning the Alt-Enter keyboard shortcut to View.ShowSmartTag gives you a bit of Resharper-style behavior.

Unit testing & Team Build

  • After upgrading, we noticed that while running unit tests, the Enterprise Library Logging Application Block could not find its enterpriselibrary.config (we moved the EntLib settings into a dedicated .config). At first, I thought it was a compatibility issue between .NET 3.5 and EntLib, but we also noticed that log4net was suffering from the same thing. After further investigation, I discovered that this is in fact a bug in Visual Studio 2008. As a workaround, we now have every test start with the following hack.
    AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);
  • Right after upgrading your test project, you may notice that the ExpectedException attribute does not seem to work anymore. This usually happens because your test project will still try to load version 8.x of the Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly (which is part of Visual Studio 2005). Simply remove it and then reference the correct version 9.x of the assembly again. See also this post for more information.
  • If you have, like me, set-up your own workspaces from within your Team Build .proj file, you can now remove this stuff. The Build Definition dialog box allows configuring exactly which part of your source control tree should be included in the build.
  • In Visual Studio 2005, it was not possible to configure Team Build to run all the unit tests part of an assembly without falling back on a .vsdmi test file. However, Buck Hodges provided a nice replacement for MSBuild's TestToolsTask that did the job quite nice. Fortunately, Microsoft integrated this functionality into Team Foundation Server 2008 out of the box. Simply define an <ItemGroup> with a <TestCountainer> that includes a wildcard pattern for the assemblies that should be included. For instance:
    <TestContainer Include="$(OutDir)\%2a%2a\%2aTest.dll" />
  • Don't forget to go to Tools->Options->Test Tools->Test Execution and limit the number of Test Results during unit testing. Oh, and check out the new shortcut keys for starting/debugging the unit tests visible within the current context.

Obviously, this is not all. During the next weeks, I'll try to update this post with new experiences and solutions to common issues.


Published: 11-01-2008 by Dennis Doomen | 0 Comments | 0 Links to this post
 

TechSessie over Visual Studio 2008 en C# 3.0 op 29 november en 4 december

Op de TechEd in Barcelona heeft Microsoft de afgelopen week aangekondigd dat de RTM versie van Visual Studio 2008 nog voor het einde van de maand beschikbaar komt. Het zal je dan ook niet verbazen dat er veel te horen en te zien was over alle nieuwe mogelijkheden en handigheidjes die Microsoft's belangrijkste ontwikkelomgeving te bieden heeft.

Wil jij ook weten wat Nested Master Pages zijn of hoe je met LINQ-to-SQL je database object-georienteerd kunt benaderen? Of wil je graag zien welke productiviteitsverbetering de ASP.NET designer je biedt? Kom dan op 29 november of 4 december naar de interactieve presentatie van Dennis. Hij zal je aan de hand van voorbeelden en demo's laten zien wat hij allemaal op de TechEd geleerd heeft.

Gewenste voorkennis
Kennis van C# 2.0 en Visual Studio 2005 is gewenst.

Over Dennis
Dennis is een software architect met 11 jaar ervaring waarvan de laatste 6 jaar vooral met de focus op .NET, architectuur en OO. De laatste twee jaar is Dennis (mede)verantwoordelijk geweest voor het ontwerpen, bouwen, en uitrollen van ontwikkelstraten gebaseerd op .NET 2.0 en 3.0 en de zo vaak genoemde DSL tools. Inmiddels maakt hij voornamelijk gebruik van de standaard software factories en applications blocks van Microsoft's Patterns & Practices groep. Dennis is sinds maart dit jaar tevens Expert Advisor voor Microsoft rondom de nieuwe Web Service Software Factory : Modeling Edition.

Aanvang
Om 18:00 uur staat de pizza klaar, om ca 18:45 start de sessie. De sessie duurt uiterlijk tot 21:00 uur.

Aanmelden & Lokatie & contactpersoon
Wil je deze sessie bijwonen laat het ons weten. Stuur je mail naar info@aviva-it.nl. Je krijgt dan een bevestiging van ons.

Aviva .Net Engineers, Roy Oude Weernink
Haagse Schouwweg 8
2332 KG  Leiden
071-5351730

Voor meer informatie over ons en de routebeschrijving kijk op onze website www.avivasolutions.nl


Published: 29-11-2007 by Dennis Doomen | 6 Comments | 0 Links to this post
 
 Next >>