XCOPY command failed with code 4 error while creating checkin with new build definition

I am using TFS2012. I created an assembly definition to build each checkin uding VS2012. In Vs2008, for my project, I created a pre-build event with XCOPY to copy some files from the solution directory to another folder. But after CheckIn Build completed with an 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 is this happening? What to do to execute a copy command before assembly?

+4
source share
7 answers

Note that adding the / C switch to xcopy does not fix the error. It just means that if xcopy detects an error with one file, and there are others to copy, it will not stop the whole copy process. It will simply fail, which cannot be copied and continued with other files that can be copied.

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

+3
source

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

+1
source

I fixed this problem by doing a copy in a different way. Open the .csproj file with a text editor and change the "AfterBuild" section at the end of the file:

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

I've never had a problem with this way of copying, and this is a cross-platform way

+1
source

From docs, exit code 4 means:

An initialization error has occurred. There is not enough memory or disk, or you specified an invalid disk name or incorrect syntax on the command line.

0
source

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

0
source

To clarify: in a solution with a lot of projects with xcopy PostBuildEvents. They failed infrequently.

  • To run Studio with height, this will not help.
  • / C just ignores the failure.
  • "start xcopy ..." is simply ignored because the launch works well (output 0), but an error occurs in the shell.
0
source

Try restarting visual studio. This may be a temporary matter. The following link will describe in different ways. The command copy is completed with code 4 at creation - restarting Visual Studio solves it

0
source

Source: https://habr.com/ru/post/1479737/


All Articles