Reputation: 2780
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
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
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
Reputation: 467
This solution worked for me
xcopy "$(TargetDir)*.dll" "$(TargetDir)lib\"
Upvotes: 0
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
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
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