Daniel Eugen
Daniel Eugen

Reputation: 2780

Post Build Event Exited with Code 1

I am trying to clean up the release folder using Post Build event so i delete .xml and .pdb files and try to copy all dll files into custom lib folder bug i get Post Build Exited with Code 1

My code:

if $(ConfigurationName) == Release del "$(TargetDir)*.xml", "$(TargetDir)*.pdb"
if $(ConfigurationName) == Release xcopy "$(TargetDir)\*.dll" "$(TargetDir)\lib\"

The 2 commands are separated by new line as shown... Also Lib folder exists.

Upvotes: 8

Views: 38226

Answers (7)

Steve Smith
Steve Smith

Reputation: 2270

I always end my pre/post build events with the line @set ERRORLEVEL=0, since programs like xcopy seem to return a non-zero error even with success.

Upvotes: 0

RJN
RJN

Reputation: 736

If you use relative path in Copy command then make sure the parent directory refers to appropriate directory you intend for otherwise you will get exit code 1 error.

For ex:

copy "C:\SolnFolder\project1\release\bin\xyz.dll" "..\MainProject\bin\x86\"

Here, Project1 and MainProject coexist at SolnFolder. When I thought of copying xyz.dll into MainProject's x86 folder, it failed because ..\ used in copy command refers release folder of source path instead of SolnFolder. Hence, the below solved the issue:

copy "C:\SolnFolder\project1\release\bin\xyz.dll" "..\..\..\MainProject\bin\x86\"

NOTE: Also, make sure quotes are used with every relative path

Upvotes: 0

SHIBIN
SHIBIN

Reputation: 467

This solution worked for me

xcopy "$(TargetDir)*.dll" "$(TargetDir)lib\"

Upvotes: 0

D T
D T

Reputation: 3746

Try open VS with Run as Administrator -> open project -> build.

Upvotes: 4

Jsinh
Jsinh

Reputation: 2579

This modification worked for me:

del *.XML, *.pdb
xcopy /y "$(TargetDir)*.dll" "$(TargetDir)lib\"

1). Omit target directory variable in del command

2). /y option in xcopy Note from Microsoft Help page: /y : Suppresses prompting to confirm that you want to overwrite an existing destination file.

Upvotes: 2

Reg Edit
Reg Edit

Reputation: 6914

Instead of

xcopy $(TargetDir)*.dll $(TargetDir)lib\

you should use

xcopy "$(TargetDir)*.dll" "$(TargetDir)lib\"

to handle spaces in the path.

Upvotes: 8

David
David

Reputation: 10708

First, try using $(TargetDir)\, as there are some variables which return without a trailing slash, which would concatenate your path so you're looking for bin\Debuglib\ instead of bin\Debug\lib

As pointed out by @Uwe Keim, Return Code 1 means no files found to copy. This can also happen if you're pointed at an invalid folder, furthering the idea that you may need that \.

There is also the possibility that the del command has failed, though the same technet article on del does not indicate any return codes. Some forum sources indicate a return code of 1 may indicate a failed deletion.

Upvotes: 2

Related Questions