【发布时间】:2016-01-26 12:20:22
【问题描述】:
我确定我缺少一些小东西。问题来了:
我有一个包含多个项目的解决方案,每次构建后都会压缩这些项目。这是在一个项目中创建 zip 的示例(它们在其他项目中几乎相同):
<ItemGroup>
<CopySourceFiles Include="$(OutDir)\**\*.*" Exclude="$(OutDir)\**\*.pdb;$(OutDir)\*.mdf;$(OutDir)\*.ldf;$(OutDir)\*.vshost.*" />
</ItemGroup>
...
<Target Name="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<MakeDir Directories="$(OutDir)\..\zip_working" />
<!-- first copy the source files specified in the CorySourceFiles ItemGroup above. -->
<Copy SourceFiles="@(CopySourceFiles)" DestinationFiles="@(CopySourceFiles->'$(OutDir)\..\zip_working\%(RecursiveDir)%(Filename)%(Extension)')" />
<!-- Perform the zip by calling the UsingTask. Make sure the DestinationFiles above and the SourceDirectory below are pointing to the same place -->
<Zip SourceDirectory="$(OutDir)\..\zip_working" OutputFilename="$(OutDir)\..\zip\$(ProjectName).zip" />
<!-- Clean up. -->
<RemoveDir Directories="$(OutDir)\..\zip_working" />
</Target>
有一个最终项目,其中包含指向它组合成一个包的压缩文件的链接。一切看起来都很正常,但显然只有当 bin 和 zip_working 文件夹已经存在时。 IE。如果我清理解决方案,删除 bin 文件夹然后重新构建,则在每个项目的“zip”文件夹中创建的最终 zip 为空...
只有在我再次构建 之后,zip 文件才有内容。
所以我猜测在构建过程中,AfterBuild 目标在构建输出文件存在之前运行。听起来对吗?我完全从 Visual Studio 中触发构建。
无论如何,我如何确保只有在创建输出文件后才能在构建输出文件上运行任务?
适用于 Visual Studio 2013 Update 5 / MSBuild 12.0
【问题讨论】:
-
请提及 VS/msbuild 的哪个版本,因为 AfterBuild 的处理方式存在差异(例如,请参阅 stackoverflow.com/questions/13727351/…)
-
@stijn Sure - Visual Studio 2013 更新 5/MSbuild 12.0
-
谢谢,只是认为这可能无关紧要:似乎问题更可能只是 msbuild 评估顺序:在加载项目时评估 CopySourceFiles。因此,如果当时没有文件,它将是空的。尝试将包含 CopySourceFiles 的 ItemGroup 移动到 AfterBuild 目标中,以便在需要时对其进行评估。
-
@stijn 就是这样!正如你所说,我将 ItemGroup 移动到 AfterBuild 目标中,并且效果很好。再次感谢:)
标签: visual-studio msbuild