给定一个在以下位置运行的 MSBuild 任务AfterTargets="AfterCompile"
并生成一些文件,如何将这些文件包含在当前项目输出中,以便将这些文件复制到引用该项目的任何项目的 bin 目录中?
我不能保证这是正确的解决方案,但它似乎有效:
<Target Name="MyTarget" AfterTargets="AfterCompile">
<PropertyGroup>
<MyInput>D:\1.txt</MyInput>
<MyOutput>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)$(OutDir)\1.txt'))</MyOutput>
</PropertyGroup>
<Copy SourceFiles="$(MyInput)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true" />
<ItemGroup>
<AllItemsFullPathWithTargetPath Include="$(MyOutput)">
<TargetPath>1.txt</TargetPath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</AllItemsFullPathWithTargetPath>
</ItemGroup>
</Target>
相关逻辑在这里:http://sourceroslyn.io/#MSBuildTarget=获取 CopyToOutputDirectory 项目 http://sourceroslyn.io/#MSBuildTarget=GetCopyToOutputDirectoryItems
http://sourceroslyn.io/#MSBuildItem=AllItemsFullPathWithTargetPath http://sourceroslyn.io/#MSBuildItem=AllItemsFullPathWithTargetPath
基本上,我们依赖于这样一个事实:为了确定要从依赖项目复制的文件列表,MSBuild 调用依赖项目的 GetCopyToOutputDirectoryItems 目标并使用其输出(即 AllItemsFullPathWithTargetPath)。
通过在最后一刻将我们自己添加到 AllItemsFullPathWithTargetPath 中,当依赖项目调用我们时,我们就会被接听。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)