Click here to Skip to main content
Click here to Skip to main content

Visual Studio 2010 and Target Framework Version

By , 22 Apr 2010
 

Almost two years ago, I wrote about a Visual Studio macro that allows you to change the Target Framework version of all projects in a solution. If you don’t know, the Target Framework version is what tells the compiler which version of the .NET Framework to compile against (more information is available here) and can be set to one of the following values:

  • .NET Framework 2.0
  • .NET Framework 3.0
  • .NET Framework 3.5
  • .NET Framework 3.5 Client Profile
  • .NET Framework 4.0
  • .NET Framework 4.0 Client Profile

This can be easily accomplished by editing the project properties:

image

The problem with this approach is that if you need to change a lot of projects at one time it becomes rather unwieldy. One possible solution is to edit the project files by hand in a text editor and change the <TargetFrameworkVersion /> and <TargetFrameworkProfile /> properties to the correct values.

For example, for the .NET Framework 4.0 Client Profile, these values would be:

<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

<TargetFrameworkProfile>Client</TargetFrameworkProfile>

Again, this is not only time consuming but can also be error-prone.

The better solution is to automate this through the use of a Visual Studio macro. Since I had already created a macro to do this for Visual Studio 2008, I updated that macro to work with Visual Studio 2010 and .NET 4.0. It prompts you for the target framework version you want to set for all of the projects and then loops through each project in the solution and makes the change. If you select one of the Framework versions that support a Client Profile, it will ask if you want to use the Client Profile or the Full Profile. It is smart enough to skip project types that don’t support this property and projects that are already at the correct version. This version also incorporates the changes suggested by George (in the comments).

The macro is available on my SkyDrive account. Download it to your <UserProfile>\Documents\Visual Studio 2010\Projects\VSMacros80\MyMacros folder, open the Visual Studio Macro IDE (Alt-F11) and add it as an existing item to the “MyMacros” project.

I make no guarantees or warranties on this macro. I have tested it on several solutions and projects and everything seems to work and not cause any problems, but, as always, use with caution. Since it is a macro, you have the full source code available to investigate and see what it’s actually doing. If you find any bugs or make any useful changes, please let me know and I’ll update the macro.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Scott Dorman
Software Developer (Senior)
United States United States
Member
Scott is a C# MVP and author who has been involved with computers in one way or another for as long as he can remember, but started professionally in 1993. He has worked at Fortune 500 companies and privately held start-ups focused on IT consulting where he gained experience in embedded systems design and software development to systems administration and database programming, and everything in between.
 
After spending 6 years as a systems administrator, Scott started developing eCommerce store fronts. Since 2001, he has worked on many different projects using .NET and C#. Although his primary focus right now is commercial software applications, he prefers building infrastructure components, reusable shared libraries and helping companies define, develop and automate process standards and guidelines.
 
Scott runs a software architecture-focused user group, speaks extensively, and contributes regularly to online communities such as The Code Project and StackOverflow, and is the Community Manager and Senior Editor for DotNetKicks.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionNew URLmemberScavanger33318 Oct '12 - 6:10 
QuestionMacro is gone from the live drive?memberjeroenp16 Aug '12 - 2:58 
QuestionIs the VS 2008 version of this macro still around?memberJeremy Thomas30 Nov '11 - 10:01 
GeneralMy vote of 5memberrobvon18 Oct '10 - 15:33 
GeneralPlease post the macro on Code Projectmemberrobvon18 Oct '10 - 15:32 
GeneralMy vote of 5memberjimbucc28 Sep '10 - 9:30 
QuestionStupid Question?memberJohnny J.22 Apr '10 - 20:22 
AnswerRe: Stupid Question?memberScott Dorman23 Apr '10 - 3:41 
GeneralRe: Stupid Question?memberJohnny J.23 Apr '10 - 6:48 
GeneralRe: Stupid Question?memberScott Dorman23 Apr '10 - 6:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 22 Apr 2010
Article Copyright 2010 by Scott Dorman
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid