在 Visual Studio 中继承构建后事件? [英] Inherit Post-Build-Event in Visual Studio?

查看:35
本文介绍了在 Visual Studio 中继承构建后事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 中有一个解决方案,其中我有一个共享属性表,其中包含需要为每个项目执行的构建后事件命令 (bar).

<块引用>

Foo.props > 通用属性 > 构建事件 > 构建后事件 >命令行 = bar

然后如何指定其他特定于项目的构建后事件?缺少通常的从父项或项目默认值继承",我宁愿不必手动将 bar 添加到每个项目,因为它很难维护.

解决方案

基于此 post,这似乎不可能.您不久前发布了您的问题;您是否设法找到了可行的替代方案?

<小时>

反馈后一个潜在的混乱替代方法是将您的命令定义为宏:

<属性组><CommandX>bar</CommandX></PropertyGroup>

然后您可以将 $(CommandX) 添加到项目的构建后命令或另一个属性表.如果 $(CommandX) 不存在,它会被悄悄地忽略.

如果您将此宏添加到另一个属性表,那么您必须Import CommandX 属性表,以便 $(CommandX) 继承一个值:

<ImportGroup Label="PropertySheets"><导入项目="CommandX.props"/></ImportGroup>

<小时>

在了解了有关构建过程的更多信息后,我想推荐使用 MSBuild 任务;特别是,Exec 任务 可能会提供最可行的解决方案.>

I have a solution in Visual Studio in which I have a shared property sheet which contains a Post-Build Event command (bar) which needs to execute for every project.

Foo.props > Common Properties > Build Events > Post-Build Event > Command Line = bar

How do I then specify additional project-specific Post-Build Events? The usual "Inherit from parent or project defaults" is missing, and I would rather not have to manually add bar to every single project as it makes it hard to maintain.

解决方案

Based on this post, it doesn't seem possible. You posted your question a while ago; did you manage to find a feasible alternative?


Edited after feedback: A potentially messy alternative would be to define your command as a macro:

<!-- CommandX.props -->
<PropertyGroup>
  <CommandX>bar</CommandX>
</PropertyGroup>

Then you could add $(CommandX) to the post-build command of the project or to another property sheet. If $(CommandX) doesn't exist, it is quietly ignored.

If you add this macro to another property sheet, then you'd have to Import your CommandX property sheet so that $(CommandX) inherits a value:

<!-- Some-Other-Property-Sheet.props -->
<ImportGroup Label="PropertySheets">
  <Import Project="CommandX.props" />
</ImportGroup>


After learning a bit more about the build process, I'd like to recommend using MSBuild tasks; in particular, the Exec task might offer the most feasible solution.

这篇关于在 Visual Studio 中继承构建后事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆