Click here to Skip to main content
Sign Up to vote bad
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
Edited 14-Jun-12 8:56am

"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? --SA
SAKryukov - 14-Jun-12 18:13pm
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 - 14-Jun-12 18:22pm
Maybe indeed, the point is not clear enough: I want to get this: H:\Informatik\C#\SharedAssemblies\HDUnitsOfMeasure\HDUnitsOfMeasureValidator\bin\Debug\HDUnitsOfMeasureValidator.dll from this: <ProjectReference Include="..\HDUnitsOfMeasureValidator\HDUnitsOfMeasureValidator.csproj"> <Project>{50D3B367-102B-45E9-8917-C7F7D0BC6565}</Project> HDUnitsOfMeasureValidator </ProjectReference>
Henning Dieterichs - 26-Jun-12 11:46am

1 solution

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.


  Print Answers RSS
Your Filters
0 Maciej Los 2,127
1 Sergey Alexandrovich Kryukov 1,559
2 CPallini 798
3 OriginalGriff 550
4 Tadit Dash 389
0 Sergey Alexandrovich Kryukov 14,818
1 OriginalGriff 9,337
2 Maciej Los 6,012
3 thatraja 4,350
4 CPallini 4,207

Advertise | Privacy | Mobile
Web01 | 2.7.131219.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid