如何获取MSBuild中所有引用的DLL的路径? [英] How to get paths to all referenced DLLs in MSBuild?

查看:60
本文介绍了如何获取MSBuild中所有引用的DLL的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在满足以下要求的情况下,我想获取 .csproj 中引用的所有程序集的路径:

I would like to get paths to all assemblies referenced in a .csproj given the following requirements:

  • 包括程序集,无论它们如何被引用(项目,nuget,直接的 .dll 导入)
  • 不触发构建

关于如何执行此操作很好的答案:

<MSBuild Projects="@(ProjectReference)" Targets="GetTargetPath">
  <Output TaskParameter="TargetOutputs" ItemName="MyReferencedAssemblies" />
</MSBuild>

是否有类似的方法来获取所有其他类型的引用的 .dll 路径?

Is there a similar way to get .dll paths of all other types of references?

推荐答案

似乎有一种干净的方法:

There is seems to be a clean way to do it:

  <Target Name="GatherReferences" DependsOnTargets="ResolveReferences">
    <ItemGroup>
      <MyReferencedAssemblies Include="@(ReferencePath)" />
    </ItemGroup>
  </Target>

此后, MyReferencedAssemblies 项组包含所有引用的DLL(完整路径,各种类型)的集合.它也适用于以新的 .csproj 格式导入的 PackageReference .重要的是,只有在 ResolveReferences 完成后, @(ReferencePath)才是非空的.

After that MyReferencedAssemblies item group contains a collection of all referenced DLLs (full paths, all kinds). It also works for PackageReference imports in the new .csproj format. Important part is that @(ReferencePath) is non-empty only after ResolveReferences finishes.

这篇关于如何获取MSBuild中所有引用的DLL的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆