问题描述
你好!
目前,我正在开发一种代码验证工具,该工具由自定义MSBuild任务实现,由目标"BeforeBuild"调用.
为了进行验证,我必须扫描属于该项目的所有cs文件,并解决对外部程序集的所有访问.
但是要做到这一点,我需要知道当前项目引用了哪些程序集.
通过传递引用"元素,我可以解析所有直接引用,因为程序集的位置存储在提示属性中.
遗憾的是,由于仅提供了csproj-path,因此无法将项目引用"元素解析为其对应的程序集.
我的自定义任务的定义如下:
Hello!
Currently I''m working on a code-validation tool, realized by a custom MSBuild Task, which is called by the target "BeforeBuild".
For validation, I have to scan all the cs-files belonging to the project and resolve all accesses to foreign assemblies.
But to do this, I need to know which assemblies are referenced by the current project.
By passing the "reference" elements I can resolve all direct references, as the location of the assembly is stored in the hint-property.
Sadly, I am not able to resolve the "project-reference" elements to their corresponding assemblies, as only the csproj-path is supplied.
The definition of my custom task looks as following:
<MyValidationTask Files="@(Compile)" ProjectReferences="@(ProjectReference)" References="@(Reference)" />
如何解决对程序集的项目引用?
感谢您的回答,
Henning
How can I resolve a project-reference to the assembly?
Thanks for answering,
Henning
推荐答案
<Target Name="BeforeBuild"
DependsOnTargets="ResolveProjectReferences;ResolveAssemblyReferences">
<UnitValidationTask Files="@(Compile)"
References="@(_ResolveAssemblyReferenceResolvedFiles)" />
</Target>
现在,所有已解析的引用都在引用"中,完整路径存储在任务项的身份"属性中.
Now, all the resolved references are in "References" and the full path is stored in the "Identity" property of the task item.
这篇关于MSBuild解决项目对程序集的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!