MsBuild可以输出类似于makedepend的依赖信息吗?

发布于 2024-12-11 19:41:12 字数 318 浏览 0 评论 0原文

有没有办法强制 MsBuild 以类似于 makedepend 的结构化形式输出目标依赖信息?对于包含 C# 和 C++ 项目的解决方案,我需要在解决方案级别使用它。我对输出格式并不挑剔。

我认为 C# 依赖关系可以通过处理 .csproj 文件并构建 DAG 来确定。同样,我可以在 C++ 源代码上运行开源 makedepend 并从那里开始。我真的不想在这里自己动手——这似乎是 MsBuild 应该能够做到的事情,即使是为了诊断目的。

Is there a way to force MsBuild to output target dependency information in a structured form similar to makedepend? I need this at the solution level for a solution containing C# and C++ projects. I'm not picky about the output format.

I've considered that the C# dependencies can be determined by processing the .csproj files and building a DAG. Likewise I could run an open-source makedepend on the C++ sources and go from there. I'm really trying not to roll my own here -- this seems like something that MsBuild ought to be able to just do, if even for diagnostic purposes.

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

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

发布评论

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

评论(1

山色无中 2024-12-18 19:41:12

我解决了这个问题,没有太多的牦牛剃毛。显然,MsBuild 在构建期间确实具有依赖项信息,因此我的方法是使用自定义目标包装构建,该目标将依赖项写入 .depends 文件:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- Write project dependencies to a .depends file, one line per dependency -->
  <Target Name="OutputProjectDependencies">
    <Delete Files="$(OutputPath)\$(TargetFileName).depends"/>
    <WriteLinesToFile File="$(OutputPath)\$(TargetFileName).depends" 
      Lines="@(CscDependencies->'%(FullPath)');@(ReferencePath->'%(FullPath)');@(Content->'%(FullPath)');@(_NoneWithTargetPath->'%(FullPath)')"
      Overwrite="false"
      Encoding="UTF-8"/>
    <WriteLinesToFile File="$(OutputPath)\$(TargetFileName).depends" 
      Lines="@(ClDependencies->'%(FullPath)')"
      Overwrite="false"
      Encoding="UTF-8"/>
  </Target>

  <ItemGroup>
    <CscDependencies Include="@(Compile);@(EmbeddedResource)"/>
    <ClDependencies Include="@(ClCompile);@(ClInclude)"/>
  </ItemGroup>

  <PropertyGroup>
    <BuildDependsOn>
      $(BuildDependsOn);
      OutputProjectDependencies;
    </BuildDependsOn>
  </PropertyGroup>

</Project>

这并不像我希望的 C++ 项目那样强大(它缺少包含的内容)头文件和链接库依赖项),但可能还可以进一步增强。我相信这对于 C# 来说是一种非常可靠的方法——它包括引用的程序集、嵌入式资源和内容。

I solved this without too much yak shaving. Obviously MsBuild does have the dependency info during the build so my approach is to wrap the build with a custom target that writes the dependency to a .depends file:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <!-- Write project dependencies to a .depends file, one line per dependency -->
  <Target Name="OutputProjectDependencies">
    <Delete Files="$(OutputPath)\$(TargetFileName).depends"/>
    <WriteLinesToFile File="$(OutputPath)\$(TargetFileName).depends" 
      Lines="@(CscDependencies->'%(FullPath)');@(ReferencePath->'%(FullPath)');@(Content->'%(FullPath)');@(_NoneWithTargetPath->'%(FullPath)')"
      Overwrite="false"
      Encoding="UTF-8"/>
    <WriteLinesToFile File="$(OutputPath)\$(TargetFileName).depends" 
      Lines="@(ClDependencies->'%(FullPath)')"
      Overwrite="false"
      Encoding="UTF-8"/>
  </Target>

  <ItemGroup>
    <CscDependencies Include="@(Compile);@(EmbeddedResource)"/>
    <ClDependencies Include="@(ClCompile);@(ClInclude)"/>
  </ItemGroup>

  <PropertyGroup>
    <BuildDependsOn>
      $(BuildDependsOn);
      OutputProjectDependencies;
    </BuildDependsOn>
  </PropertyGroup>

</Project>

This is not quite as robust as I'd like for C++ projects (it lacks included header and link library dependencies) but could probably be further enhanced. I believe this is a very solid approach for C# -- it includes referenced assemblies, embedded resources and content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文