Inherit Post-Build-Event in Visual Studio?

吃可爱长大的小学妹 提交于 2019-12-08 21:33:23

问题


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.


回答1:


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.




回答2:


After finding this solution and looking at the other post. I found it impossible to understand why the VC++ team would leave this feature out.

After looking through the Macros for the property pages you can include the command from the previous properties using the %(Command) macro / environment variable. This works for all build events.

PropertySheet1.props

copy some.dll $(OutputPath)
%(Command)

PropertySheet2.props

copy other.dll $(OutputPath)
%(Command)

Results in all commands being executed.




回答3:


As some Post-Build Events did non inherit from the property sheet they are defined in, I questioned the duck and landed here.

I have good news: Since Visual Studio 2013, the Pre-Build and Post-Build event command lines have a "Inherit from parent or project defaults" option, which adds all events from the property sheets.

(Tested with Visual Studio 2013 and 2017 Professional)



来源:https://stackoverflow.com/questions/15232329/inherit-post-build-event-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!