Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Project MSBuild BUILD Task , +
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
0 Sergey Alexandrovich Kryukov 495
1 OriginalGriff 339
2 ChintanShukla 305
3 Richard Deeming 260
4 RyanDev 230
0 Sergey Alexandrovich Kryukov 8,768
1 OriginalGriff 7,387
2 CPallini 2,603
3 Richard MacCutchan 2,095
4 Abhinav S 1,893


Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 2 Jul 2012
Copyright © CodeProject, 1999-2014
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