What is going wrong when Visual Studio tells me “xcopy exited with code 4”

后端 未结 16 2079
北荒
北荒 2020-12-05 01:33

I\'m not very familiar with post-build events, so I\'m a little confused as to what\'s going wrong with my program. When compiling in visual studio 2010, I get the following

相关标签:
16条回答
  • 2020-12-05 02:08

    I had a post build command that worked just fine before I did an update on VS 2017. It turned out that the SDK tools updated and were under a new path so it couldn't find the tool I was using to sign my assemblies.

    This changed from this....

    call "%VS140COMNTOOLS%vsvars32"
        "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools\x64\sn.exe" -Ra "$(TargetPath)" "$(ProjectDir)Key.snk"
    

    To This...

    "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\sn.exe" -Ra "$(TargetPath)" "$(ProjectDir)Key.snk"
    

    Very subtle but breaking change, so check your paths after an update if you see this error.

    0 讨论(0)
  • 2020-12-05 02:09

    I received the 'exited with code 4' error when the xcopy command tried to overwrite a readonly file. I managed to solve this problem by adding /R to the xcopy command. The /R indicates read only files should be overwritten

    old command:

    XCOPY /E /Y "$(ProjectDir)source file" "destination"
    

    new command

    XCOPY /E /Y /R "$(ProjectDir)source file" "destination"
    
    0 讨论(0)
  • 2020-12-05 02:09

    I ran across this issue, so I ran the xcopy command from the command line and it said:

    File creation error - The requested operation cannot be performed on a file with
     a user-mapped section open.
    

    It was actually Visual Studio holding onto something. I just restarted Visual Studio and it worked.

    0 讨论(0)
  • 2020-12-05 02:12

    I got this along with the message

    Invalid drive specification

    when copying to a network share without specifying the drive name, e.g.

    xcopy . \\localhost
    

    where

    xcopy . \\localhost\share
    

    was expected

    0 讨论(0)
  • 2020-12-05 02:14

    Switch the watch tab to the "ouput" and look for the xcopy command. Sometimes here you find some more message ( the actual xcopy output ) that could help you to solve the issue. If you don't see the output tab, use View-Output menu to show it.

    0 讨论(0)
  • 2020-12-05 02:14

    I addition to the accepted answer, the error can also occur when the destination folder is read-only (Common when using TFS)

    0 讨论(0)
提交回复
热议问题