Technology Toolbox

Your technology Sherpa for the Microsoft platform

Jeremy Jameson - Founder and Principal



Test Projects in Visual Studio 2010 Must Target .NET Framework 4

This post originally appeared on my MSDN blog:

Since I no longer work for Microsoft, I have copied it here in case that blog ever goes away.

Last week I installed Visual Studio 2010 on my primary desktop. This morning, I opened my Fabrikam.Demo solution in the new version of Visual Studio, but chose not to upgrade the target framework when prompted by Visual Studio during the solution upgrade. In other words, I chose to leave the Target framework project setting set to .NET Framework 3.5 -- at least for now.

There's no doubt I'll eventually upgrade my demo solution to .NET Framework 4, but in the short term, I imagine that I'll still be working primarily with the older version of the .NET Framework, especially since I don't believe SharePoint is going to support .NET Framework 4 anytime soon.

After viewing the conversion log and verifying that no errors or warnings occurred during the upgrade process, I then proceeded to rebuild the solution.

I was surprised to see that the build failed.

My first thought was "that's weird, the solution compiled without any warnings or errors last week when I built it using Visual Studio 2008."

Then I looked more closely at the error:

The type 'System.Web.Security.MembershipProvider' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.ApplicationServices, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Hmmm...that is strange indeed...didn't I just tell Visual Studio not to target .NET Framework 4?

I then looked at the settings for the project that failed to build (Security.DeveloperTests) and confirmed that, yes, the Target framework setting had indeed been changed to .NET Framework 4. Hmmm...must have just been a glitch, I'll just change the setting back to .NET Framework 3.5...

Unfortunately, that's when I got the following warning:

Attempted re-targeting of the project has been canceled. You cannot change the specified .NET framework version or profile for a test project.

After clicking the OK button, I noticed the project setting -- not suprisingly -- was changed back to .NET Framework 4.

After adding the reference in the Security.DeveloperTests project to the new System.Web.ApplicationServices assembly, my solution compiled without error (and all of the unit tests passed).

While I don't anticipate there to be any issues with this project setting for test projects, I would feel more comfortable if you could truly target an older version of the .NET Framework using Visual Studio 2010 (meaning, across all project types that you could create in Visual Studio 2008).


  1. # re: Test Projects in Visual Studio 2010 Must Target .NET Framework 4

    June 21, 2010 11:02 PM
    Saeid Rastak


    you can set the target .NET Framework Version in Project Properties in Application Tab.

  2. # re: Test Projects in Visual Studio 2010 Must Target .NET Framework 4

    September 1, 2010 6:41 AM

    yes, but not for a VS 2010 test project... so far.

  3. # re: Test Projects in Visual Studio 2010 Must Target .NET Framework 4

    September 5, 2010 6:53 PM
    Tim Abell

    people are angry, and microsoft's response was "Won't Fix" and "By Design" respectively.

    Plus ca change.

  4. # re: Test Projects in Visual Studio 2010 Must Target .NET Framework 4

    December 7, 2010 5:41 PM
    Euan Garden

    Get SP1 Beta, its been fixed in that

Add Comment

Optional, but recommended (especially if you have a Gravatar). Note that your email address will not appear with your comment.
If URL is specified, it will be included as a link with your name.

To prevent spam from being submitted, please select the following fruit: Apple

Please add 8 and 8 and type the answer here: