Geeks With Blogs

News



Microsoft Store

Support This Site


AddThis Social Bookmark Button

Locations of visitors to this page

Subscribers to this feed

TwitterCounter for @sdorman

Creative Commons License


Scott Dorman Microsoft MVP, Software Architect, Developer, Author

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.

Technorati Tags: ,
Digg This
Posted on Wednesday, April 21, 2010 10:03 PM .NET (General) , Visual Studio | Back to top


Comments on this post: Visual Studio 2010 and Target Framework Version

# re: Visual Studio 2010 and Target Framework Version
Requesting Gravatar...
Is there any way to disable framework for a project not related to .NET?
Left by Ivan on Mar 17, 2011 5:09 PM

# re: Visual Studio 2010 and Target Framework Version
Requesting Gravatar...
how to check the Target Framework Version of Visual Studio 2010
Left by veeresh on Feb 20, 2012 12:14 AM

# re: Visual Studio 2010 and Target Framework Version
Requesting Gravatar...
Could not get the macro from SkyDrive. Is it available elsewhere?
Left by Kangkan Goswami on Apr 05, 2012 3:59 AM

# re: Visual Studio 2010 and Target Framework Version
Requesting Gravatar...
Kangkan, you can find the script posted on StackOverflow here: http://stackoverflow.com/questions/2956415/change-the-target-framework-for-all-my-projects-in-a-visual-studio-2010-solution
Left by David Kassa on May 30, 2012 10:17 AM

# re: Visual Studio 2010 and Target Framework Version
Requesting Gravatar...
Thanks for the visual studio tipps, they will be useful for my thesis.
Left by Maria on Jun 10, 2012 2:06 PM

# re: Visual Studio 2010 and Target Framework Version
Requesting Gravatar...
Thanks for the tip, this helped my with my course work...
Left by sarah on Oct 18, 2012 8:44 AM

# re: Visual Studio 2010 and Target Framework Version
Requesting Gravatar...
net 2 3 3.5 4
Left by liberter2 on Nov 29, 2012 12:25 PM

Your comment:
 (will show your gravatar)
 


Copyright © Scott Dorman | Powered by: GeeksWithBlogs.net | Join free