1

I want to programatically get a project output directory in a Visual Studio macro.
I managed to get a string of the path (through prj.ConfigurationManager.ActiveConfiguration.Properties and looking at property OutputDirectory) but this string may contain macros such as $(foo) where foo is defined in a property sheet or whatnot.

How do I resolve this output directory string to the 'real' directory?

expert
  • 29,290
  • 30
  • 110
  • 214
Zack
  • 2,021
  • 4
  • 18
  • 19

1 Answers1

2

I wrote this function for my macros which searches for full absolute output path by substring.

Function FindOutBinaryNameByExtension(ByVal prj As EnvDTE.Project, ByVal extName As String) As String
    FindOutBinaryNameByExtension = Nothing

    Dim cm As ConfigurationManager = prj.ConfigurationManager
    If cm IsNot Nothing Then
        Dim ac As Configuration = cm.ActiveConfiguration
        For Each grpOut In ac.OutputGroups
            If grpOut.DisplayName = "Primary output" Then
                Dim lst As Array = grpOut.FileURLs
                For i As Long = 0 To lst.Length - 1
                    Dim fileName As String = lst.GetValue(i)
                    If fileName.Contains(extName) Then
                        FindOutBinaryNameByExtension = fileName
                        Exit Function
                    End If
                Next
            End If
        Next
    End If
End Function
expert
  • 29,290
  • 30
  • 110
  • 214