Ver versión en español    
 
Home
10 Reasons to use MZ-Tools
MZ-Tools 6.0 for VS.NET
Editions
Features
Online Documentation
MZ-Tools SDK
Download
Purchase
Version History (RSS)  
FAQ & Support
MZ-Tools 3.0 for VB6 & VBA
Features
Online Documentation
Download (freeware)
Donations (Paypal)
Version History (RSS)  
FAQ & Support
User Reviews
Community Place
Contact  
For Add-In Developers
About
   
 
User Testimonials

I'm an avid supporter of MZ-Tools. It's a product I couldn't do without and your level of support is outstanding.

Jan Hyde (Visual Basic MVP)

You will soon wonder how you ever lived without it.

Andy Maggs

More user reviews
 
HOWTO: Get the target .NET Framework of a Visual Studio 2008 project from a Visual Studio add-in or macro

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2008
Date: June 2008    
       
Introduction

Projects created with Visual Studio versions previous to Visual Studio 2008 targets a single .NET Framework version:

  • Visual Studio .NET 2002 targets .NET Framework 1.0
  • Visual Studio .NET 2003 targets .NET Framework 1.1
  • Visual Studio 2005 targets .NET Framework 2.0

Visual Studio 2008 projects can target .NET Framework 2.0, .NET Framework 3.0 and .NET Framework 3.5 (last both are actually extensions to the .NET Framework 2.0, using the same CLR, etc.).

You can specify the target .NET Framework:

  • When creating the project, in the New Project dialog window, which offers a combobox to select the target .NET Framework.
  • Afterwards, in the Project Properties dialog, "Compile" section, "Advanced Compile Options" button.

This article explains how to get programmatically the target .NET Framework of an EnvDTE.Project from a Visual Studio macro or add-in.

More Information

To get the target .NET Framework of a Visual Studio 2008 project you must get the "TargetFramework" property from the EnvDTE.Project.Properties collection. The returned value is an unsigned integer which apparently doesn't make sense. However, when you convert it to hexadecimal notation, it can be 0x20000, 0x30000 or 0x30005, representing the .NET Framework 2.0, 3.0 or 3.0 respectively.

The following macro shows the source code to get target .NET Framework:

Sub Test()

   MessageBox.Show(GetTargetFramework(DTE.Solution.Projects.Item(1)))

End Sub

Function GetTargetFramework(ByVal objProject As EnvDTE.Project) As String

   Dim iValue As Integer

   iValue = CType(objProject.Properties.Item("TargetFramework").Value, Integer)

   Return iValue.ToString("X")

End Function

Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this


MZ-Tools 6.0 for Visual Studio .NET

You can code, design, locate code and document your apps much faster using VB.NET, C#, C++ or Visual J#:

Buy MZ-Tools Now Download MZ-Tools Demo

   Top