Visual Studio uses wrong PostBuildEvent

Douglas Godfrey 1 Reputation point
2021-03-02T19:28:38.617+00:00

Visual Studio 2019 projects for xerces-c mibrated from Visual Studio 2008.
When I build the project everything compiles without errors but the PostBuildEvent fails with return code 2.
The Output window shows commands that are NOT in the project's PostBuildEvent.

PostBuildEvent used by Visual Studio 2019
xcopy /y /r "$(OutDir).lib" "$(ProjectDir)............\lib\Debug"
xcopy /y /r "$(OutDir)
.dll "C:\Program Files (x86){CompanyName}\bin"
xcopy /y /r "$(OutDir).pdb "C:\Program Files (x86){CompanyName}\bin"
xcopy /y /r "$(OutDir)
.map "C:\Program Files (x86){CompanyName}\bin"
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(153,5): error MSB3073:
:VCEnd" exited with code 2.

Actual PostBuildEvent
xcopy /y /r "$(OutDir).pdb" "$(ProjectDir)............\lib64\debug\"
xcopy /y /r "$(OutDir)
.map" "$(ProjectDir)............\lib64\debug\"
xcopy /y /r "$(OutDir).lib" "$(ProjectDir)............\lib64\debug\"
xcopy /y /r "$(OutDir)
.dll" "$(ProjectDir)............\bin64\debug\"
exit 0

NOTE : Different output directory paths and a different order to the commands.

Question: Where is Visual Studio 2019 getting these incorrect commands from?
How do I fix the project so it uses the PostBuildEvent that is specified in the project?

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,797 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Michael Taylor 51,346 Reputation points
    2021-03-02T19:59:27.823+00:00

    Post build events are defined in the project file. If you open it up in a text editor (because you don't trust what VS is showing you) then you'll see the commands to be run. That is what MSBuild will run. Post build events are simply a custom Target that is inserted into the project file that executes after the build. So anything inside that target will run.

    But given the messaging it appears you are building a C++ project. It is useful to mention this (or tag it) when posting so we have some context. In .NET projects you have a single pre/post-build for all configurations/platforms. But C++ allows a separate set of tasks for each configuration/platform combination. Therefore my gut instinct is that what you're looking at in the UI is the Debug/x86 settings. But when you build the solution the solution is compiling the project using Debug/x64. That configuration/platform combination uses a different set of options.

    In the UI at the top of the build events editor is the configuration/platform that it is specified for. Change to the configuration/platform you are building and check the tasks to make sure they line up with what you expect. Note that you'll need to do this for each configuration/platform you want to use.

    73449-image.png

    Now right click the solution in Solution Explorer and select the Configuration Manager option. In that UI is the solution's configuration/platform mappings. When you build/debug in VS it is using the solution's configuration/platform settings, not the projects. The Configuration Manager UI shows you what configuration/platform is being built for each project in the solution. Ensure that they line up with what you expect. For example most of the time the solution's Debug/x86 mapping should build each project's Debug/x86 mapping. However there are exceptions.

    73429-image.png

    Ensure the solution mapping you're building is using the project's mappings that you expect and thus the build events associated with that mapping in the project are correct.

    0 comments No comments

  2. Douglas Godfrey 1 Reputation point
    2021-03-02T20:15:14.47+00:00

    I opened the .vcxproj file using notepad and the commands that Visual Studio used were NOT in the file.

    0 comments No comments

  3. Douglas Godfrey 1 Reputation point
    2021-03-02T20:17:58.713+00:00

    Visual Studio uses WRONG PostBuildEvent [NOT the PostBuildEvent in the .vcxproj file]

    PostBuildEvent used by Visual Studio 2019
    xcopy /y /r "$(OutDir).lib" "$(ProjectDir)..\..\..\..\..\..\lib\Debug"
    xcopy /y /r "$(OutDir)
    .dll "C:\Program Files (x86)\{CompanyName}\bin"
    xcopy /y /r "$(OutDir).pdb "C:\Program Files (x86)\{CompanyName}\bin"
    xcopy /y /r "$(OutDir)
    .map "C:\Program Files (x86)\{CompanyName}\bin"
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(153,5): error MSB3073:
    :VCEnd" exited with code 2.

    Actual PostBuildEvent in the .vcxproj file
    xcopy /y /r "$(OutDir).pdb" "$(ProjectDir)\..\..\..\..\..\..\lib64\debug\"
    xcopy /y /r "$(OutDir)
    .map" "$(ProjectDir)\..\..\..\..\..\..\lib64\debug\"
    xcopy /y /r "$(OutDir).lib" "$(ProjectDir)\..\..\..\..\..\..\lib64\debug\"
    xcopy /y /r "$(OutDir)
    .dll" "$(ProjectDir)\..\..\..\..\..\..\bin64\debug\"
    exit 0

    NOTE : Different output directory paths and a different order to the commands.


  4. Michael Taylor 51,346 Reputation points
    2021-03-02T20:38:04.723+00:00

    Two things come to mind. The first thing is that the vcxproj format is the current C++ project file format but that format was added in VS2010 or somewhere thereabouts. Before that it would have been the vcproj format. The older format didn't run under MSBuild and had its own way of doing things. The C++ team switched to the newer format so that C++ projects would fit into the MSBuild infrastructure and behave like other languages. Unfortunately not everything the old format supported worked in the newer format. When you try to open the older project it should prompt a one time conversion to the newer format. Without seeing the entire project it would be hard to tell if the post build event is actually coming from something related to the older format and being referenced by the new project file. That would happen through an Import element or similar I would wager.

    The second thing that comes to mind is that it isn't actually a post build event that is generating that output but a build step (perhaps from the conversion) that is behaving like a post build event. But that would be difficult to trace down.

    My recommendation is to enable diagnostic logging in the build output and build your solution. Then search in the build output log for the lines containing the bad event. From there you can see what is triggering that task to run and that might provide some insight into where it is coming from. For C++ there is the Build Log FIle that you might be able to look at as well.


  5. Douglas Godfrey 1 Reputation point
    2021-03-04T06:56:55.857+00:00

    At this time I am trying to create brand new project files for each xerces-c project with the same source files as the old projects.

    This is needed anyway because xerces-c 3.2.3 does not come with any visual studio projects.