我想以编程方式在Visual Studio宏中获取项目输出目录
我设法得到一个路径的字符串(通过prj.ConfigurationManager.ActiveConfiguration.Properties
并查看属性OutputDirectory
),但是这个字符串可能包含宏,例如$(foo),其中foo是在属性表中定义的,或者是什么。< / p>
如何将此输出目录字符串解析为“真实”目录?
答案 0 :(得分:2)
我为我的宏编写了这个函数,它通过子字符串搜索完整的绝对输出路径。
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