IT researcher
IT researcher

Reputation: 3304

The command "XCOPY" exited with code 4 error while building checkin with new build definition

I am using TFS2012.I have created a build definition to build every checkIn uding VS2012. In Vs2008 for my project i have created a pre-build event with XCOPY to copy some files from solution Directory to another folder.But after i do CheckIn Build is failing with following error

Summary
Debug | Any CPU
 1 error(s), 0 warning(s)
$/test/coding_files/cal_reg.sln - 1 error(s), 0 warning(s), View Log File
 C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets (895): The command "XCOPY "C:\Builds\1\test\New Build Definition 1\Sources\coding_files\*.*" "\\pc97\D\" /E /Y /R /K" exited with code 4.
 $/test/coding_files/cal_reg.sln compiled
 No Test Results
 No Code Coverage Results
Other Errors and Warnings
 1 error(s), 0 warning(s)
 Exception Message: MSBuild error 1 has ended this build. You can find more specific information about the cause of this error in above messages. (type BuildProcessTerminateException)
Exception Stack Trace:    at System.Activities.Statements.Throw.Execute(CodeActivityContext context)
   at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Why this is happening?what to do to execute copy command before build?

Upvotes: 4

Views: 25826

Answers (5)

Mari
Mari

Reputation: 228

I fixed this issue by doing copy in another way. Open your .csproj file with text editor and modify "AfterBuild" section at the end of file:

<Target Name="AfterBuild">
    <ItemGroup>
        <MyFile Include="myfile.xml"/>
    </ItemGroup>
    <Copy SourceFiles="@(MyFile)" DestinationFolder="$(OutputPath)" />
</Target>

I have never had an issue with such way of copying and it is cross-platform way

Upvotes: 1

Manuraj Bharall
Manuraj Bharall

Reputation: 11

Try to restart your visual studio. This may be temporary issue. Following link will describe different way Command copy exited with code 4 when building - Visual Studio restart solves it

Upvotes: 0

Rashad Valliyengal
Rashad Valliyengal

Reputation: 3162

instead of xcopy, use start xcopy /Y /R. This worked for me.

Upvotes: 3

user3739214
user3739214

Reputation: 91

Please note that adding the /C switch to xcopy does not fix an error. It simply means that if xcopy encounters an error with one file and there are others to copy, it will not fail the whole copy process. It will just fail whatever can't be copied and continue on with other files that can be copied.

In some situations this may be desirable behavior but it could also be dangerous, hiding an actual copy problem depending on how you implement it.

Upvotes: 3

Reddy
Reddy

Reputation: 119

Running the same xcopy command in powershell I saw Sharing Vilation. Adding /C to xcopy fixed the porblem.

Upvotes: -1

Related Questions