3

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?

dah97765
  • 679
  • 1
  • 13
  • 29

2 Answers2

1

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>
dah97765
  • 679
  • 1
  • 13
  • 29
  • So you have tried using task with updated destination files path? I've tried different cases and it works for me perfectly, basically copying specified files up to the parent folder, an important point is using of $(MSBuildProjectDirectory) – sll Aug 17 '11 at 15:28
0

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)')" />
sll
  • 61,540
  • 22
  • 104
  • 156
  • Unfortunately, it does not behave as I would like. What it does is puts the parent folder structure (IncludeTest\...) in the root, rather that just the file, robots.txt – dah97765 Aug 16 '11 at 20:38
  • You doing somethign wrong, it should only move files included in @(Content) into the parent dir. Just testet on my PC – sll Aug 16 '11 at 20:49
  • I've added one more option in EDIT, try it out – sll Aug 16 '11 at 21:05
  • I was not able to get it to work for me in that way. Not sure what the differences are, but I still marked as answer bc it seems to be working for you, and it eventually led me to something that did work (see answer below). - Thanks! – dah97765 Aug 17 '11 at 15:21