Click here to Skip to main content
15,881,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:
XML
<MyValidationTask Files="@(Compile)" ProjectReferences="@(ProjectReference)" References="@(Reference)" />


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


Thanks for answering,
Henning
Posted
Updated 14-Jun-12 8:56am
v2
Comments
Sergey Alexandrovich Kryukov 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 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:
H:\Informatik\C#\SharedAssemblies\HDUnitsOfMeasure\HDUnitsOfMeasureValidator\bin\Debug\HDUnitsOfMeasureValidator.dll

from this:
<ProjectReference Include="..\HDUnitsOfMeasureValidator\HDUnitsOfMeasureValidator.csproj">
<Project>{50D3B367-102B-45E9-8917-C7F7D0BC6565}</Project>
<name>HDUnitsOfMeasureValidator
</ProjectReference>

1 solution

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

XML
<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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900