question

DouglasGodfrey-2179 avatar image
0 Votes"
DouglasGodfrey-2179 asked ·

Visual Studio uses wrong PostBuildEvent

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?

vs-msbuild
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered ·

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.



image.png (13.0 KiB)
image.png (13.8 KiB)
·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DouglasGodfrey-2179 avatar image
0 Votes"
DouglasGodfrey-2179 answered ·

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

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DouglasGodfrey-2179 avatar image
0 Votes"
DouglasGodfrey-2179 answered ·

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.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

XCOPY output
1>...........\Build\Win32\VC9\Debug\xerces-c_3D_x86.lib
1>1 File(s) copied
1>Does C:\Program Files (x86)\WhamTech\bin specify a file name
1>or directory name on the target
1>(F = file, D = directory)? ?Does C:\Program Files (x86)\WhamTech\bin specify a file name
1>or directory name on the target
1>(F = file, D = directory)? Does C:\Program Files (x86)\WhamTech\bin specify a file name
1>or directory name on the target
1>(F = file, D = directory)? ?0 wæ▄≥K0 w=▄≥K0 w ▄≥K0 w1wwíετ< 0 α 0 á 0 P └ É ≡ á ╨ ` ╨ p ░
1>
1> X[[it ₧íª¬¡▒╜¬¬Does C:\Program Files (x86)\WhamTech\bin specify a file name
1>or directory name on the target
1>(F = file, D = directory)? Does C:\Program Files (x86)\WhamTech\bin specify a file name
1>or directory name on the target
1>(F = file, D = directory)? ?Does C:\Program Files (x86)\WhamTech\bin specify a file name
1>or directory name on the target
1>(F = file, D = directory)?

0 Votes 0 ·
cooldadtx avatar image
0 Votes"
cooldadtx answered ·

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.

· 4 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I deleted the old .vcproj file and the ,user files [there were several]
I edited the .vcxproj file and updated it to match the new command from the posting above

 <PostBuildEvent>
   <Command>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"</Command>
   <Message>echo "copy lbuild files from " "$(OutDir)" " To " "$(ProjectDir)\\..\\..\\..\\..\\..\\..\\lib64-bin64\release\"</Message>
 </PostBuildEvent>


Still the same error NOTE: xcopy is displaying the .lib file on the VS console

0 Votes 0 ·

¬Does C:\Program Files (x86)\WhamTech\bin specify a file name
1>or directory name on the target
1>(F = file, D = directory)? Does C:\Program Files (x86)\WhamTech\bin specify a file name
1>or directory name on the target
1>(F = file, D = directory)? ?Does C:\Program Files (x86)\WhamTech\bin specify a file name
1>or directory name on the target
1>(F = file, D = directory)?
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(153,5): error MSB3073: The command "xcopy /y /r ...........\Build\Win32\VC9\Debug*.lib "H:\Svn\ThirdParty\xerces-c-3.1.1\projects\Win32\VC19\xerces-all\XercesLib............\lib\Debug"
. . .
1>Done building project "XercesLib.vcxproj" -- FAILED.

0 Votes 0 ·
cooldadtx avatar image cooldadtx DouglasGodfrey-2179 ·

OK the error about does ?? specify is because of a missing quote. In your xcopy lines 3-5 you are missing a closing quote after the source path

xcopy /y /r "$(OutDir)*.dll"


Once that is fixed try running the build again.

0 Votes 0 ·

The text was mangled by Microsofts web forms any occurrence of '..\'' the slash was deleted

0 Votes 0 ·
DouglasGodfrey-2179 avatar image
0 Votes"
DouglasGodfrey-2179 answered ·

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.

· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @DouglasGodfrey-2179 , after you created new project files for each xerces-c project, did this issue disappear?

0 Votes 0 ·