visual-studio-2010msbuildcsprojitemgroup

msbuild include / copy from subdirectory to root directory - possible?


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?


Solution

  • 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>