如何从 Visual Studio 宏获取 msbuild 路径?

发布于 2024-12-11 05:34:12 字数 156 浏览 0 评论 0原文

我正在尝试创建一个上下文菜单项,它将在某些扩展上运行 msbuild。 我找到了将检查解决方案资源管理器中当前所选项目的扩展名的宏。

我剩下要做的就是在该文件上运行 msbuild。我不想对路径进行硬编码。 所以我认为必须有一种方法来获取当前加载的解决方案的 msbuild 路径。

I am trying to create a context menu item that will run msbuild on certain extensions.
I've found the macro that will check for the extension of the currently selected item in the solution explorer.

All I have left to do is run msbuild on the file. I don't want to hard code the path.
So I'm thinking there has to be a way to get the path to msbuild path for the currently loaded solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

东京女 2024-12-18 05:34:12

使用保留属性 $(MSBuildToolsPath),它将解析为类似以下内容,具体取决于 .NET 版本:

C:\Windows\Microsoft.NET\Frameworks\v4.0.30319\

还有 $(MSBuildExtensionsPath) 系列属性(包括 32 位和 64 位特定属性)那些)将指向:

C:\Program Files\MSBuild\

- 来自书“MSBuild Trickery”技巧#19和#43

编辑:添加宏代码以提取

以下Visual Studio宏将枚举所有当前属性,包括$(MSBuildToolsPath)、$(MSBuildToolsRoot) 和 $(MSBuildToolsPath32),最后一个可能仅在 64 位计算机上,我不确定。

'
' Note: you need to have an open solution, an active document,
' and a visible Build pane in the Output window
'
Public Module Module1
  Public Sub ListProperties()
    Dim doc As Document = DTE.ActiveDocument
    Dim projectItem As ProjectItem = doc.ProjectItem
    Dim project As Project = projectItem.ContainingProject

    Dim evalProject As Microsoft.Build.Evaluation.Project = _
        Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection _
          .LoadProject(project.FullName)

    Dim ow As EnvDTE.OutputWindow
    ow = DTE.ToolWindows.OutputWindow
    Dim wp As OutputWindowPane
    wp = ow.OutputWindowPanes.Item("Build")

    Dim e As System.Collections.Generic.IEnumerator(Of Microsoft.Build _
      .Evaluation.ProjectProperty)
    e = evalProject.AllEvaluatedProperties.GetEnumerator()
    e.MoveNext()
    For i = 0 To evalProject.AllEvaluatedProperties.Count - 1
      Dim s As String
      s = s + e.Current.Name + " = " + e.Current.UnevaluatedValue + vbCrLf
      wp.OutputString(s)
      e.MoveNext()
      s = ""
    Next
  End Sub
End Module

Use the reserved property $(MSBuildToolsPath), which will resolve to something like this, depending on the .NET version:

C:\Windows\Microsoft.NET\Frameworks\v4.0.30319\

There is also the $(MSBuildExtensionsPath) family of properties (including 32 and 64-bit specific ones) that will point to:

C:\Program Files\MSBuild\

-- from the book "MSBuild Trickery" tricks #19 and #43

edit: adding macro code to extract

The following Visual Studio Macro will enumerate all of the current properties, including $(MSBuildToolsPath), $(MSBuildToolsRoot) and $(MSBuildToolsPath32), the last one maybe only on a 64-bit machine, I'm not sure.

'
' Note: you need to have an open solution, an active document,
' and a visible Build pane in the Output window
'
Public Module Module1
  Public Sub ListProperties()
    Dim doc As Document = DTE.ActiveDocument
    Dim projectItem As ProjectItem = doc.ProjectItem
    Dim project As Project = projectItem.ContainingProject

    Dim evalProject As Microsoft.Build.Evaluation.Project = _
        Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection _
          .LoadProject(project.FullName)

    Dim ow As EnvDTE.OutputWindow
    ow = DTE.ToolWindows.OutputWindow
    Dim wp As OutputWindowPane
    wp = ow.OutputWindowPanes.Item("Build")

    Dim e As System.Collections.Generic.IEnumerator(Of Microsoft.Build _
      .Evaluation.ProjectProperty)
    e = evalProject.AllEvaluatedProperties.GetEnumerator()
    e.MoveNext()
    For i = 0 To evalProject.AllEvaluatedProperties.Count - 1
      Dim s As String
      s = s + e.Current.Name + " = " + e.Current.UnevaluatedValue + vbCrLf
      wp.OutputString(s)
      e.MoveNext()
      s = ""
    Next
  End Sub
End Module
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文