Terje Sandstrom

------ Chief Software Geek at Inmeta Consulting in Scandinavia ----- and a Visual Studio ALM MVP

  Home  |   Contact  |   Syndication    |   Login
  38 Posts | 1 Stories | 18 Comments | 0 Trackbacks

News

Follow me on twitter: @OsirisTerje

Twitter












Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

Company stuff

Interesting bloggers

Interesting companies

Microsoft

Microsoft Norge

Microsoft Regional Directors

Microsoft Test

MSFT Blogs

MVP

NNUG

Other interesting stuff

TFS

Visual Studio

Sunday, November 27, 2011 #

Memory for managed code is handled by the garbage collector, but if you use any kind of unmanaged code, like native resources of any kind, open files, streams and window handles, your application may leak memory if these are not properly handled.  To handle such resources the classes that own these in your application should implement the IDisposable interface, and preferably implement it according to the pattern described for that interface.

When you suspect a memory leak, the immediate impulse would be to start up a memory profiler and start digging into that.   However, before you follow that impulse, do a Static Code Analysis run with a ruleset tuned to finding possible memory leaks in your code.  If you get any warnings from this, fix them before you go on with the profiling.

How to use a ruleset

In Visual Studio 2010 (Premium and Ultimate editions) you can define your own rulesets containing a list of Static Code Analysis checks.   I have defined the memory checks as shown in the lists below as ruleset files, which can be downloadedsee bottom of this post.  When you get them, you can easily attach them to every project in your solution using the Solution Properties dialog. Right click the solution, and choose Properties at the bottom, or use the Analyze menu and choose “Configure Code Analysis for Solution”:

image

In this dialog you can now choose the Memorycheck ruleset for every project you want to investigate.  Pressing Apply or Ok opens every project file and changes the projects code analysis ruleset to the one we have specified here.

How to define your own ruleset  (skip this if you just download my predefined rulesets)

If you want to define the ruleset yourself, open the properties on any project, choose Code Analysis tab near the bottom, choose any ruleset in the drop box and press Open

image

Clear out all the rules by selecting “Source Rule Sets” in the Group By box, and unselect the box

image

Change the Group By box to ID, and select the checks you want to include from the lists below.

Note that you can change the action for each check to either warning, error or none, none being the same as unchecking the check.

image

 

Now go to the properties window and set a new name and description for your ruleset.

Then save (File/Save as) the ruleset using the new name as its name, and use it for your projects as detailed above.

It can also be wise to add the ruleset to your solution as a solution item. That way it’s there if you want to enable Code Analysis in some of your TFS builds.

 

Running the code analysis

In Visual Studio 2010 you can either do your code analysis project by project using the context menu in the solution explorer and choose “Run Code Analysis”, you can define a new solution configuration, call it for example Debug (Code Analysis), in for each project here enable the Enable Code Analysis on Build

image

 

In Visual Studio Dev-11 it is all much simpler, just go to the Solution root in the Solution explorer, right click and choose “Run code analysis on solution”.

 

 

The ruleset checks

The following list is the essential and critical memory checks. 

CheckID Message Can be ignored ? Link to description with fix suggestions
CA1001 Types that own disposable fields should be disposable No  http://msdn.microsoft.com/en-us/library/ms182172.aspx
CA1049 Types that own native resources should be disposable Only if the pointers assumed to point to unmanaged resources point to something else  http://msdn.microsoft.com/en-us/library/ms182173.aspx
CA1063 Implement IDisposable correctly No  http://msdn.microsoft.com/en-us/library/ms244737.aspx
CA2000 Dispose objects before losing scope No  http://msdn.microsoft.com/en-us/library/ms182289.aspx
CA2115 1 Call GC.KeepAlive when using native resources See description  http://msdn.microsoft.com/en-us/library/ms182300.aspx
CA2213 Disposable fields should be disposed If you are not responsible for release, of if Dispose occurs at deeper level  http://msdn.microsoft.com/en-us/library/ms182328.aspx
CA2215 Dispose methods should call base class dispose Only if call to base happens at deeper calling level  http://msdn.microsoft.com/en-us/library/ms182330.aspx
CA2216 Disposable types should declare a finalizer Only if type does not implement IDisposable for the purpose of releasing unmanaged resources  http://msdn.microsoft.com/en-us/library/ms182329.aspx
CA2220 Finalizers should call base class finalizers No  http://msdn.microsoft.com/en-us/library/ms182341.aspx

Notes:

1) Does not result in memory leak, but may cause the application to crash

 

The list below is a set of optional checks that may be enabled for your ruleset, because the issues these points too often happen as a result of attempting to fix up the warnings from the first set.

 

ID Message Type of fault Can be ignored ? Link to description with fix suggestions
CA1060 Move P/invokes to NativeMethods class Security No http://msdn.microsoft.com/en-us/library/ms182161.aspx
CA1816 Call GC.SuppressFinalize correctly Performance Sometimes, see description http://msdn.microsoft.com/en-us/library/ms182269.aspx
CA1821 Remove empty finalizers Performance No http://msdn.microsoft.com/en-us/library/bb264476.aspx
CA2004 Remove calls to GC.KeepAlive Performance and maintainability Only if not technically correct to convert to SafeHandle http://msdn.microsoft.com/en-us/library/ms182293.aspx
CA2006 Use SafeHandle to encapsulate native resources Security No http://msdn.microsoft.com/en-us/library/ms182294.aspx
CA2202 Do not dispose of objects multiple times Exception (System.ObjectDisposedException) No http://msdn.microsoft.com/en-us/library/ms182334.aspx
CA2205 Use managed equivalents of Win32 API Maintainability and complexity Only if the replace doesn’t provide needed functionality http://msdn.microsoft.com/en-us/library/ms182365.aspx
CA2221 Finalizers should be protected Incorrect implementation, only possible in MSIL coding No http://msdn.microsoft.com/en-us/library/ms182340.aspx

 

Downloadable ruleset definitions

I have defined three rulesets, one called Inmeta.Memorycheck with the rules in the first list above, and Inmeta.Memorycheck.Optionals containing the rules in the second list, and the last one called Inmeta.Memorycheck.All containing the sum of the two first ones. 

All three rulesets can be found in the  zip archive  “Inmeta.Memorycheck” downloadable from here.

 

Links to some other resources relevant to Static Code Analysis

MSDN Magazine Article by Mickey Gousset on Static Code Analysis in VS2010

MSDN :  Analyzing Managed Code Quality by Using Code Analysis, root of the documentation for this

Preventing generated code from being analyzed using attributes

Online training course on Using Code Analysis with VS2010

Blogpost by Tatham Oddie on custom code analysis rules

How to write custom rules, from Microsoft Code Analysis Team Blog

Microsoft Code Analysis Team Blog

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Tuesday, November 15, 2011 #

Our free extension to Visual Studio , the folder based Build Explorer Version 1.1 has now been released, and uploaded to the Visual Studio Gallery and Codeplex. We have collected up a few changes and some bugs, as follows:

Changes:

  • Queue Default Builds can now be optionally fully enabled, fully disabled or enabled just for leaf nodes (=disabled for folders).  If you got a large number of builds it was pretty scary to be able to launch all of them with just one click.  However, it is nice to avoid having the dialog box up when you want to just run off a single build.  That’s the reasoning between the 3rd choice here.
  • Auto fill-in of the builds at start up and refresh  This was a request that came up a lot, and which was also irritating to us.  When the Team Project is opened, the Build explorer will start by itself and fill up it’s tree. So you don’t need to click the node anymore.
    • There was also quite a bit of flashing when the tree filled up, this has been reduced to just a single top level fill before it collapses the node.
    • The speed of the buildup of the tree has also been increased.
  • The “All Build Definitions” node is now shown on top of the list
  • Login box appeared in certain cross domain situations. This was a fix for the TF30063 authentication problem we had in the beginning.  Hopefully the new code has that fixed properly so that both the login box and the TF30063 are gone forever.  Our testing so far seems to indicate it works.  If anyone gets a real problem here there are two workarounds: 1) Turn off the auto refresh to reduce the issue. If this doesn’t fix it, then 2) please reinstall the former version (go to the codeplex download site if you don’t have it anymore)  Write a comment to this blog post with a description of what happens, and I will send a temporary fix asap.

Bug fixes:

  • The folder name matching was case sensitive, so “Application.CI” and “application.CI” created two different folders. 
  • View all builds not shown for leaf odes, and view builds didn’t work in all cases.  There was some inconsistencies here which have been fixed.
  • Partly fixed:  The context menu to queue a new build for disabled builds should be removed, but that was a difficult one, and is still on the list, but the command will not do anything for a disabled build.
  • Using the Queue Default Builds on a folder, and if it had some disabled builds below an error box appeared and ruined the whole experience.

As a result of these fixes there has been introduced some new options, as shown below:

 

image

The two first settings, the Separator symbol and the options for how to handle Queuing of default builds are set per Team Project, and is stored in the TFS source control under the BuildProcessTemplates folder, with the name Inmeta.VisualStudio.BuildExplorer.Settings.xml

The next two settings need some explanations.  They handle the behavior for the auto update of the build folders.  First, these are stored in the local registry per user, at the key HKEY_CURRENT_USER/Software\Inmeta\BuildExplorer.

The first option Use Timed Refresh at Startup, if turned off, you will need to click the node as it is done in Version 1.0. 

The second option is a timed value, the time after the Build explorer node is created and until the scanning of the Build folders start.  It is assumed that this is enough, and the tests so far indicates this.  If you have very many builds and you see that the explorer don’t get them all, try to increase this value, and of course, notify me of your case, either here or on the Visual Gallery site.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

UPDATED Jan 9th: Added link to SQL 2008 R2 SP1 CU4 for ghost file fix

Recently there has been several reports on TFS databases growing too fast and growing too big.  Notable this has been observed when one has started to use more features of the Testing system.  Also, the TFS 2010 handles test results differently from TFS 2008, and this leads to more data stored in the TFS databases. As a consequence of this there has been released some tools to remove unneeded data in the database, and also some fixes to correct for bugs which has been found and corrected during this process.  Further some preventive practices and maintenance rules should be adopted.

A lot of people have blogged about this, among these are:

Anu’s very important blog post here describes both the problem and solutions to handle it.  She describes both the Test Attachment Cleaner tool, and also some QFE/CU releases to fix some underlying bugs which prevented the tool from being fully effective.

Brian Harry’s blog post here describes the problem too

This forum thread describes the problem with some solution hints.

Ravi Shanker’s blog post here describes best practices on solving this (TBP)

Grant Holidays blogpost here describes strategies to use the Test Attachment Cleaner both to detect space problems and how to rectify them.

 

The problem can be divided into the following areas:

  • Publishing of test results from builds
  • Publishing of manual test results and their attachments in particular
  • Publishing of deployment binaries for use during a test run
  • Bugs in SQL server preventing total cleanup of data

(All the published data above is published into the TFS database as attachments.)

The test results will include all data being collected during the run.  Some of this data can grow rather large, like IntelliTrace logs and video recordings.   Also the pushing of binaries which happen for automated test runs, including tests run during a build using code coverage which will include all the files in the deployment folder, contributes a lot to the size of the attached data.

 

In order to handle this systematically, I have set up a 3-stage process:

  1. Find out if you have a database space issue
  2. Set up your TFS server to minimize potential database issues
  3. If you have the “problem”, clean up the database and otherwise keep it clean

 

Analyze the data

Are your database( s) growing ?  Are unused test results growing out of proportion ?

To find out about this you need to query your TFS database for some of the information, and use the Test Attachment Cleaner (TAC) to obtain some  more detailed information.

If you don’t have too many databases you can use the SQL Server reports from within the Management Studio to analyze the database and table sizes. Or, you can use a set of queries . I find queries often faster to use because I can tweak them the way I want them.  But be aware that these queries are non-documented and non-supported and may change when the product team wants to change them.

If you have multiple Project Collections, find out which might have problems:

(Disclaimer: The queries below work on TFS 2010. They will not work on Dev-11, since the table structure have been changed.  I will try to update them for Dev-11 when it is released.)

Open a SQL Management Studio session onto the SQL Server where you have your TFS Databases.

Use the query below to find the Project Collection databases and their sizes, in descending size order. 

 
use master
select DB_NAME(database_id) AS DBName, (size/128) SizeInMB
 FROM sys.master_files 
 where type=0  and substring(db_name(database_id),1,4)='Tfs_' and DB_NAME(database_id)<>'Tfs_Configuration' order by size desc 

Doing this on one of our SQL servers gives the following results:

image

It is pretty easy to see on which collection to start the work Smile

 

Find out which tables are possibly too large

Keep a special watch out for the Tfs_Attachment table.

Use the script at the bottom of Grant’s blog to find the table sizes in descending size order.

In our case we got this result:

image

From Grant’s blog we learnt that the tbl_Content is in the Version Control category, so the major only big issue we have here is the tbl_AttachmentContent.

 

Find out which team projects have possibly too large attachments

In order to use the TAC to find and eventually delete attachment data we need to find out which team projects have these attachments. The team project is a required parameter to the TAC.

Use the following query to find this, replace the collection database name with whatever applies in your case:

 

use Tfs_DefaultCollection
select  p.projectname, sum(a.compressedlength)/1024/1024 as sizeInMB from dbo.tbl_Attachment as a 
inner join tbl_testrun as tr on a.testrunid=tr.testrunid 
inner join tbl_project as p on p.projectid=tr.projectid
group by p.projectname
order by sum(a.compressedlength) desc

In our case we got this result (had to remove some names), out of more than 100 team projects accumulated over quite some years:

image

As can be seen here it is pretty obvious the “Byggtjeneste – Projects” are the main team project to take care of, with the ones on lines 2-4 as the next ones. 

Check which attachment types takes up the most space

It can be nice to know which attachment types takes up the space, so run the following query:

use Tfs_DefaultCollection
select  a.attachmenttype, sum(a.compressedlength)/1024/1024 as sizeInMB from dbo.tbl_Attachment as a 
inner join tbl_testrun as tr on a.testrunid=tr.testrunid 
inner join tbl_project as p on p.projectid=tr.projectid
group by a.attachmenttype
order by sum(a.compressedlength) desc

We then got this result:

image

From this it is pretty obvious that the problem here is the binary files, as also mentioned in Anu’s blog.

Check which file types, by their extension, takes up the most space

Run the following query

use Tfs_DefaultCollection
select  SUBSTRING(filename,len(filename)-CHARINDEX('.',REVERSE(filename))+2,999)as Extension, sum(compressedlength)/1024 as SizeInKB from tbl_Attachment
group by SUBSTRING(filename,len(filename)-CHARINDEX('.',REVERSE(filename))+2,999)
order by sum(compressedlength) desc

This gives a result like this:

image

 

Now you should have collected enough information to tell you what to do – if you got to do something, and some of the information you need in order to set up your TAC settings file, both for a cleanup and for scheduled maintenance later. 

 

Get your TFS server and environment properly set up

Even if you have got the problem or if have yet not got the problem, you should ensure the TFS server is set up so that the risk of getting into this problem is minimized.  To ensure this you should install the following set of updates and components.

The assumption is that your TFS Server is at SP1 level.

  • Install the QFE for KB2608743 – which also contains detailed instructions on its use, download from here. The QFE changes the default settings to not upload deployed binaries, which are used in automated test runs.
    • Binaries will still be uploaded if:
      • Code coverage is enabled in the test settings.
      • You change the UploadDeploymentItem to true in the testsettings file.
        • Be aware that this might be reset back to false by another user which haven't installed this QFE.
    • The hotfix should be installed to
      • The build servers (the build agents)
      • The machine hosting the Test Controller
      • Local development computers (Visual Studio)
      • Local test computers (MTM)
    • It is not required to install it to the TFS Server, test agents or the build controller – it has no effect on these programs.
  • If you use the SQL Server 2008 R2 SP1 you should also install the CU 4 (or later) (for pre-SP1 it is the the CU 10 ). This CU fixes a potential problem of hanging “ghost” files.  This seems to happen only in certain trigger situations, but to ensure it doesn’t bite you, it is better to make sure this CU is installed.
    • There is no such CU for SQL Server 2008 pre-R2
      • Work around:  If you suspect hanging ghost files, they can be – with some mental effort, deduced from the ghost counters using the following SQL query:
        use master
        SELECT DB_NAME(database_id) as 'database',OBJECT_NAME(object_id) as 'objectname',
        index_type_desc,ghost_record_count,version_ghost_record_count,record_count,avg_record_size_in_bytes 
        FROM sys.dm_db_index_physical_stats (DB_ID(N'<DatabaseName>'), OBJECT_ID(N'<TableName>'), NULL, NULL , 'DETAILED')
      • The problem is a stalled ghost cleanup process.  Restarting the SQL server after having stopped all components that depends on it, like the TFS Server and SPS services – that is all applications that connect to the SQL server. Then restart the SQL server, and finally start up all dependent processes again.  (I would guess a complete server reboot would do the trick too.) After this the ghost cleanup process will run properly again.
    •        
    • The "hanging ghost file” issue came up after one have run the TAC, and deleted enourmes amount of data.  The SQL Server can get into this hanging state (without the QFE) in certain cases due to this.
  • And of course, install and set up the Test Attachment Cleaner command line power tool.  This should be done following some guidelines from Ravi Shanker:
    • When you run TAC, ensure that you are deleting small chunks of data at regular intervals (say run TAC every night at 3AM to delete data that is between age 730 to 731 days) – this will ensure that small amounts of data are being deleted and SQL ghosted record cleanup can catch up with the number of deletes performed. “
      • This rule minimizes the risk of the ghosted hang problem to occur, and further makes it easier for the SQL server ghosting process to work smoothly.
    • “Run DBCC SHRINKDB post the ghosted records are cleaned up to physically reclaim the space on the file system”
      • This is the last step in a 3 step process of removing SQL server data. First they are logically deleted. Then they are cleaned out by the ghosting process, and finally removed using the shrinkdb command.

Cleaning out the attachments

The TAC is run from the command line using a set of parameters and controlled by a settingsfile.  The parameters point out a server uri including the team project collection and also point at a specific team project. So in order to run this for multiple team projects regularly one has to set up a script to run the TAC multiple times, once for each team project.  When you install the TAC there is a very useful readme file in the same directory.

When the deployment binaries are published to the TFS server, ALL items are published up from the deployment folder. That often means much more files than you would assume are necessary. This is a brute force technique. It works, but you need to take care when cleaning up.

Grant has shown how their settings file looks in his blog post, removing all attachments older than 180 days , as long as there are no active workitems connected to them. This setting can be useful to clean out all items, both in a clean-up once operation, and in a general

There are two scenarios we need to consider:

  1. Cleaning up an existing overgrown database
  2. Maintaining a server to avoid an overgrown database using scheduled TAC

 

1. Cleaning up a database which has grown too big due to these attachments.

This job is a “Once” job.  We do this once and then move on to make sure it won’t happen again, by taking the actions in 2) below.  In this scenario you should only consider the large files. Your goal should be to simply reduce the size, and don’t bother about  the smaller stuff. That can be left a scheduled TAC cleanup ( 2 below).

Here you can use a very general settings file, and just remove the large attachments, or you can choose to remove any old items.  Grant’s settings file is an example of the last one.  A settings file to remove only large attachments could look like this:

<!-- Scenario : Remove large files -->
<DeletionCriteria>
    <TestRun />
    <Attachment>
        <SizeInMB GreaterThan="10" />
    </Attachment>
</DeletionCriteria>

Or like this:

If you want only to remove dll’s and pdb’s about that size, add an Extensions-section.  Without that section, all extensions will be deleted.

<!-- Scenario : Remove large files of type dll's and pdb's -->
<DeletionCriteria>
    <TestRun />
    <Attachment>
        <SizeInMB GreaterThan="10" />
        <Extensions>
            <Include value="dll" />
            <Include value="pdb" />
        </Extensions>
    </Attachment>
</DeletionCriteria>

 

Before you start up your scheduled maintenance, you should clear out all older items.

 

 

2. Scheduled maintenance using the TAC

If you run a schedule every night, and remove old items, and also remove them in small batches.  It is important to run this often, like every night, in order to keep the number of deleted items low. That way the SQL ghost process works better.

One approach could be to delete all items older than some number of days, let’s say 180 days. This could be combined with restricting it to keep attachments with active or resolved bugs.  Doing this every night ensures that only small amounts of data is deleted.

<!-- Scenario : Remove old items except if they have active or resolved bugs -->
<DeletionCriteria> 
  <TestRun> 
    <AgeInDays OlderThan="180" /> 
  </TestRun> 
  <Attachment /> 
  <LinkedBugs>     
     <Exclude state="Active" /> 
     <Exclude state="Resolved"/>
  </LinkedBugs> 
</DeletionCriteria>

In my experience there are projects which are left with active or resolved workitems, akthough no further work is done.  It can be wise to have a cleanup process with no restrictions on linked bugs at all. Note that you then have to remove the whole LinkedBugs section.

A approach which could work better here is to do a two step approach, use the schedule above to with no LinkedBugs as a sweeper cleaning task taking away all data older than you could care about.  Then have another scheduled TAC task to take out more specifically attachments that you are not likely to use. This task could be much more specific, and based on your analysis clean out what you know is troublesome data.

<!-- Scenario : Remove specific files early -->
<DeletionCriteria>
    <TestRun >
        <AgeInDays OlderThan="30" />
    </TestRun>
    <Attachment>
        <SizeInMB GreaterThan="10" />
        <Extensions>
            <Include value="iTrace"/>
            <Include value="dll"/>
            <Include value="pdb"/>
            <Include value="wmv"/>
        </Extensions>
    </Attachment>
    <LinkedBugs>
        <Exclude state="Active" />
        <Exclude state="Resolved" />
    </LinkedBugs>
</DeletionCriteria>

The readme document for the TAC says that it recognizes “internal” extensions, but it does recognize any extension.

To run the tool do the following command:

tcmpt attachmentcleanup /collection:your_tfs_collection_url /teamproject:your_team_project /settingsfile:path_to_settingsfile /outputfile:%temp%/teamproject.tcmpt.log /mode:delete

 

Shrinking the database

You could run a shrink database command after the TAC has run in cases where there are a lot of data being deleted.  In this case you SHOULD do it, to free up all that space.  But, after the shrink operation you should do a rebuild indexes, since the shrink operation will leave the database in a very fragmented state, which will reduce performance. Note that you need to rebuild indexes, reorganizing is not enough.

For smaller amounts of data you should NOT shrink the database, since the data will be reused by the SQL server when it need to add more records.  In fact, it is regarded as a bad practice to shrink the database regularly.  So on a daily maintenance schedule you should NOT shrink the database.

To shrink the database you do a DBCC SHRINKDATABASE command, and then follow up with a DBCC INDEXDEFRAG afterwards.  I find the easiest way to do this is to create a SQL Maintenance plan including the Shrink Database Task and the Rebuild Index Task and just execute it when you need to do this.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Monday, October 24, 2011 #

UPDATED Dec 8th 2011:   Added Kanban book by David Anderson

“Send me a list of books to read” – that is what I am often asked.  No more, as this list is an answer to those request! 

I have divided it into different subject areas, and each area hold a small number of the books I have found most appropriate and covering for that area.  I do love reading books, and there are so many good ones, but the list can’t go on forever. If you feel there are books I have not listed that you feel should be on this “recommended book list” please send me a comment. I also know some subjects are missing, don’t fret, I will add to the list over time. 

I have also added links to most of the authors blogs, which can be just as useful as their books Smile .

 

TFS and Visual Studio

Title Author Subtopic Comment
Software Testing with Visual Studio 2010 Jeff Levinson Testing This is a very good book covering how to use Visual Studio Test Manager to perform testing in the way the tool was intended to be used.
Professional Team Foundation Server 2010 Ed Blankenship, Martin Woodward, Grant Holiday, Brian Keller TFS Server The authoritative book on the TFS Server.
Professional Application Lifecycle Management Mickey Gousset, Brian Keller, Ajoy Krishnamoorthy, Martin Woodward ALM with TFS This book is on how the TFS tool suite covers the different roles in an ALM process, Architect, Developer and Tester, and also introduction to TFS server and process management with TFS. 
Agile Software Engineering with Visual Studio Sam Guckenheimer,
Neno Loje
ALM with TFS, Process A very good book on Agile techniques with TFS.  It is a very good read for project managers and those who want a good overview on best practices in Agile engineering.
Professional Scrum with Team Foundation Server Steve Resnick, Aaron Bjork, Michael de la Maza Process This book is not only on Scrum for TFS using the Scrum template, but also a very good book on agile techniques in general, but directed at the TFS.
Using MSBuild and Team Foundation Build Sayed Ibrahim Hashimi, William Bartholomew Build Great book covering how to customize the MS Build and TFS Build processes.

Code quality

Title Author Subtopic Comment
Effective C# and More Effective C# Bill Wagner Coding Taken after Scott Meyers famous similar books on C++ these books are a very good list of best practices techniques for C#. These books are MUST reads for developers.
Framework Design Guidelines Krzysztof Cwalina, Brad Abrams Coding Guidelines specially aimed at frameworks and libraries, but most of the stuff is generally applicable.
Clean Code “Uncle Bob” Robert C. Martin Coding Great book on coding practices by “Uncle Bob”.
Refactoring Martin Fowler Refactoring The seminal book on refactoring
Working effectively with Legacy Code Michael Feathers Refactoring The book contains a series of patterns for how to work and refactor legacy code.
C++ FAQs Marshall P.Cline, Greg A. Lomow, Mike Girou Coding An old but very good classic FAQ guideline books.  It is still very valuable, and should be useful for both C++ and C# developers. Lots of very good advices.
Implementation Patterns Kent Beck Coding A very nice book on best practices coding. Examples in Java, but just as valid for C#
Effective C++ and More Effective C++ and Effective STL Scott Meyers Coding Fantastic books on C++ best practices. Catalogue of 3 x 50 coding patterns for C++.

 

Design and architecture

Title Author Subtopic Comment
Design Patterns Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides Design patterns THE book on design patterns.
Design Patterns explained Alan Shalloway, James R. Trott Design patterns A very good book explaining the patterns in a very good and easy to follow manner
Head First Design Patterns Elisabeth Freeman, Eric Freeman Design patterns A very fun and easy read book on design patterns.  The style is very humorous and in my opinion the best book in this series.
Domain driven design Eric Evans Design An essential book on proper and correct software design.  Domain design, usually the center of business logic are often neglected and poorly understood. This book explains it all.
Patterns on Enterprise Application Architecture Martin Fowler Architectural patterns An essential book on application patterns, explaining the basic patterns which governs most proper made applications and frameworks.
Applying UML and Patterns Craig Larman UML, Design Patterns Another classic, it covers both how to use UML and also some fundamental design patterns, called the GRASP.
Large Scale C++ Software Design John Lakos Design A great classic book. Although it says C++, it is more valuable as a general book on software layering, and how to organize components, layers and levels.
The Timeless Way of Building Christopher Alexander Architecture This book is not originally intended for software people, but for building and city architects. It has become the de-facto fundamental book on software architecture too, simply because Alexander lifts out the theory and it applies just as well to software as to general architecture.

 

Testing

Title Author Subtopic Comment
xUnit Test Patterns Gerard Meszaros Unit Testing A very good test pattern catalogue book. Explains what to do based on pattern thinking when things go wrong, covers best practices for how to design and code unit tests.
Software Testing with Visual Studio 2010 Jeff Levinson Manual and Automated Testing This is a very good book covering how to use Visual Studio Test Manager to perform testing in the way the tool was intended to be used.
Test-Driven Development Kent Beck Unit Testing A fundamental book from the leading Kent Beck and creator of TDD. Read and enjoy!
The Art of Unit Testing Roy Osherove Unit Testing A great book covering a  lot of what you need to know, mocks, stubs, frameworks and best practices.

 

Process

Title Author Subtopic Comment
Kanban David J. Anderson Process A very good book on Kanban and related thinking, lot of good stuff that is useful to anyone going to make changes in their way of making software
Agile Software Engineering with Visual Studio Sam Guckenheimer,
Neno Loje
ALM with TFS, Process A very good book on Agile techniques with TFS. It is a very good read for project managers and those who want a good overview on best practices in Agile engineering.
Professional Scrum with Team Foundation Server Steve Resnick, Aaron Bjork, Michael de la Maza Process This book is not only on Scrum for TFS using the Scrum template, but also a very good book on agile techniques in general, but directed at the TFS.
Agile Project Management with Scrum Ken Schwaber Process Ken Schwaber is the father of Scrum.  This is his book. Read it!
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Sunday, August 07, 2011 #

During the summer Microsoft has released two important hotfixes for the Testing tools. These two hotfixes solves 7 serious problems:

# Issue solved Fix in :
1.1 Appdomain error when running a test agent on a computer with Visual Studio installed 1)
1.2 Exception with search error may happen on playback of a coded UI test on some WPF controls 1)
1.3 OutOfMemory exception may occur when creating a work item from the Test Result pane.  More frequent when TFS server has many builds. 1)
1.4 Publishing of test results and builds stop responding for tests run in a build, due to a MSTest crash. 1)
2.1 Test runner says “waiting for application under test” due to a crash when running a Manual test and you create a bug or run a test. 2)
2.2 Unit tests fail to start after editing of testsettings when using batch files. 2)
2.3 StackOverflowException occurs in Test Manager 2)

Note 1:  KB2544407

Note 2:  KB2443428

More detailed information on these problems can be found in the detailed description for each KB,  KB2544407 details here and  KB2443428 details here.

There are two blog entries explaining more for each of them :  KB2544407 blog here and KB2443428 blog here

They can be downloaded from :  KB2544407 download here  and KB2443428 download here

These two hotfixes are not accumulative, so you have to download and install both of them.  The sequence does not matter, they are well behaved !

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Thursday, May 12, 2011 #

The 1.0.1 version of the Build Folder Extension is now out and can be downloaded from the Visual Studio Code Gallery  at http://visualstudiogallery.msdn.microsoft.com/35daa606-4917-43c4-98ab-38632d9dbd45 

Source code, discussions and issue tracking can be found at the codeplex site at http://tfsbuildfolders.codeplex.com/ 

Context menu

The context menu has been extended with the following commands, shown below:

image

Queue New Build… :  This pops up the traditional queue build dialog

Queue Default Build(s):  This starts the default build directly, no dialog pops up.  Less clicks!   Another cute thing here is that if you select a folder, it will start all the builds in that folder directly.

View Builds:  View the builds for the particular select build definition

View All Builds:  Use this instead of the All Build Definitions to see the builds for all build definitions.

Goto Team Explorer Build Node:  Some functionality is still in the original build tree.  Use this to go directly to that node from the node in the Inmeta Build Folders.

******************

Change in 1.0.1 regarding build folders named equal to a build.

In some cases one defines builds which has the same name as a folder, like the picture below shows:

 

image

In those cases we add a “fake” node, named just ‘$’ to represent this build definition.  This also makes it easier to see these specially named build definitions.  In the earlier versions (pre 1.0) builds named like this was “lost”.

**************

Other

Disabled builds are shown properly with the correct icon.

image

Credentials problem

The pre 1.0 version assumed that you were logged in to the domain, or had the credentials in the credentials manager.  The extension threw a TF30063 error if it could not authenticate properly.   This has been changed so that it pops up the login dialog. 

This means that one may have to log in twice, once for the Team Explorer connection and once for the Build Explorer connection.   To avoid this, it’s recommended to add your credentials for that TFS connection to the Credential Manager.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Friday, April 01, 2011 #

We have just released a free extension for Visual Studio which adds a Builds Explorer with folders to the Team Explorer. 

The extension can be downloaded from Visual Studio Gallery or just search for Inmeta in Tools/Extension Manager.

The documentation and issue tracking  can be found at the codeplex site for the project http://tfsbuildfolders.codeplex.com/ and source code is available there.

 

image

The Build explorer is based on using a convention of separators in the build definition names.  See Brian Harry’s blog for  a nice explanation and description of this.

Lars Nilsson who wrote the code base for this extension has blogged up some of the challenges he faced when implementing this.

The extension have now had 300 downloads in 4 days!  We’ve got very useful feedback, and fixed the issues that came in. 

  • It had problems loading more than 100 builds – now it handles 1000 without any sign of stress. 
  • Some people noted it had problems when the separator token also existed in the team project name, also fixed.
  • And some others noted that they couldn’t use a whitespace as a separator!  Something we hadn’t even considered! We fixed that too.

To us this just shows how useful it is to get community feedback like this.  It is very effective and really appreciated!

If you want to contribute, post us a message at the codeplex site, and we will add you.  There are always possibilities for improvement.  We’ve added a couple of discussions to get some feedback on things that we have seen.

The source has also been posted up there, feel free to use it and do your own stuff based on it.  If you do, we would appreciate a comment back Smile.  Also, if you see issues in the code, tell us, or change it!

Blogs:

Nice blog on Coding4Fun  Channel 9 by Greg Duncan

Brian Harry has blogged it.

Shai Raiten has blogged it.

Jakob Ehn has blogged it.

Lars Nilsson has blogged it.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Friday, January 28, 2011 #

Sometimes the tool is blamed for errors which are not the fault of the tool – this is one such story.  It was however, not so easy to get to the bottom of it, so I hope sharing this story can help some others.

One of our test developers started to get this message inside the test steps part of a test case in the MTM.

image

saying “Could not load file or assembly ‘0 bytes from System, Version=4.0.0.0,……..”

The same error came up inside Visual Studio when we opened a test case there.

Then we noted a similar error on another piece of software – this error:

image

A System.BadImageFormatException, and same message as above, but just for framework 2.0.

We found this  description which pointed to a malware problem (See bottom of that post), that is a fake anti-spyware program called “Additional Guard”.  We checked the computer in question using Malwarebytes Anti-Malware tool.  It found and cleaned out 753 registry keys!!  After this cleanup operation the error was gone.  This is a great tool ! 

The “Additional Guard” program had been inadvertently installed, and then uninstalled afterwards, but the corrupted keys were of course not removed. 

We also noted that this computer had full corporate virus scanning and malware protection, but still this nasty little thing still slipped through.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Sunday, December 05, 2010 #

UPDATED Jan 9th 2012: New versions of Resharper, NuGet and Code Contracts.  Added link to a blog post by Grant Holiday on TFS/VS SP’s and hotfixes. Added link to CU4 for SQL 2008 R2 SP1.

UPDATED Dec 16th: New version of TFS Power tools, and NuGet

UPDATED Nov 28th: Added NuGet, new versions WebEssentials & Beyond Compare

UPDATED Nov 11th: Added the cloud update to Visual Studio which includes multistep test steps and bug fixes, updates to TFS and SQL, dotPeek, Test Attachment Cleaner and new version of our BuildExplorer, and of NDepend. Added Web Essentials.

UPDATED Aug 23rd & 26th: Added TFS SP1 Cumulative update 1. Fixes timeouts on source control. (26th: Fixed the link to the same)

UPDATED Aug 19th & 21st 2011: New version of the TFS Power tools released.  Some more suggestions from Adam fixed, Moles/Pex updates included.  

UPDATED Aug 8th 2011:  Two Visual Studio Testing tools Rollup updates added

UPDATED July 27th 2011: Adam Cogan suggested a different layout and information structure. 

This post is a list of the addins and extensions we (I ) recommend for use at Inmeta.  It’s coming up all the time – what to install, where are the download sites, last version, etc etc, and thus I thought it better to post it here and keep it updated. The basics are Visual Studio 2010 connected to a Team Foundation Server 2010. 

The list is more or less in priority order.

The focus is to get a setup which can be used for a complete coding experience for the whole ALM process.

The list of course reflects what I use for my work , so it is by no means complete, and for some of the tools there are equally useful alternatives.  The components directly associated with Visual Studio from Microsoft should be common, see the Microsoft column. 

 

Product Notes Latest Version License Applicable to Microsoft
TFS Power Tools December 20111   December 2011 (10.0.41206.0) Free TFS integration Yes
ReSharper Trial only 6.1 (6.1.37.86) Licensed Coding & Quality No
Productivity Power Tools1   10.0.20626.18 Free Coding Yes
Inmeta Build Explorer1   1.1.8 Free TFS integration No
Code Contracts   1.4.41228.0 Free Coding & Quality Yes
Code Contracts Editor Extensions1   1.4.40602.0 Free Coding & Quality Yes
Power Commands1   1.0.2.3 Free Coding Yes
NuGet Package Manager1 If upgrading fails, there is a signature mismatch  between this and the former version you have preventing upgrading. Uninstall the former first, and then install the new one. 1.6.21215.9133 Free Coding Yes
Web Std Update1   1.0.4 Free Coding (Web) Yes (MSFT)
Web Essentials 1   2.6 Free Coding (Web) Yes (MSFT)
FeaturePack 2 2 Found in MSDN Subscriber download under Visual Studio 2010 FP2 Part of MSDN Subscription Modeling & Testing Yes
Test Attachment Cleaner1   1.0 Free Testing Yes
DotPeek   1.0.0.2545 Free Coding/Investigation No
Just Decompile   Beta Free Coding/Investigation No
Beyond Compare   3.3.3 (build 14128) Licensed Coding/Investigation No
dotTrace   4.5.1 Licensed Quality No
NDepend Trial only 3.9.0.5848 Licensed Quality No
tangible T4 editor   1.9.66 Lite version Free (Good enough) Coding (T4 templates) No
Pex and Moles
Moles x861
Moles x641
Complete package found in MSDN Subscriber download under Visual Studio 2010
0.94.51023 Part of MSDN Subscription
License information here
Coding & Unit Testing Yes
LinqPad   4.26.2 Licensed Coding No
ApexSQL     Licensed SQL No
VSCommands1   3.7.3.13 Lite version Free (Good enough) Coding No

#1 Get via Visual Studio’s Tools | Extension Manager (or The Code Gallery).  (From Adam : All these are auto updated by the Extension Manager in Visual Studio)

#2 Works with ultimate only

 

Upgrades and patches for VS/TFS 2010

Go to Grant’s blogpost to see a complete list of patches and updates for installing TFS and VS. His post details what to install and where, and covers all updates and patches you need to handle, and also links to relevant documentation.

Product Notes Date Applicable to
TFS 2010 Hotfix KB2608743 This hotfix can reduce the size of the test data saved to the TFS.  See Anu’s blog here and KB2608743 details here. Oct 2011 Visual Studio, MTM, Test Ctrls.Build Agent
SQL Server 2008 R2 SP1 Cumulative Update 4  - or -
SQL Server 2008 R2 Cumulative Update 10
 
This update should be applied before using the Test Attachment Cleaner. The TAC may leave ghost records in the database due to a bug in the SQL Server.   See Anu’s blog here and more info here. Oct 2011/Dec 2011 SQL Server 2008 R2 (SP1 and pre-SP1)
Visual Studio 2010 SP1 TFS Compatibility GDR Visual Studio update to access a TFS 11 server and Team Foundation services preview, TFS in the cloud.  Includes some bug fixes and adds multiline test step support for the MTM. See Brian Harry’s blog here and KB2581206. Oct 2011 Visual Studio
TFS 2010 SP1 Cumulative Update 1 See KB2580221 and Brian Harry’s blog here and here Aug 2011 TFS
Visual Studio SP1 Rollup Update 2 A rollup update for the SP1 Testing tools, KB2443428.  See more info blog here and details here Aug 2011 Visual Studio Testing tools
Visual Studio SP1 Rollup Update 1 A rollup update for the SP1 Testing tools, KB2544407.  See more info blog here and details here June 2011 Visual Studio Testing tools
Visual Studio SP1 SP1 contains all earlier patches + a lot of new fixes
See
Brian Harry’s blog for information on what to install and how. Also contains links to a lot of the stuff to install.
Be aware of
this potential problem and workaround if you are using C++ and W7 SDK
March 2011 Visual Studio
TFS 2010 SP1 SP1 for the TFS server. March 2011 TFS
2010 SP1 fix for accessing TFS 2008 KB2522890 See info here    (Aug 23rd: Included in SP1 Cumulative Update 1, see above) March 2011 Visual Studio with TFS 2008
       

 

Some important earlier Patches, upgrades and fixes  (pre-SP1)

Product Notes Date Applicable to
Scrolling context menu KB2345133 and KB2413613 Here  Solve the problem with having a small/short context menu with scroll bars, which is much smaller than the available screen height. After the fix, the context menu uses all available screen height before scroll bars are added. October 2010 Visual Studio
MTM Patch Here and here  KB2387011  Recommended (if you use MTM) October 2010 MTM
Data warehouse fix Iteration dates fails with SQL 2008 R2.  KB2222312. Affects Burndown chart in Agile workbook.  Only for SQL 2008 R2 June 2010 Server
Upgrade 2008 to 2010 issue and hotfix Fixes problems with labels and branches which are lost during upgrade. Apply before upgrade. Note: This has been fixed in the latest re-release of the TFS Server dated Aug 5th 2010. See here. Recommends downloading the latest bits. Only if upgrade from 2008 from earlier bits August 2010 Server
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Friday, November 19, 2010 #

When checking in code with workitems, one should connect them with workitems.  In some cases you need to check in multiple times before the item is resolved.  If you are too quick there, the checkin action causes the workitem to go to the Resolved state as this is the default state, if you don’t manually change it to Associate.  This default state can now – in VS 2010 – be turned around, so that Associate becomes the default action.

See this blog post for the details.

As noted in Ed’s post, this key has to be changed on the developers machines, so it has to be rolled out to all developers. To make it simpler, copy the following into a file named for example AssociateAsDefaultCheckinAction.reg:


Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0\TeamFoundation\SourceControl\Behavior]
"ResolveAsDefaultCheckinAction"="False"


and just right click it in Explorer and choose Merge, or just run it from a command prompt.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati