How do I fix MSB3073 error in my post-build event?

…衆ロ難τιáo~ 提交于 2019-11-27 20:06:20

Playing around with different project properties, I found that the project build order was the problem. The project that generated the files I wanted to copy was built second, but the project that was running the batch file as a post-build event was built first, so I simply attached the build event to the second project instead, and it works just fine. Thanks for your help, everyone, though.

Prefer the MsBuild "Copy" task in an AfterBuild target over a post-build event.

Append this Target into your project file and remove the PostBuildEvent.

<Target Name="AfterBuild">
    <Copy SourceFiles="C:\Users\scogan\Documents\Visual Studio 2012\Projects\Organizr\Server\bin\Debug\Organizr.Services.*" 
          DestinationFolder="C:\inetpub\wwwroot\AppServer\bin\" 
          OverwriteReadOnlyFiles="true" 
          SkipUnchangedFiles="false" />
</Target>

For what it's worth, the problem in my case was caused by using '/' as the directory separator in a copy command. Must use backslashes.

In my case, the dll I was creating by building the project was still in use in the background. I killed the application and then xcopy worked fine as expected.

The specified error is related to the post built event. Somehow VS tool is not able to copy the files to the destination folder. There can be many reasons for it. To check the exact error cause go to Tools > Option> Project and Solution > Built and run, and change "MsBuild project build output verbosity" to "Diagnostic". It will give you enough information to detect the actual problem.

This is too late but posting my experience for people looking at it later:- In MS VS 2010 I had the same issue. It got resolved by putting quotes to post build copy command args which contained spaces !!!

In Project Properties --> Configuration Properties --> Build Events --> Post-Build Event --> Command Line changed

copy $(ProjectDir)a\b\c $(OutputPath)

to

copy "$(ProjectDir)a\b\c" "$(OutputPath)"

If the problem still persists even after putting the after build in the correct project try using "copy" instead of xcopy. This worked for me.

The Post-Build Event (under Build Events, in the properties dialog) of an imported project, had an environment variable which was not defined.
Navigated to Control Panel\All Control Panel Items\System\Advanced system settings to add the appropriate environment variable, and doing no more than restarting VS2017 resolved the error.
Also, following on from @Seans and other answers regarding multiple project races/contentions, create a temp folder in the output folder like so,

and select the project producing the preferred output:

and build (no rebuild/clean) is a speedy solution.

I solved it by doing the following: In Visual studio I went in Project -> Project Dependencies

I selected the XXX.Test solution and told it that it also depends on XXX solution to make the post-build events in the XXX.Test solution not generating this error (exit with code 4).

Regards,

Following thing you should do before to run copy command if you facing some issue with copy command

  1. open solution as a administrator and build the solution.
  2. if you have problem like "0 File(s) copied" check you source and destination path. might you are using wrong path. it would be better if you run the same command in "command prompt" to check whether it is working fine or not.

I had the same problem for my Test project. I found out why my post build event wasn't working and that's because I was copying files before running the $(ProjectName).exe command and some of these files were required for Test project itself. Hence, by just moving $(ProjectName).exe as the first command fix the issue.

I've found the issue happens when you have multiple projects building in parallel and one or more of the projects are attempting to copy the same files, creating race conditions that will result in occasional errors. So how to solve it?

There's a lot of options, as above just changing things around could solve the issue for some people. More robust solutions would be...

a. Restrict the files being copied i.e. instead of xcopy $(TargetDir)."... instead do xcopy "$(TargetDir)$(TargetName).*"...

b. Catch the error and retry i.e

:loop
xcopy /Y /R /S /J /Q  "$(TargetDir)$(TargetName).*" "somewhere"
if ErrorLevel 1 goto loop

c. User robocopy instead of xcopy

d. You probably won't want to do this as it will increase your build times, but you could reduce the maximum number of parallel project builds to 1...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!