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
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.
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"
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.
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
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.
I addition to the accepted answer, the error can also occur when the destination folder is read-only (Common when using TFS)