Click here to Skip to main content
13,201,050 members (57,896 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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)" />

How can I resolve a project-reference to the assembly?

Thanks for answering,
Posted 13-Jun-12 3:01am
Updated 14-Jun-12 8:56am
SAKryukov 14-Jun-12 18:13pm
"I am not able" is not descriptive. The set references is clearly indicated in the project file, as you can see in your own example. Or do you want to find the set of references from and already-built assembly? This is also possible, via Reflection, but this is something you can include in your custom Task assembly. So, what's the problem?
Henning Dieterichs 14-Jun-12 18:22pm
Thank you for your response!
I want to resolve the "project-reference" into an assembly:
Through the "ProjectReferences" property of my task, I get only an array of ITaskItem.
But how can I get the file path to the assembly (i.e. the compiled project in the same solution) from this ITaskItem object?
There is no property like HintPath, in contrast to the normal "References" ITaskItem.
Henning Dieterichs 26-Jun-12 11:46am
Maybe indeed, the point is not clear enough:

I want to get this:

from this:
<ProjectReference Include="..\HDUnitsOfMeasureValidator\HDUnitsOfMeasureValidator.csproj">

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I've asked the question here[^] and get the solution:

<Target Name="BeforeBuild" 
  <UnitValidationTask Files="@(Compile)"
        References="@(_ResolveAssemblyReferenceResolvedFiles)" />

Now, all the resolved references are in "References" and the full path is stored in the "Identity" property of the task item.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171020.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100