Pre Build Action in Windows Application Project

Copper Contributor



Trying to copy files to target folder in a pre build action with this command

xcopy /y "$(SolutionDir)..\common\lib\AnyCPU\*.*" "$(TargetDir)"


Getting error as follows:

Severity Code Description Project File Line Suppression State
Error MSB3073 The command "xcopy /y "E:\\AppSystem\..\common\lib\AnyCPU\*.*" """ exited with code 4. WAP.AppSystem D:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 1330


Seems like wapproj does not like macros in pre build actions because the macro expression disappears. Tried with other macro expressions - each one disappears on build.


Pl advise asap.



12 Replies

Hi @abhisinghal 


Thanks for reporting this. We're following up with the Visual Studio team to see what the issue is with using macros in prebuild actions in the wapproj. 



@abhisinghal This appears to be an ordering issue, you need to move the <PreBuildEvent> propertygroup in the .wapproj below the import for the .targets at the bottom of the file.


Out of curiosity, what are you using the copy PreBuildEvent for? The Packaging Project will not pick up the files in the output folder to package unless you have another step to add them to the package, so I am not sure why you would want to copy these files there?

@scoban Thanks - Yes that was going to be the next question.


Even if the files are manually copied, the packager does not pick up files in the output folder to package.


So what is that additional step to do so ?



@abhisinghal What is the scenario you are trying to enable that does not work with normal project references?


If you really need this behavior I would suggest using an itemgroup for the files that you want, This is not really recommended as the projects that you reference should be including all the files needed for packaging and they also include additional metadata that we use for other reasons.  In other words this could have unintended side effects depending on what you are doing.

 <None Include="SomeDir\*">


@scoban Thanks - will try this.


The scenario I am trying to enable is this.


Project has a reference to LibraryA.dll , which is AnyCPU.

This LibraryA uses some platform specific dlls which are dynamically loaded using assembly resolver.

On the pre-build action, we copy files for both platforms to the output folder under sub folders x64 and x86, and then load depending on the platform on which app is running.


Do I need to do anything else to package above ?



@scoban Getting this error


Severity Code Description Project File Line Suppression State
Error PRI175: 0x8007000b - Processing Resources failed with error: An attempt was made to load a program with an incorrect format. AppSystem.Wap GENERATEPROJECTPRIFILE 1


Package format selected is neutral.

@abhisinghal Thats not enough to go off of, do you have a sample project I can look at? Try building for x86/x64 instead?

@scoban Tried with that too but no change.

PFA a simple sample project where the error is thrown when creating the package.

Please advise.

@abhisinghal I was able to successfully package that app with a more recent version of Visual Studio and even tried with a slightly older version.  Try deleting your bin/obj folders (Clean the project).


Did you see the error with the sample project as well?

@scoban Yes I did see that with the sample project before uploading it here.


Cleaned and built again and saw the same error again.


Just to make sure, I am building for Microsoft Store with the following options:




Here is my Visual Studio about box:



Pl advise. 



@scoban awaiting your reply.


@abhisinghal I was not able to reproduce the issue with the provided project.  I noticed you have some commented out prebuild events which could be causing it if you are testing with those uncommented.  I need a repro so that I can investigate further.