Terje Sandstrom

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

  Home  |   Contact  |   Syndication    |   Login
  55 Posts | 1 Stories | 82 Comments | 0 Trackbacks

News

Subscribe

Delicious Save this on Delicious Visual Studio Feeds

¨

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

Saturday, February 8, 2014 #

This issue is resolved in the latest ReSharper release, version 8.2.0.2160, download here

The issue appears when using the Test Explorer to run tests in any of the frameworks mentioned in the title.  The tests are shown in the Test Explorer, but are not executed.  It may look like this:

image

Note:  The tests shown dimmed are NUnit and XUnit tests, which have the issue. The other tests are MSTests, which are not affected. The tests are discovered by the adapter, but not executed.

If you look in the Output window, under Tests, a message there says the message above, like:

image

image

image

One report of this issue is on the Chutzpah page.

The issue seems to have surfaced in different circumstances. Some people, including myself, noted the issue when we used the Nuget adapter for NUnit, which btw is a brilliant way of adding an adapter – and noted that it worked with the extension adapter but not with the NuGet adapter. With the XUnit and Chutzpah however, the issue appeared with the extension test adapters, so it was obviously not the way the adapters were installed that caused the issue to appear.

The common denominator was always ReSharper.  A similar issue was solved in version 8.0.2, but this seems to be another one coming up. 

The current issue is now solved in a pre-release version of ReSharper, version 23.904,  the latest official version is 23.546.  So note that you need to upgrade to this pre-release version if the issue appears. The 904 version doesn’t seem to have any other “bad” issues, as far as I have seen.

This blogpost will be updated when ReSharper is officially updated.


Monday, January 13, 2014 #

By Terje Sandstrøm and Syver Enstad

This article was originally written in 2003 and used internally within our company and for clients of our company.  The text is as it was at that time, and – given the general nature of this topic - should still be useful.

Introduction

There has been a lot of talk about design patterns, but not so much about code patterns, also referred to as idioms. A code pattern describes typical general code for common operations. This article focuses on operator patterns in C++. Not all classes need their own operators, but small classes which often represents some kind of value, will very often need a set of operators. Further, classes that use dynamic memory (heap allocation) must implement a copy constructor and an assignment operator (in addition to a destructor) if they are going to be copy able. (ref. The Big Three Law (B3L(see C++ FAQ).

In this article, we will make a catalogue of the typical operator patterns. Many of the patterns are due to other authors, the references can be found at the end. We have put all of them together and also elaborated on some of their implications.

The patterns are shown as combined declarations and implementations, as both are equally important. In many cases the operators are so small that they can safely be implemented in the header file, thus one can make them inline.

The challenge with operators is that they should be implemented as efficiently as possible, concerning both design time and runtime. Bugs caused by errors in operators can be harder to find than normal bugs, because when you use the classes in a program, you don’t see the difference between calling an internal operator or a user defined operator, so you tend to overlook them. We often find these bugs when single stepping through the program and then, very much to our surprise, we step into an operator implementation which existence was forgotten.

It is also important to note that custom class operators should conform to the interface used by the built-in types. In some cases, the compiler will transfer your definition to one compatible with the internal built-in types. Be aware of this. See for example the operator== below.

A good advice: Use operator overloading for syntactic sugar, and please do not stray from accepted semantics for an operator.

A general pattern observation

Several operators do nearly the same thing, only slightly different. As each piece of code can introduce a bug, it is good advice to only write an “algorithm” once, and then reuse it. It is similar with operator implementation – implement one operator in terms of another. This can in fact go quite a long way, as we show in this article, and it is a powerful technique. You get one more function call, but if speed optimization is highly demanded, you should make the operator methods inline, and the compiler will “remove” your function call anyway. Further, the golden rule we follow is to first make it work, then make it right, and at last make it fast.

As is the case with the Boolean and arithmetic operators below it’s often useful to implement all similar operators in terms of another member function. The Boolean operators are implemented in terms of a compare member function and the arithmetic functions in terms of their corresponding @= (+=, -=, /=) and so on.

Operator patterns table

Table 1 shows the operators discussed, and which of these is implemented directly and which one is implemented in terms of another.

Operator name

Must be member function

Operator short signature

Implementation

Assignment operator

Yes

Op=

Directly

Copy constructor[1]

Yes

 

Maybe in terms of assignment operator[2]

operator +=

No, but it probably should

Op+=

Directly

Prefix increment

No, but it probably should

Op++()

In terms of op+=

Postfix increment

No, but it probably should

Op++(int)

In terms of prefix increment

Addition operator

No, cannot be

Op+

In terms of Op+=

Subscript operators

Yes

Op[]

Directly, or member func

Stream operators

No, cannot be.

Op<< and Op>>

Directly, or member func in a class hierarchy

Equal operator

No, cannot be

Op==

Directly,

Non-equal operator

No, cannot be

Op!=

In terms of op== or member func

Less than

No, cannot be

op<

In terms of member function

Less than or equal

No, cannot be

op<=

“”

Greater than or equal

No, cannot be

op>=

“”

Greater than

No, cannot be

op>

“”

dereferencing operator

Yes

op*

Directly

dereferencing member selection operator

Yes

op->

Directly

Conversion operator

Yes

operator T

Directly

Function call operator

Yes

operator()

Directly

The operator patterns

Introduction

All patterns are described with pseudo code. The term C denotes the Class name of your class. The term X may denote a secondary class, which also may be equal to C. Member variables are just denoted as m_x. You should substitute your own members wherever you see this. We have kept the explanations rather short, so that this is more like a reference guide than a tutorial. For further discussions, you should look up the references.

We describe the patterns with the non-dependent operator first, and then follow with the operators that depend on the former.

Member or non member

Generally, operators that don’t modify any of its arguments should be implemented as free functions instead of member functions. Operators that modify the first argument often makes for shorter and more readable code if implemented as member functions and in some cases, like operator= it’s not possible to implement it as a non-member. Some operators have to be implemented as non-members. An example is the streaming operators, where it’s the second parameter that decides which operator to use, and you generally don’t want to modify the iostream classes each time you want a new implementation of the streaming operators, which is the only alternative if you’re going to implement it as a member function. All operators that can be used associatively, that is, a op b can also be called as b op a, must be implemented as non-members. This holds for many of the arithmetic operators and the comparison operators. You must be able to say bool b = 5>a ; This is valid, and should be allowed, but demands a non-member operator for the operator()>..

Difference in signature between member and non-member versions:

The non-member version of an operator will have an extra left-most parameter since it is not connected to any object.

Two typical binary operator signatures:

Member binary operator:

RetType C::operatorX(const ParamType& other);

Non-member binary operator:

RetType operatorX(const ParamType& lhs, const ParamType& rhs);

Operators for value types

The following operators do generally make most sense to implement for value types, or concrete types as they are also referred to (Str97). These types are generally very close to the built-in types of the language, and are implemented as classes where the concept of identity is generally irrelevant. Inheritance and virtual functions are seldom used in implementing such classes. This is in the contrast to reference types , objects of these classes are generally heap allocated and operated on through virtual functions.

The assignment operator, Op=

The assignment operator pattern is first shown for a single class, that is:

No inheritance
C& C::operator=(const C& other)
{
   if (this!=&other)
   {
       // copy members
       x = other.x; // and so on
   }
   return *this;
}

The assignment operator should always return a reference. That way it is possible to write code like a=b=c;

The first check is to verify that if we’re doing a=a, which is perfectly legal and which in fact happens when programmers use arrays, typedefs and other mechanism which obscure the simple fact that they are doing an a=a operation. In that case, we skip the rest of the assignment procedure.

Also, note that if the class contains dynamic memory, we have some options regarding deep or shallow copying of those blocks, which is not discussed in this article.

Inheritance

If class C inherits from class Base, then the pattern is as follows:

C& C::operator=(const C& other)
{
   if (this!=&other)
   { 
      // copy base
      Base::operator=(other);
      // copy members
      x = other.x; // and so of
   }
   return *this;
}

Note that the only change is the addition of the call to the base class assignment operator just before we start copying our own member variables. Note also that in this case we use the operator= function name of the assignment operator for the base class.

Diversion

Observe that the parameter is declared const. This has a special effect on any class that aggregates an instance of your class.

Assume you declare a class A like this:

class A
{
   private:
   C c;
   Public:
   // a lot of methods ......
}

In addition, in your code elsewhere you have something like

A a1,a2;

.... lots of code

a1 = a2;

Now when the compiler sees the assignment of a2 to a1 it will generate a default assignment operator for class A. Then comes the trap. When doing so, it will look at the member variables, and look at their assignment operators. If they ALL have assignment operators following the pattern above, with a const parameter, it will generate a similar assignment operator. If, however, one of the members (f.e. your class A) has an assignment operator where the parameter is NOT declared const, the assignment operator for class A will have a non-const parameter too.

If you think this is no big deal, just try to make a vector of A, like in

std::vector<A> va;

And look at all the nice error messages popping up from deep inside the vector template code. The reason is that the vector template demands that all members have assignment operators with const parameters because the vector must own the content.

Copy Constructor

Although this is not an operator, we have included this special constructor here, because it is part of the B3L (Big Three Law), and with some caveats, it may be implemented in terms of the assignment operator. Lets start with what a copy constructor should do. What we need for the implementation of the copy constructor is first default construction and then assignment. This is illustrated by the following example:

void Func(B& b)
{
   Obj a;
   a = b;
}

should mean the same as:

void Func(B& b)
{
   Obj a(b);
}

What is crucial here is that the precondition for calling the assignment operator is a fully constructed object, like one created by the default constructor. Following this line of thought, the ideal thing would be to implement the copy ctor something like this (pseudo code):

Obj(const Obj& other)
{
   CallDefaultCtor();  
   *this = other;
}

It is not possible to call the default ctor like this in C++, so we will have to settle for less. The first idea might be to put all initialization code into a member function, but functions cannot be called from the initializer list so this will not work for members who have to be initialized there (members with no default ctor). The general solution is therefore to duplicate the code from the default ctor to ensure that the object is in a valid state before calling the assignment operator. The class below illustrates this case:

 

class C
{
   private:
   int X;       
   const int Y;
   public:
   C() : X(0), Y(0) {};
   C(int Y) : X(0), Y(Y) {};
   C& operator=(const C& other)
   {
     if (this!=&other)
     {
        X = other.X;
     }
     return *this;
   }
   C(const C& other) : Y(other.Y) 
   { 
      *this=other; 
   }
};

In many cases the benefit gained from sharing implementation between operator= and copy ctor will be so little, and/or efficiency constraints will preclude it, so that it may be better to just implement the copy ctor directly.

NB: No matter how you define your copy ctor, remember this: It should always have the same result as default construction followed by assignment.

Arithmetic operators

The arithmetic operators are all implemented in terms of each other. We show the addition operators, but the patterns are similar for the subtraction, multiplication and division operators. They follow the same pattern, and have the same dependencies. For the sake of saving some space, we only show the addition operator patterns here. For example, for the subtraction patterns, just replace the +’s with –‘s and you should be doing fine.

Operator +=

This operator is the workhorse when it comes to arithmetic operators, and should always be implemented first when you need to do arithmetic on a class.

The pattern is:

C& C::operator+=(const X& other)
{
   x += other.x;
   return *this;
}
Addition operator

The addition operator should be implemented in terms of the op+=. The pattern for addition of an element is shown below.

const C operator+(const C& a, const X& b)
{
   C result = a; // more efficient than copy constr
   result += b;
   return result; // Note result value optimization[3]
}

The pattern is declared as a free function rather than a member of C. This is necessary in order to do operations on const values, like f.e. c = 4+a; where the number 4 no way can have a method called operator+.

The const return value stops you from writing

code like :

(a+b)=c;

Also, observe that the internal construction of the result object will have reduced negative effect due to the return value optimisation C++ compilers do. The compiler will optimise away this construction while looking at the calling code. (See Scott Meyer, item 20 in ref.2) If your code is

C a = 4;

C b = 6;

C x = a+b;

Then the compiler will combine the internal construction in the operator+ and the construction in the calling code, of x, leaving you with only one construction.

Also, note that we use an empty construction together with the assignment operator instead of a copy constructor, because the copy constructor is implemented in terms of an assignment operator. Since we know this, the assignment above is more efficient, and just as clear.

Prefix increment operator

There are two increment operators, one for prefix operations and another for postfix operations. We start with the prefix operator pattern, which is implemented in terms of the op+=. The postfix operator is implemented in terms of the prefix operator.

C& operator++()
{
   *this += 1; // Implemented in terms of op+=() 
   return *this;
}

It is natural to implement this in terms of the op+= because it is only a special case of that, which increments by one. The op+= increments by any value given.

Postfix increment operator

The postfix operator pattern has a strange signature. The pattern is:

C operator++(int)
{
   C old = *this; // more efficient than copy constr
   ++(*this); // Inc in terms of prefix oper++
   return old;
}

Note that a parameter with only the type int is used. This is a speciality just for telling the compiler that this signature is a postfix operator, and not a prefix operator. Without the int, there would be no differences between the two signatures. One can wonder why the standard committee choose this rather than make an explicit keyword that would be clearer to read like

C operator++() postfix

But I assume some old C guys are still present (pun indented!).

Also, observe that the postfix increment operator will return a copy of the old value. This is the reason why you should opt for the prefix increment operator, and only use the postfix if you need this behaviour. If you use the postfix inadvertently, you will have a useless object construction on your conscience.

A typical efficiency “error” many people make, especially old C-coders who are more used to the postfix than the prefix is in loops:

for (C i=0; i<N; i++)
{
   …..
}

Now for each iteration of the loop, a copy of ‘i’ is created and thrown away. The better way is thus:

for (C i=0; i<N; ++i)
{
   …..
}

Actually, this only holds true for user defined types. For built-in’s postfix is as efficient as prefix. But it’s a good rule anyway.

Equal operator

The equal operator has a binary and symmetrical form, and is thus defined as a function or a friend function if it needs access to the private representation. Both operands should preferably, or normally, be of the same type. You may of course define operator== with different types, which has been done in the STL for the string class, where three overloaded operator==’s exist. If you do that, implement two of those in terms of the first. If you also have an operator== it is important that the result of applying operator= to an object makes operator== return true for the two objects afterwards, or it will get people very confused.

class C
{
   public:
   friend bool operator==(const C& c1,const C& c2)
}

and implemented as

bool operator==( const C& c1,const C& c2)
{
   return c1.x==c2.x;
}
Equal operator for STL vector of pointers

If you have made yourself a vector of pointers, and you would like to use the find template algorithm on that vector, you will need a special operator== in your class.

class C
{
   public:
   friend bool operator==(const C* pc1,const C& c2)
}

and implemented as

bool operator==( const C* pc1,const C& c2)
{
   return pc1->x==c2.x;
}

and you call the find template as

vector<C*> v;
// code to fill the vector
C c; // object to look for
vector<C*>::iterator iter = find(v.begin(),v.end(),c)

Note that the find call uses the object to find as a reference argument, not a pointer as one could assume. The call is in fact equal to the call used for vector of objects (vector<C>), but a vector of objects uses only the standard operator==.

Non-equal operator

The non-equal operator follows the same rule as the equal operator, and is also implemented in terms of that operator.

class C
{
   public:
   friend bool operator!=(const C& c1,const C& c2)
}

and should be implemented as

bool operator!=( const C& c1,const C& c2)
{
   return !(c1==c2);
}

When you have only one member, this may seem a waste, but with multiple members, you save a lot of typing, and also a lot of possibilities for making errors.

A compare method and all the Boolean operators

If you need to implement all the Boolean operators it is often best to implement them in terms of a function compare that returns 0 for equality, < 0 for less and > 0 for greater.

class C {
   public:
   // Compare probably needs access to the representation of C
   virtual int compare(const C& other);.....
};

The reason for the compare method to be virtual is that in case of derivations, you won’t need to make new Boolean operators for the derived classes. All you need to do is to implement the new compare method in the derived class.

bool operator==(const C& lhs, const C& rhs)
{
   return lhs.compare(rhs) == 0;
}

bool operator!=(const C& lhs, const C& rhs)
{
   return lhs.compare(rhs) != 0;
}

bool operator<(const C& lhs, const C& rhs)
{
   return lhs.compare(rhs) < 0;
}

bool operator>(const C& lhs, const C& rhs)
{
   return lhs.compare(rhs) > 0;
}

bool operator<=(const C& lhs, const C& rhs)
{
   return lhs.compare(rhs) <= 0;
}

bool operator>=(const C& lhs, const C& rhs)
{
   return lhs.compare(rhs) >= 0;
}
Array operators

The array operator, or subscript operator, should always be defined as both a const and a non-const version. This operator can be found at both the left and the right side of an assignment.

When you need code for:

C c;
c[5] = 8;

The following operator should be implemented

c& C::operator[](int position)

{

return m_data[position];

}

However, when you only need to read out the value,

C c;

X = c[5];

The following operator pattern should be used:

const C& C::operator[](int position) const
{
   return m_data[position];
}

Conversion operators

class Rational
{ 
   public:
   Rational(int num=0,int denom=1);
   operator double() const
   {
      return double(num)/double(denom);
   }
}

Conversion operators are very often a problem, because they are often being called implicitly, and often when you don’t want them to be called. They are especially deadly in combination with a one argument non-explicit constructor for the same type. The result from implementing conversion operators is often that the programmer must explicitly cast and jump through hoops to get the wanted behaviour, so most times it’s better to just make a member function that returns the required representation. Note also that the example above don’t check for a possible zero value of denom. This might be handled by the runtime system by throwing a division-by-zero exception, at least for Win32.

Tip: Observe that the conversion operator does not declare a return type, much like a constructor.[SE1]

A special case for the conversion operator is if you want the object to signify if it is in a good or bad state for use in f.e. Boolean statements. To implement this as an operator bool conversion would seem the obvious way to implement this but it should rather be implemented like the below:

class C {
   public:
   operator const void*() const
   {
      return this->valid() ? this : 0
   }
   ....
};

If this had been implemented as a bool conversion operator the result could be used in other constructs than checking the objects state. The code above can only be used for checking the validity of the object by comparing the result to 0. [4]

Miscellaneous operators

Streaming operators

You should at least implement the put to operator (“<<”) for your classes, as it at the least is very helpful for printing debug messages.

Stream out
friend ostream& operator<<(ostream& out, const C& c)
{
   out << c.m_n1 << c.m_n2; 
   return out;
}
Stream in
friend istream& operator>>(istream& in, C& c)
{
   in >> c.m_n1 >> c.m_n2;
   return in;
}

These two operators should be declared friend of the class they work on if they need access to the representation of the object, parameter C above.

Streaming a class hierarchy:

Define a virtual function print in the base class of the hierarchy:

class Base {
   public:
   virtual ostream& print(ostream& os) = 0;
   ....
};

Implement the ostream operator in terms of the print member function

ostream& operator<<(ostream& os, const Base& object)
{
   return object.print(os);
}

It does not seem particularly useful to implement a similar scheme for the get from operator.

Dereference and member selection operator

The dereference and member selection operators are typically used to implement classes whose instances behave like pointers.

class Obj {
   public:
   void doIt();
   .....
};

class PtrToObj 
{
   private:
   Obj* pObj;
   public:
   ........
   Obj& operator*()
   {
      return *pObj;
   }
   Obj* operator->()
   {
      return pObj;
   }
}; 

This enables clients to use an instance of PtrToObj like it actually was an Obj pointer.

Obj* pObj = new ......

PtrToObj p(pObj);

p->doIt();

(*p).doIt();

Be aware that there are many ways in which to implement so called smart pointers, some are designed to be passed by value (value objects), where you write the copy constructor, assignment operator and destructor for the smart pointer to cater for features such as ownership transfer and reference counting. Another way is to disallow copying, and rely on passing by reference down the stack. See the article by B. Milewski in the references, for details of design and use of smart pointers.

You need to implement the const versions if you are going to pass the Ptr object by const reference. Like this:

void func(const PtrToObj& ptr)
{
   ptr->doIt(); // compile error if the const version of Ptr::operator-> is not defined.
}

Here are the implementations of the const versions of the dereferencing operators:

class PtrToObj
{
   ……..
   const Obj& operator*() const
   {
      return *m_pObj;
   }
   const Obj* operator->() const
   {
      return m_pObj;
   }
   ……
};

AddressOf operator

Also sometimes used with a smart pointer, implemented like this:

class PtrToObj 
{
   public:
   Obj** operator&()
   {
      return &m_pObj;
   }
   .....
}; 

Be aware that overloading the address operator breaks the identity check in the assignment operator (operator=). This may or may not be a problem.

Overriding the AddressOf operator is generally not seen as a good idea.

FunctionCall operator

This operator becomes very useful when extending/using the STL library, because the STL algorithms often take a function like object as a parameter. If you implement your custom function like object as a Class (a so called functor), instead of a function you can save and/or accumulate state through out the algorithm.

class C 
{
   public:
   void operator()(int, int);
   .....
}; 

Operators &&, ||, and ,

We have NO patterns for these operators since you should not overload them. See Scott Meyer (ref 2) item 7 for an explanation.

Conclusion

This article has laid out a series of operator patterns. By using these you can eliminate some of the most common bugs occurring with operators, and perhaps more important, you have one place to look for the patterns! Which is the reason we wrote it in the first case.

References:

The C++ Programming Language, 4th ed. Bjarne Stroustrup, 1997, Addison-Wesley

Exceptional C++, Herb Sutter, , 2000, Addison-Wesley

Effective C++ , Scott Meyer, 2nd ed. 1997, Addison- Wesley

More Effective C++, Scott Meyer, 1996, Addison-Wesley

Online:  C++ FAQs  or Book M.P. Cline and G.A. Lomow, 1998, Addison-Wesley

The ANSI/ISO C++ Professional Programmers Handbook, Danny Kalev, 1999, QUE

Large Scale C++ Software Design, Lakos, 1996, Addison-Wesley

Resource Management, Bartosz Milewski, http://www.relisoft.com/resource/resmain.html

Terje Sandstrøm is Senior Software Architect at Osiris Data AS. He has a M.Sc. in physics from the University of Oslo, and has been working with programming and program design since 1980, in a variety of languages, but C++ is still the favourite.

(2013 : Currently at Inmeta Consulting AS ,  for updated information on Terje , see http://about.me/Terjes)

Syver Enstad is a Software Developer at Osiris Data As. He has a B.Sc in computer Science from the University of Trondheim, and has been working with programming since 1998. He enjoys both C++ and C#, he also enjoys programming in Python and Smalltalk.

(2013 : Currently programmer at Tandberg ASA)


[1] Ok, ok, not exactly an operator, but it is part of the B3L, and is implemented in terms of op=, thus we add it here.

[2] As long as the assignment operator is implemented directly

[3] Before 1996 a named object would not be eligible for return value optimisation but after that date, the standard declares that both named and unnamed objects are eligible and newer compilers should do this optimisation.

[4] Lakos, page 649-650.


[SE1] This true under Win32, but not necessarily for C++ as such.


Saturday, December 14, 2013 #

Go to Part 1 – List of Product Updates for information on Visual Studio and TFS 2013 updates

Looking for the VS 2012 product updates and extensions ?  Go to Visual Studio 2012 Product and updates (Part 1)  and Visual Studio 2012 extensions (Part 2)

Looking for the VS 2010 extensions ? Go to Visual Studio 2010 - List of Product Updates (Part 1) + Extensions (Part 2).

Looking for links to the test adapters, go to this blog post.

Update April 12th 2014:  Updated TypeScript, ReSharper3 , TFS Power Tools , NDepend3 .  Added Devart T4 editor

This post is a list of the extensions I recommend for use with Visual Studio 2013. 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 2013 connected to a Team Foundation Server 2013, although most also works with earlier versions. 

Many live in a side-by-side environment with Visual Studio 2010 and 2012. The side-by-side is supported by VS 2013. However, if you installed a component supporting VS2013 before you installed VS2013, then you need to reinstall it. (Components marked with Note 3 below) The VSIX installer will understand that it is to apply those only for VS2013, and will not touch – nor remove – the same for VS2010 and VS 2012. A good example here is the Power Commands.

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.

For components that are updated through the gallery, I will no longer update the latest version numbers, as they are easily controlled through the Tools/Extensions and Updates dialogue. In the version column I will just write Auto.

If you want to use the same set of extensions on multiple computers, you might like to share them easily. Lars Wilhelmsen has a great blog post about how to use Dropbox to share extensions and common settings.

Extensions ready for VS 2013, both upgrades and new ones

Product Notes Latest Version License Applicable to Microsoft
File Nesting Awesome and convenient Auto Free Visual Studio MSFT
AutoHistory Awesome, local history Auto Freee Visual Studio MS Devlabs
EF Power Tools Beta 41 See blog post Auto Free Visual Studio Yes
MyHistory1 See MSDN Article Auto Free TFS Integration No
Inmeta AssociateRecentWorkItems1 Fast way to associate recent work items to a checkin, reduce need to search around.  See Jakobs blogpost for more info Auto Free TFS Integration No

Unit Test Generator1

Get back the ability to generate unit tests from code, also works for NUnit and XUnit. Auto Free Unit Testing (VS) ALM Rangers
Codelens Code Health Indicator  12 Awesome !  See this post (Norwegian), and this and this. Auto Free Coding & Quality Yes
Runsettings1 Item template to create default runsettings file Auto Free Unit Testing (VS & TFS) No
TypeScript See info here, and B.Harry’s blogpost. Codeplex here
Release notes
1.0 Free Coding Yes
ReSharper3 Note:Version 8.1.23.546 and earlier have an issue with Nuget/NUnit/Chutzpah, see here.  Download version 8.2 to get this resolved.
8.2.0.2160 Licensed Coding & Quality No
NuGet Manager   3 New initial install included with VS 2013. Updates through extension gallery Auto Free Visual Studio Yes
TFS Power Tools
See Brian Harry’s blog post for more info

12.1.00402.0 Free TFS integration Yes
NDepend3 Info on updates here. Trial available.

5.2.1.8320

Licensed Quality No
Build Manager1 Community Build Manager. Info here from Jakob Auto Free TFS Integration No
Visual Studio 2013 SDK Required for using Wix Published 11.Oct.2013 Free Visual Studio Yes
Wix Toolset 3.8 Free Coding/Installers No
Productivity Power Tools1 Awesome package. A must have! Auto Free Visual Studio Yes
Code Contracts1 3 Now on gallery too. Info here and follow the forum here
1.5.60911.10 Free Coding Yes
Code Contract Editor Extensions1   1.5.60813.10 Free Coding Yes
Visualization and Modeling SDK Requires VS 2013 SDK
Nov 10th 2013 Free now, otherwise Part of MSDN Subscription Modeling, DSL, UML extensions Yes
Slow Cheetah1 3 Tool for transforming XML files, like config files. Auto Free Coding No
Web Essentials1 Auto Free Coding Yes
Devart T4 editor Nice T4 editor, using this now instead of tangible. Auto Free Coding (T4 templates) No
tangible T4 editor1 Lite version is free and more than enough for T4 editing. 2.2.3 Lite version Free (Good enough) Coding (T4 templates) No
ASP.Net and Web Tools 2013 Free Coding Yes

#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

#3 Also works with VS 2010 and VS 2012

 

Tools (outside Visual Studio)

Product Notes Latest Version License Applicable to Microsoft
ILSpy Decompiler –open source. Can also export assembly as C# project 2.1.0.1603 Free Coding/Investigation No
DotPeek Decompiler from Jetbrains. Can also export as C# project 1.1.1.33 Free Coding/Investigation No
LinqPad Info here 4.47.02 Free and licensed versions Coding No
           
TFS Team Project Manager Extremely valuable. Handle maintenance of work items, process, and much more across multiple team projects at once.  No more batch files with witadmin! See it at Codeplex  1.6.5039 Free TFS No
TFS Administration Tool Handling security and permissions in TFS, Sharepoint and reporting services. Open source tool at Codeplex
Version 2.3 is fully 2013 compatible. If you don’t have VS installed, download and install the TFS 2013 Object model
Version 2.2 works on 2013 but requires the 2012 Object model to be installed.
2.3 Free TFS No

 

Extensions we wait for, not yet in a VS 2013 version

Product Notes Latest Version License Applicable to Microsoft
Inmeta Build Explorer     Free TFS integration No
           


Looking for List of VS 2013 Extensions (Part 2)

Updated April 12th 2014:  Visual Studio 2013 Update 2 RCTFS Server 2013 Update 2

Looking for the VS 2012 product info and extensions?  Go to Visual Studio 2012 Product and updates (Part 1)  and Visual Studio 2012 extensions (Part 2)

Looking for the VS 2010 extensions ? Go to Visual Studio 2010 - List of Product Updates (Part 1) + Extensions (Part 2).

Looking for links to the test adapters, go to this blog post.

 

The information contains the download links to all versions and updates where applicable, links to information about each version, the version number for each and the release dates. I have also added prerequisites, like the SQL server version necessary.

This is the major download link for all official Visual Studio products.

 

Product Notes Version number Date Applicable to
Visual Studio 2013 Update 2 RCTFS Server 2013 Update 2 See info:  Release notesBrian Harry blog on General AvailabilityBrian Harry on TFS 2013 U2, KB 2927432 12.0.30324.0 Apr 3rd, 2014 Visual Studio & TFS
Visual Studio 2013 Update 1 See info : KB 2911573, 12.0.30110.0 Jan 20th 2014 Visual Studio
Visual Studio and TFS 2013
download link
The RTM version of Visual Studio 2013  (Note 3)

12.0.21005.1

Nov 18th 2013 Visual Studio and TFS
SQL Server 2012 SP1
The TFS 2013 require the SQL 2012 server, SP1
Also see Manually Install SQL Server for TFS 2013
    SQL Server 2012 SP1

 

Note 1

The version number of Visual Studio is not changed when installing this patch.  The only place you see it is in the Installed Updates list

image

Note 2

The Update 1 RC doesn’t include the Queue Build patch.

Note 3

There was a rerelease of TFS 2013.  The first release had a bug which appeared in the Web UI, Code section, History.  If you get a red cross there, you got the first release.  You then need to reinstall.

Unsure which version and update you have  ?

Visual Studio:

Go to the top menu, choose Help | About

image

Note that both the name of the update and the corresponding version number is given.

Go to the top menu, select Tools | Extensions and Updates. Under the Updates | Product Updates section you will see if there is a new update ready for you. Note that pre-releases and hotfixes don’t arrive here.

image

(Image from VS 2013 preview, but it is the same in VS 2013)

To the far right you see the version number you have, and what version to update to.  Since the updates are cumulative, you don’t need to worry about those in between.

 

Team Foundation Server (on premise):

Use the web access for the TFS. Go to the Help Icon to the far right, and choose “About” from the menu:

image

In this case I have a TFS 2013 preview server.

Team Foundation Service:

If you are connected to the  Team Foundation Service you will not find any version number.  It is also always updated to the latest version.  You could check the service status page to see if all is working, and to see what has been done at the updates and release notes listed here.

 

Thanks

Thanks to Adam Cogan for valuable help in structuring these posts


Wednesday, December 4, 2013 #

Download:  VS2012 Runsettingstemplate   VS2013 Runsettingstemplate

The VS2012/13 unit test feature can generate code coverage results.  It can do so for (nearly) any type of adapter you choose to use, MSTest, CPPTest (managed/native), XUnit and NUnit (but not Chutzpah (note 1)).

Assume you have a project with a set of unit tests included.  For this demonstration I have used multiple different test frameworks just to show that this applies to any of these frameworks.

You choose to analyze for code coverage:

image

 

The code under test is this:

image

All the tests we have tests the Add method, none tests the Subtract method, so the expected code coverage should be 50%.

The result we get is this:

image

The total code coverage is calculated to 88%.  We also see all the tests, which – not surprisingly – is at 100%. 

 

Some people find this to be just fine, and want the code coverage to include the tests.  I , for one, are not so keen on this.  I want to see the code coverage of the real production code, and would have expected a result of 50% in this case. 

One can argue in different ways here, but let us assume that you do agree with me – and you want to get this result more correct :-)

We then need to exclude the tests from the code coverage results, and there are two ways to do this.

1) Add an ExcludeFromCodeCoverage attribute to the test classes

2) Add and enable a runsettings file to the solution. 

 

Option 1) will be tedious to use when the number of tests goes up, so we will go for Option 2).

After googling “runsettings” you will find this article, which tells you to copy settings information from that post into an emtpy runsettings file.  That is hard work!  And, if you use those settings, and you use  a 3rd party test adapter you will find more stuff in your test coverage results than you really bargained for.  (In one case I found the testadapters there!) We need to sweeten up this file.

And, we don’t want to do this manually each time.

Solution:  Install the Runsettings solution Item template from here:  VS2012 Runsettingstemplate   VS2013 Runsettingstemplate

Now, right click your Solution, choose Add Item:

image

Select the runsettings:

Your solution will get this added:

SNAGHTML216dc13b

Since we have added the default stuff and also the excludes for the unit testing in this, all you now need to do is to enable the use of this from the Test Menu:

image

You select the file using the “Select Test Settings File” and then you enable it by ensuring it has been checked.

 

Now when we run the Test Coverage we get this very nice result:

image

Compared to the results above, it is less clutter, as the irrelevant test code is not included in the results.  The resulting numbers are also more correct, imho.

 

Removing test code based on file exclusions

Most often your test code is placed in projects and assemblies suffixed with “Test”.  You can then use this as an exclusion criteria.  In that case you must open the runsettings file and add that criteria to the list.

Note, you don’t need to do this if your test files only contains attributed test classes, then the default runsettings file from the extension above will handle them.

Find  the section in the file named ModulePaths and add the relevant pattern there under the Exclude section.  Note that the patterns are Regular Expressions, and that special characters like ‘.’ and ‘*’may have special meanings. Test the exclusion properly.  See “Regular expressions” in this MSDN post.

image

 

 

Handling special test code

If you have code in your test project that is not covered by attributes, that code can be excluded by adding the ExcludeFromCodeCoverageAttribute to that part of the code, either class or method.  This can f.e. be stub classes or mocking classes, or common test code that does not have any of the other exclusion attributes.

 

TFS Build

Note that The TFS Build templates also have a property for setting the runsettingsfile.

image

This is the default setup, which means there is no coverage data.  If you select CodeCoverageEnabled( or …ForAspNetApps) then the standard codecoverage will be performed.  If you select a runsettings file, which must have been checked in to the repository, the Type goes to UserSpecified, and the specifications in the selected runsettings file takes effect.

image

Note that this don’t apply if you use the MSTest runner, but in TFS 2013, the VSTest runner is the default.

 

Note 1:   VS Test runner can’t find code coverage for javascript code, there is no dll’s to analyze, so it doesn’t work for Chutzpah, which handles QUnit andJasmine.


Wednesday, October 30, 2013 #

Using NuGet in Visual Studio together with ReSharper may sometimes lead you into an annoying error where ReSharper indicates your code has an error, but the solution builds just fine.
This may happen if you have a set of NuGet packages, and you either just restore them, or delete them on disk and then restore again.  Your code ends up looking like this, note the red missing functions, which comes from the Moq library - which is downloaded from NuGet:

 

image

while the Build is still fine, it compiles without any errors:

image

This stackoverflow question gives some different approaches to solve this, but my experience have been that the Resharper Suspend-Resume trick most often solves the issue:
In Visual Studio:  Go to Tools/Options/Resharper

Press Suspend:

image

When this is done the error markers disappear, since ReSharper now is inactive.

Then just press Resume again:

image

This has been submitted to Jetbrains support,  here http://youtrack.jetbrains.com/issue/RSRP-396411 – Comment and votes please. 


Friday, September 20, 2013 #

The last year I have written three blog posts for the Microsoft MSDN ALM blog on unit testing. The posts focused on the new test explorer with its abilities to run tests in multiple frameworks, and utilizing traits to filter what to run, both in Visual Studio and on TFS Build.  I covered the adapters for NUnit, XUnit and Chutzpah.

 

How to manage unit tests in Visual Studio 2012 Update 1 : Part 1–Using Traits in the Unit Test Explorer

Part 2–Using Traits with different test frameworks in the Unit Test Explorer

Part 3: Unit testing with Traits and code coverage in Visual Studio 2012 using the TFS Build – and the new NuGet adapter approach

 

The adapters can be installed either into Visual Studio using a Visual Studio Extension, or added to your solution using an adapter delivered through NuGet. At the time of writing only NUnit offers the NuGet adapter. The advantage of using a NuGet based adapter is that it follows the solution, so it will just work for any developer regardless of that developer has installed the adapter or not.  It will also work directly on a TFS server, either on-premise or the TF Service.

If you use non-NuGet adapter, the content of the adapter must be added to the TFS Server custom build activities folder. This is described in Part 3 (above). Grab a readymade zip with this content. 

Part 3 also describes how to get the NUnit NuGet adapters – there are two variants – and how to choose between them. 

NuGet Quick Access: Search for “NUnit TestAdapter”.   Note:  You need only one per solution

Setting up NuGet correctly in your solution is described in this NuGet Setup Inmeta Knowledge Article

 

If you choose to go the extensions road, they are found at

NUnit Test Adapter Extension

XUnit Test Adapter Extension

Chutzpah Test Adapter Extension (covering QUnit and Jasmine for Javascript testing)

 

Some other useful articles

Visual Studio 2012 RC – What’s new in Unit Testing

Windows Phone Unit Tests in Visual Studio 2012 Update 2

Visual Studio Unit Test Generator v1 “lands”

What's New in Visual Studio 11 Beta Unit Testing

Visual Studio 11 Beta - Unit Testing Plugins List

 

or search for more here.


Sunday, August 18, 2013 #

Go to Part 2 – List of extensions and tools for Visual Studio and TFS 2012

Looking for the VS 2010 extensions ? Go to Visual Studio 2010 - List of Product Updates (Part 1) + Extensions (Part 2).

Looking for links to the test adapters, go to this blog post.

 

UPDATE  Nov 26th 2013:   Visual Studio 2012 Update 4

This information was formerly contained within my blog post on  List of extensions (Part 2), but it seems better to keep this separate now, since the cadence has increased tremendously for VS 2012, and the list grows very fast.

The information contains the download links to all versions and updates, links to information about each version, the version number for each and the release dates. I have also added prerequisites, like the SQL server version necessary.

 

Product Notes Version number Date Applicable to
Visual Studio 2012 Update 4 Some info here 11.0.61030.0 Nov 11th 2013 VS
Visual Studio 2012 & TFS 2012  

11.0.50727.1

Aug 15th 2012 Visual Studio and TFS
SQL Server 2008 R2 SP1 Cumulative Update 4
The TFS 2012 requires the CU1 at least, but you should go up to at least CU4, since this update solves a ghost record problem that otherwise may cause your TFS database to not release records the way it should when you clean it up, see this post for more information on that issue.   Oct 2011 SQL Server 2008 R2 SP1

 

Unsure which version and update you have  ?

Visual Studio:

Go to the top menu, choose Help | About

image

Note that both the name of the update and the corresponding version number is given.

Go to the top menu, select Tools | Extensions and Updates. Under the Updates | Product Updates section you will see if there is a new update ready for you:

image

(Image from VS 2013 preview, but it is the same in VS 2012)

To the far right you see the version number you have, and what version to update to.  Since the updates are cumulative, you don’t need to worry about those in between.

 

Team Foundation Server (on premise):

Use the web access for the TFS. Go to the Help Icon to the far right, and choose “About” from the menu:

image

In this case I have a TFS 2013 preview server.

Team Foundation Service:

If you are connected to the  Team Foundation Service you will not find any version number.  It is also always updated to the latest version.  You could check the service status page to see if all is working, and to see what has been done at the updates and release notes listed here.

 

Thanks

Thanks to Adam Cogan for valuable help in structuring these posts


Tuesday, April 2, 2013 #

Go to Part 1 – List of Product Updates for information on Visual Studio and TFS 2012 updates

Looking for the VS 2010 extensions ? Go to Visual Studio 2010 - List of Product Updates (Part 1) + Extensions (Part 2).

Looking for links to the test adapters, go to this blog post.

 

UPDATE Aug 18th 2013: Updates: Visual Studio Tools for Git, TypeScript, ReSharper, TFS Power Tools, Code Contracts, Build Manager, Web EssentialsCode Contracts, tangible T4 editor , Just Decompile, DotPeek   ADDED:  Inmeta AssociateRecentWorkItems , Unit Test Generator

Added separate tools section:  TFS Administration Tool , TFS Team Project Manager

This post is a list of the extensions I recommend for use with Visual Studio 2012. 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 2012 connected to a Team Foundation Server 2012.

Many live in a side-by-side environment with Visual Studio 2010. The side-by-side is supported by VS 2012. However, if you installed a component supporting VS2012 before you installed VS2012, then you need to reinstall it. The VSIX installer will understand that it is to apply those only for VS2012, and will not touch – nor remove – the same for VS2010. A good example here is the Power Commands.

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. Many components have not yet arrived with VS2012 support. I will add them as they arrive.

The components directly associated with Visual Studio from Microsoft should be common, see the Microsoft column.

If you want to use the same set of extensions on multiple computers, you might like to share them easily. Lars Wilhelmsen has a great blog post about how to use Dropbox to share extensions and common settings.

Extensions ready for VS 2012, both upgrades and new ones

Product Notes Latest Version License Applicable to Microsoft
Visual Studio Tools for Git1 See Brian Harry’s blogpost 0.9.5.0 Pre-release Visual Studio Yes
EF Power Tools Beta 3 Available1 See blog post 0.7.0.0 Free Visual Studio Yes
MyHistory1 See MSDN Article 1.4 Free TFS Integration No
Inmeta AssociateRecentWorkItems Fast way to associate recent work items to a checkin, reduce need to search around.  See Jakobs blogpost for more info 1.0.0.3 Free TFS Integration No

Unit Test Generator1

Get back the ability to generate unit tests from code, also works for NUnit and XUnit. 1.0.13.717 Free Unit Testing (VS) ALM Rangers
Runsettings1 Item template to create default runsettings file 1.1 Free Unit Testing (VS & TFS) No
TypeScript See info here, and B.Harry’s blogpost. Codeplex here
Release notes
0.9.1 Free Coding Yes
ReSharper3 8.0.14.856 Licensed Coding & Quality No
NuGet Manager1 3 Initial install included with VS 2012. Updates through extension gallery 2.6.40627.9000 Free Visual Studio Yes
TFS Power Tools
(This applies to Update 1-3)

TFS Power tools (This applies to RTM)
See Brian Harry’s blog post for more info
(Side-by-side with TFS 2010 should work, but remove the Shell Extension from the TFS 2010 power tool first.), and this post for info on Update 1
July 2013(11.0.60506.0) Free TFS integration Yes
NDepend3 Info on updates here. Trial available.

4.1.0.6871

Licensed Quality No
Build Manager1 Community Build Manager. Info here from Jakob 1.4.0.10 Free TFS Integration No
Visual Studio 2012 SDK Required for using Wix Published 2.Aug.2012 Free Visual Studio Yes
Wix Toolset 3.7 Free Coding/Installers No
Visual Studio 11 Feedback tool1 Use this to really ease the process of sending bugs back to Microsoft. 1.2.3 Free Visual Studio Yes
Productivity Power Tools1 Re-added with new features, now also includes Power Commands, which can be uninstalled. 11.0.60403.0 Free Visual Studio Yes
Power Commands1 3 Just reinstall, even if you already have it for VS2010. The reinstall will then apply it to VS 2012
Install Productivity Power Tools which includes Power Commands
1.0.2.3 Free Coding Yes
Code Contracts1 3 Now on gallery too. Info here and follow the forum here
1.5.60813 Free Coding Yes
Code Contract Editor Extensions1   1.5.64024.12 Free Coding Yes
Visualization and Modeling SDK Requires VS 2012 SDK
RTM (Sept. 29th 2012) Free now, otherwise Part of MSDN Subscription Modeling, DSL, UML extensions Yes
Slow Cheetah1 Tool for transforming XML files, like config files. 2.5.5 Free Coding No
Web Essentials1 2.9 Free Coding Yes
T4 Toolbox1 11.8.0 Free Coding (T4 templates) No (Author now MSFT)
tangible T4 editor1   2.2.1 Lite version Free (Good enough) Coding (T4 templates) 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

#3 Also works with VS 2010

 

Tools (outside Visual Studio)

Product Notes Latest Version License Applicable to Microsoft
ILSpy Decompiler –open source. Can also export assembly as C# project 2.1.0.1603 Free Coding/Investigation No
DotPeek Decompiler from Jetbrains. Can also export as C# project 1.1.1.33 Free Coding/Investigation No
Just Decompile Decompiler from Telerik 2013.2.613 Free Coding/Investigation No
LinqPad Info here 4.45.05 Free and licensed versions Coding No
TFS Administration Tool Handling security and permissions in TFS, Sharepoint and reporting services. Open source tool at Codeplex 2.2 Free TFS No
TFS Team Project Manager Extremely valuable. Handle maintenance of work items, process, and much more across multiple team projects at once.  No more batch files with witadmin! See it at Codeplex  1.6.4968 Free TFS No

 

Extensions we wait for, not yet in a VS 2012 version

Product Notes Latest Version License Applicable to Microsoft
Inmeta Build Explorer     Free TFS integration No

Extensions which are now integrated into VS 2012

Product Notes
Fakes Was Moles in 2010. Fakes is improved and made into a product.
NuGet Manager Included in the install, but still an extension package. Info here. So it is updated through the extension manager. Initial version is 1.6.30117.9648


Friday, November 30, 2012 #


During the summer and fall this year, me and my colleague Jakob Ehn has worked together on a book project that has now finally hit the stores!
The title of the book is Team Foundation Server 2012 Starter and is published by Packt Publishing.

Get it from http://www.packtpub.com/team-foundation-server-2012-starter/book or from Amazon http://www.amazon.com/dp/1849688389 

                 image 

The book is part of a concept that Packt have with starter-books, intended for people new to Team Foundation Server 2012 and who want a quick guideline to get it up and working. 
It covers the fundamentals, from installing and configuring it, and how to use it with source control, work items and builds. It is done as a step-by-step guide, but also includes best practices advice in the different areas. It covers the use of both the on-premises and the TFS Services version. It also has a list of links and references in the end to the most
relevant Visual Studio 2012 ALM sites.

Our good friend and fellow ALM MVP Mathias Olausson have done the review of the book, thanks again Mathias!

We hope the book fills the gap between the different online guide sites and the more advanced books that are out.

Book Description

Your quick start guide to TFS 2012, top features, and best practices with hands on examples


Overview

  • Install TFS 2012 from scratch
  • Get up and running with your first project
  • Streamline release cycles for maximum productivity


In Detail

Team Foundation Server 2012 is Microsoft's leading ALM tool, integrating source control, work item and process handling, build automation, and testing.

This practical "Team Foundation Server 2012 Starter Guide" will provide you with clear step-by-step exercises covering all major aspects of the product.
This is essential reading for anyone wishing to set up, organize, and use TFS server.

This hands-on guide looks at the top features in Team Foundation Server 2012, starting with a quick installation guide and then moving into using it for your
software development projects. Manage your team projects with Team Explorer, one of the many new features for 2012.

Covering all the main features in source control to help you work more efficiently, including tools for branching and merging, we will delve into the Agile Planning
Tools for planning your product and sprint backlogs.

Learn to set up build automation, allowing your team to become faster, more streamlined, and ultimately more productive with this
"Team Foundation Server 2012 Starter Guide".


What you will learn from this book

  • Install TFS 2012 on premise
  • Access TFS Services in the cloud
  • Quickly get started with a new project with product backlogs, source control, and build automation
  • Work efficiently with source control using the top features
  • Understand how the tools for branching and merging in TFS 2012 help you isolate work and teams
  • Learn about the existing process templates, such as Visual Studio Scrum 2.0
  • Manage your product and sprint backlogs using the Agile planning tools


Approach

This Starter guide is a short, sharp introduction to Team Foundation Server 2012, covering everything you need to get up and running.


Who this book is written for

If you are a developer, project lead, tester, or IT administrator working with Team Foundation Server 2012 this guide will get you up to speed quickly
and with minimal effort.