Reputation: 2086
When a C# project references another C# project (e.g. a lib), Visual Studio adds something like this to the project file:
<ItemGroup>
<ProjectReference Include="..\some\path\lib.csproj">
<Project>{4beb6b28-90f5-77c3-af2a-f5fa3336dac9}</Project>
<Name>Lib</Name>
</ProjectReference>
</ItemGroup>
Let’s assume, lib.csproj
contains some items like this:
<SpecialFile Include="foo.dll" />
<SpecialFile Inclued="bar.txt" />
How can I access these SpecialFile
items in the first project file? I’d like to do something like this:
<Target Name="SpecialFileCopyTarget" AfterTargets="AfterBuild">
<Copy
DestinationFolder="$(OutputPath)"
SourceFiles="@(SpecialFile)" <-- ?????
SkipUnchangedFiles="true" />
</Target>
I think I do not want to Import
the lib.csproj
, just get the items somehow.
Upvotes: 1
Views: 20
Reputation: 833
XmlPeek task allows to query any XML file:
<XmlPeek Namespaces="<Namespace Prefix='n' Uri='http://schemas.microsoft.com/developer/msbuild/2003'/>"
XmlInputPath="%(ProjectReference.FullPath)"
Query="/n:Project/n:ItemGroup/n:SpecialFile/@Include">
<Output TaskParameter="Result" ItemName="SpecialFiles" />
</XmlPeek>
This code will collect SpecialFile items from all referenced projects. Please specify ToolsVersion="4.0" for your project.
Upvotes: 1