Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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)" />
 
How can I resolve a project-reference to the assembly?
 

Thanks for answering,
Henning
Posted 13-Jun-12 3:01am
Edited 14-Jun-12 8:56am
v2
Comments
SAKryukov at 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? --SA
Henning Dieterichs at 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 at 26-Jun-12 11:46am
   
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>

1 solution

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

Solution 1

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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,518
1 OriginalGriff 503
2 Manas Bhardwaj 393
3 Tadit Dash 310
4 Damith Weerasinghe 290
0 Sergey Alexandrovich Kryukov 9,575
1 OriginalGriff 5,856
2 Peter Leow 4,405
3 Maciej Los 3,540
4 Abhinav S 3,513


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