Reputation: 687
Can I include a file from a subdirectory, but have it placed in the root directory of the bulid instead of its original sub directory?
Example: We have multiple robots.txt files for different release configurations. The files are in the solution as \IncludeTest\Development\robots.txt and \IncludeTest\Production\robots.txt
I can dynamically grab them appropriately using something like:
<ItemGroup Condition=" '$(Configuration)' == 'Development' ">
<Content Include="IncludeTest\Development\robots.txt">
<SubType>Designer</SubType>
</Content>
</ItemGroup>
but when I do that, I maintain the \IncludeTest\Development\ (or \IncludeTest\Production) directory. Any way to just include it in the root directory, where robots.txt is supposed to be?
Upvotes: 3
Views: 2257
Reputation: 687
The above still did not work for me entirely, but I was able to find a work around based on how you set up the itemgroup:
Including the file in the solution as a link puts it in the root directory. And with your $(Configuration) hint, I was able to do this, and just include it dynamically as a link, rather than copy it over to the root.
<Content Include="..\Robots_Source\$(Configuration)\robots.txt">
<Link>robots.txt</Link>
</Content>
Upvotes: 2
Reputation: 62514
Not sure I got your question right, let me know whether this work as you expected:
<ItemGroup>
<Content Include = "IncludeTest\$(Configuration)\robots.txt">
<SubType>Designer</SubType>
</Content>
</ItemGroup>
Copy to root:
<Copy SourceFiles="@(Content)"
DestinationFiles="@(Content ->'..\%(RecursiveDir)%(Filename)%(Extension)')" />
EDIT: It could be problem when files are in nested directories, so try out:
<Copy SourceFiles="@(Content)"
DestinationFiles="@(Content ->'$(MSBuildProjectDirectory)..\%(RecursiveDir)%(Filename)%(Extension)')" />
Upvotes: 0