msbuild include/从子目录复制到根目录 - 可能吗?

发布于 2024-11-29 19:08:09 字数 568 浏览 1 评论 0原文

我可以包含子目录中的文件,但将其放置在 bulid 的根目录中而不是其原始子目录中吗?

示例:我们有多个用于不同发布配置的 robots.txt 文件。这些文件在解决方案中为 \IncludeTest\Development\robots.txt 和 \IncludeTest\Production\robots.txt

我可以使用类似的方法动态地抓取它们:

  <ItemGroup Condition=" '$(Configuration)' == 'Development' ">
    <Content Include="IncludeTest\Development\robots.txt">
      <SubType>Designer</SubType>
    </Content>
  </ItemGroup>

但是当我这样做时,我会维护 \IncludeTest\Development\ (或\includeTest\Production) 目录。有什么方法可以将其包含在根目录中,即 robots.txt 应该在的位置吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

落花随流水 2024-12-06 19:08:09

上述方法仍然不完全适合我,但我能够根据您设置项目组的方式找到解决方法:

将文件作为链接包含在解决方案中,将其放入根目录中。通过您的 $(Configuration) 提示,我能够做到这一点,并且只需将其动态包含为链接,而不是将其复制到根目录。

<Content Include="..\Robots_Source\$(Configuration)\robots.txt">
  <Link>robots.txt</Link>
</Content>

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>
老娘不死你永远是小三 2024-12-06 19:08:09

不确定我的问题是否正确,请让我知道这是否按您的预期工作:

 <ItemGroup>
    <Content Include = "IncludeTest\$(Configuration)\robots.txt">
      <SubType>Designer</SubType>
    </Content>
  </ItemGroup>

复制到根目录:

<Copy SourceFiles="@(Content)" 
   DestinationFiles="@(Content ->'..\%(RecursiveDir)%(Filename)%(Extension)')" />

编辑:当文件位于嵌套目录中时可能会出现问题,因此请尝试:

 <Copy SourceFiles="@(Content)" 
   DestinationFiles="@(Content ->'$(MSBuildProjectDirectory)..\%(RecursiveDir)%(Filename)%(Extension)')" />

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)')" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文