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 output build folder from a Visual Studio add-in or macro

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: July 2009   Microsoft Visual Studio .NET 2003
      Microsoft Visual Studio 2005
      Microsoft Visual Studio 2008

Introduction

A Visual Studio project can have several project configurations, each one with a different output build folder that is set in the project properties window, Compile/Build section, Build output path. Furthermore, the output build folder can be absolute or relative to the project folder.

More Information

The following macro gets the absolute output build folder for the active configuration of each project of a solution.

Language: VB.NET   Copy Code Copy Code (IE only)
Sub Macro1()

   Dim proj As EnvDTE.Project

   For Each proj In DTE.Solution.Projects

    GetProjectOutputBuildFolder(proj)

   Next

End Sub

Sub GetProjectOutputBuildFolder(ByVal proj As EnvDTE.Project)

   Dim activeConfiguration As EnvDTE.Configuration
   Dim configManager As EnvDTE.ConfigurationManager
   Dim outputPath As String
   Dim absoluteOutputPath As String
   Dim projectFolder As String

   Try

      ' Get the configuration manager of the project
      configManager = proj.ConfigurationManager

      If configManager Is Nothing Then

         MessageBox.Show("The project " & proj.Name & " doesn't have a configuration manager")

      Else

         ' Get the active project configuration
         activeConfiguration = configManager.ActiveConfiguration

         ' Get the output folder
         outputPath = activeConfiguration.Properties.Item("OutputPath").Value.ToString()

         ' The output folder can have these patterns:
         ' 1) "\\server\folder"
         ' 2) "drive:\folder"
         ' 3) "..\..\folder"
         ' 4) "folder"

         If outputPath.StartsWith(IO.Path.DirectorySeparatorChar & IO.Path.DirectorySeparatorChar) Then

            ' This is the case 1: "\\server\folder"
            
            absoluteOutputPath = outputPath

         ElseIf outputPath.Length >= 2 AndAlso outputPath.Chars(1) = IO.Path.VolumeSeparatorChar Then

            ' This is the case 2: "drive:\folder"
            
            absoluteOutputPath = outputPath

         ElseIf outputPath.IndexOf("..\") <> -1 Then

            ' This is the case 3: "..\..\folder"
            
            projectFolder = IO.Path.GetDirectoryName(proj.FullName)

            Do While outputPath.StartsWith("..\")
               outputPath = outputPath.Substring(3)
               projectFolder = IO.Path.GetDirectoryName(projectFolder)
            Loop

            absoluteOutputPath = IO.Path.Combine(projectFolder, outputPath)

         Else

            ' This is the case 4: "folder"
            
            projectFolder = IO.Path.GetDirectoryName(proj.FullName)
            absoluteOutputPath = IO.Path.Combine(projectFolder, outputPath)

         End If

         MessageBox.Show("Output folder of " & proj.Name & ": " & absoluteOutputPath)

      End If

   Catch ex As Exception

      MessageBox.Show(ex.ToString)

   End Try

End Sub

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