将属性组值从一个 MsBuild 任务传递到另一个任务
如何使一个构建目标中定义的值在其他目标中保持活动状态?如果 PropertyGroup 不是我应该在此处使用的写入 MsBuild 实体,那么什么是? ReleaseDir 在“Package”目标中打印正常,但在“DoPackage”中为空
<Target Name="Package">
<PropertyGroup>
<ReleasesDir>c:\tmp</ReleasesDirBase>
</PropertyGroup>
<Message Text="$(ReleaseDir)"/>
<CallTarget Targets="DoPackage" Condition="!Exists('$(ReleaseDir)')"/>
</Target>
<!-- Do the acutal packaging -->
<Target Name="DoPackage">
<Message Text="Creating package in '$(ReleaseDir)'"/>
<Error Condition="'$(ReleaseDir)' == ''" Text="No ReleaseDir defined"/>
<MakeDir Directories="$(ReleaseDir)"/>
...
</Target>
How do I keep values defined in one build target alive in other targert? If PropertyGroup is not the write MsBuild entity I should use here, what is? ReleaseDir is printed ok in "Package" target, but is empty in "DoPackage"
<Target Name="Package">
<PropertyGroup>
<ReleasesDir>c:\tmp</ReleasesDirBase>
</PropertyGroup>
<Message Text="$(ReleaseDir)"/>
<CallTarget Targets="DoPackage" Condition="!Exists('$(ReleaseDir)')"/>
</Target>
<!-- Do the acutal packaging -->
<Target Name="DoPackage">
<Message Text="Creating package in '$(ReleaseDir)'"/>
<Error Condition="'$(ReleaseDir)' == ''" Text="No ReleaseDir defined"/>
<MakeDir Directories="$(ReleaseDir)"/>
...
</Target>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个 属性和 CallTarget 任务的众所周知的问题。您应该改用 DependsOnTargets。
There is a well known issue with properties and the CallTarget task. You should use DependsOnTargets instead.
这可能不是解决这个问题的最干净的方法,但是如果有人仍然想在构建文件上使用CallTarget,他/她必须在另一个Target中定义PropertyGroup,以下是解决方案这个奇怪的问题。
It might not be the cleanest way to solve this problem, but if some one still wants to use CallTarget on the build file, he/she must define the PropertyGroup in another Target, the following is the solution to this weird problem.
如果想要将属性传递给目标,MSBuild 任务可能会很有用。这是使用不同属性值多次调用目标的唯一方法,但它不允许传入项目或项目组。请参阅线程中的此评论朱利安链接到。
使用 MSBuild 任务的代码片段如下所示:
如果您想将目标用作子例程(可以使用不同的参数值多次调用该子例程),则此技术非常有用。例如,调用多个产品配置的构建过程。
If one wants to pass a property to a target, the MSBuild task can be useful. This is the only way to call a target multiple times with different property values, but it does not allow passing in items or item groups. See this comment in the thread that Julien links to.
Here is what your code snippet would look like using the MSBuild task:
This technique is useful if you want to use the target as a subroutine, which you can call multiple times with different parameter values. For example, to call a build process for several product configurations.