开发者

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 hav开发者_开发知识库e 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?


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>


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)')" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜