[英]How to get paths to all referenced DLLs in MSBuild?
I would like to get paths to all assemblies referenced in a .csproj
given the following requirements: 鉴于以下要求,我想获取
.csproj
引用的所有程序集的路径:
.dll
import) .dll
导入) There is a good answer about how to do it for project references: 对于如何做为项目参考,有一个很好的答案 :
<MSBuild Projects="@(ProjectReference)" Targets="GetTargetPath">
<Output TaskParameter="TargetOutputs" ItemName="MyReferencedAssemblies" />
</MSBuild>
Is there a similar way to get .dll
paths of all other types of references? 有没有类似的方法来获取所有其他类型的引用的
.dll
路径?
There is seems to be a clean way to do it: 似乎有一种干净的方法:
<Target Name="GatherReferences" DependsOnTargets="ResolveReferences">
<ItemGroup>
<MyReferencedAssemblies Include="@(ReferencePath)" />
</ItemGroup>
</Target>
After that MyReferencedAssemblies
item group contains a collection of all referenced DLLs (full paths, all kinds). 之后,
MyReferencedAssemblies
项组包含所有引用的DLL(完整路径,所有类型)的集合。 It also works for PackageReference
imports in the new .csproj
format. 它也适用于新
.csproj
格式的PackageReference
导入。 Important part is that @(ReferencePath)
is non-empty only after ResolveReferences
finishes. 重要的是,
@(ReferencePath)
仅在ResolveReferences
完成后才为空。
It doesn't look like TargetOutput's will give you want you want, since you are looking for inputs. 由于您正在寻找输入,因此TargetOutput看起来不会像您想要的那样。
This should be a trivial matter if you use the MSBuild API (using c#). 如果您使用MSBuild API(使用c#),这应该是一件小事。 You can can see how I extended the
Project
class to include just such a thing: 您可以看到我如何扩展
Project
类以包括以下内容:
https://github.com/chris1248/SolutionBuilder/blob/master/MSBuildTools/ProjectBase.cs https://github.com/chris1248/SolutionBuilder/blob/master/MSBuildTools/ProjectBase.cs
specifically look at the function: 具体看一下功能:
protected int GatherReferenceAssemblies()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.