MSBuild解决项目对程序集的引用

编程入门 行业动态 更新时间:2024-10-27 07:29:43
本文介绍了MSBuild解决项目对程序集的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好! 目前,我正在开发一种代码验证工具,该工具由自定义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

推荐答案

我问了一个问题此处 [ ^ ]并获得解决方案: I''ve asked the question here[^] and get the solution: <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解决项目对程序集的引用

本文发布于:2023-11-09 23:15:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573706.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   项目   MSBuild

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!