8

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.

Light
  • 55
  • 7
JBentley
  • 6,099
  • 5
  • 37
  • 72

3 Answers3

21

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.

discomurray
  • 14,411
  • 1
  • 21
  • 11
2

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.

Pooven
  • 1,744
  • 1
  • 25
  • 44
  • No, I have resorted to manually maintaining every project separately, as per my question. The only solution I have thought of (but not attempted to implement) is designing my own inheritance structure through scripts - have every project call the same script as its post-build event but pass in the project name as a variable, and have the script run the additional commands as appropriate. Clunky, but at least it reduces maintenance to just a single file. – JBentley Dec 09 '13 at 15:43
  • Alternatively, have each project call it's own script (by using MSVC's built in macros to call the script from a project-dependent location), and have the scripts recursively call the script(s) from the project(s) they inherit from. The main problem with both of these approaches is that the inheritance structure itself has to be updated in two places (property sheets, and scripts), otherwise they fall out of sync. – JBentley Dec 09 '13 at 15:45
0

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)

Yamakuzure
  • 367
  • 2
  • 9
  • 1
    This is nice, but doesn't solve the problem. As soon as you add a custom post-build event to your project, it replaces the inherited value. Your custom post-build step runs _instead of_ the inherited one. The original question was asking how to run a custom post-build step _in addition_ to the inherited one. – foo64 Aug 31 '18 at 22:20
  • Sorry, I reacted on "The usual "Inherit from parent or project defaults" is missing". – Yamakuzure Sep 06 '18 at 17:23