Pre Build Action in Windows Application Project

%3CLINGO-SUB%20id%3D%22lingo-sub-1300860%22%20slang%3D%22en-US%22%3EPre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1300860%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETrying%20to%20copy%20files%20to%20target%20folder%20in%20a%20pre%20build%20action%20with%20this%20command%3C%2FP%3E%3CP%3Excopy%20%2Fy%20%22%24(SolutionDir)..%5Ccommon%5Clib%5CAnyCPU%5C*.*%22%20%22%24(TargetDir)%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGetting%20error%20as%20follows%3A%3C%2FP%3E%3CP%3ESeverity%20Code%20Description%20Project%20File%20Line%20Suppression%20State%3CBR%20%2F%3EError%20MSB3073%20The%20command%20%22xcopy%20%2Fy%20%22E%3A%5Cvs.com%5CAppSystem%5C..%5Ccommon%5Clib%5CAnyCPU%5C*.*%22%20%22%22%22%20exited%20with%20code%204.%20WAP.AppSystem%20D%3A%5CProgram%20Files%20(x86)%5CMicrosoft%20Visual%20Studio%5C2019%5CProfessional%5CMSBuild%5CCurrent%5CBin%5CMicrosoft.Common.CurrentVersion.targets%201330%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESeems%20like%20wapproj%20does%20not%20like%20macros%20in%20pre%20build%20actions%20because%20the%20macro%20expression%20disappears.%20Tried%20with%20other%20macro%20expressions%20-%20each%20one%20disappears%20on%20build.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPl%20advise%20asap.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1306527%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1306527%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F618460%22%20target%3D%22_blank%22%3E%40abhisinghal%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks%20for%20reporting%20this.%20We're%20following%20up%20with%20the%20Visual%20Studio%20team%20to%20see%20what%20the%20issue%20is%20with%20using%20macros%20in%20prebuild%20actions%20in%20the%26nbsp%3B%3CSPAN%3Ewapproj.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ETanaka%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1310365%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1310365%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F618460%22%20target%3D%22_blank%22%3E%40abhisinghal%3C%2FA%3E%26nbsp%3BThis%20appears%20to%20be%20an%20ordering%20issue%2C%20you%20need%20to%20move%20the%20%3CPREBUILDEVENT%3E%20propertygroup%20in%20the%20.wapproj%20below%20the%20import%20for%20the%20.targets%20at%20the%20bottom%20of%20the%20file.%3C%2FPREBUILDEVENT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOut%20of%20curiosity%2C%20what%20are%20you%20using%20the%20copy%20PreBuildEvent%20for%3F%20The%20Packaging%20Project%20will%20not%20pick%20up%20the%20files%20in%20the%20output%20folder%20to%20package%20unless%20you%20have%20another%20step%20to%20add%20them%20to%20the%20package%2C%20so%20I%20am%20not%20sure%20why%20you%20would%20want%20to%20copy%20these%20files%20there%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1311751%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1311751%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F623142%22%20target%3D%22_blank%22%3E%40scoban%3C%2FA%3E%26nbsp%3BThanks%20-%20Yes%20that%20was%20going%20to%20be%20the%20next%20question.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EEven%20if%20the%20files%20are%20manually%20copied%2C%20the%20packager%20does%20not%20pick%20up%20files%20in%20the%20output%20folder%20to%20package.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20what%20is%20that%20additional%20step%20to%20do%20so%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1313449%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1313449%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F618460%22%20target%3D%22_blank%22%3E%40abhisinghal%3C%2FA%3E%26nbsp%3BWhat%20is%20the%20scenario%20you%20are%20trying%20to%20enable%20that%20does%20not%20work%20with%20normal%20project%20references%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20really%20need%20this%20behavior%20I%20would%20suggest%20using%20an%20itemgroup%20for%20the%20files%20that%20you%20want%2C%20This%20is%20not%20really%20recommended%20as%20the%20projects%20that%20you%20reference%20should%20be%20including%20all%20the%20files%20needed%20for%20packaging%20and%20they%20also%20include%20additional%20metadata%20that%20we%20use%20for%20other%20reasons.%26nbsp%3B%20In%20other%20words%20this%20could%20have%20unintended%20side%20effects%20depending%20on%20what%20you%20are%20doing.%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%3CITEMGROUP%3E%0A%20%3CNONE%20include%3D%22SomeDir%5C*%22%3E%0A%20%20%3CCOPYTOOUTPUTDIRECTORY%3EPreserveNewest%3C%2FCOPYTOOUTPUTDIRECTORY%3E%0A%20%3C%2FNONE%3E%0A%3C%2FITEMGROUP%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1315301%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1315301%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F623142%22%20target%3D%22_blank%22%3E%40scoban%3C%2FA%3E%26nbsp%3BThanks%20-%20will%20try%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20scenario%20I%20am%20trying%20to%20enable%20is%20this.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EProject%20has%20a%20reference%20to%20LibraryA.dll%20%2C%20which%20is%20AnyCPU.%3C%2FP%3E%3CP%3EThis%20LibraryA%20uses%20some%20platform%20specific%20dlls%20which%20are%20dynamically%20loaded%20using%20assembly%20resolver.%3C%2FP%3E%3CP%3EOn%20the%20pre-build%20action%2C%20we%20copy%20files%20for%20both%20platforms%20to%20the%20output%20folder%20under%20sub%20folders%20x64%20and%20x86%2C%20and%20then%20load%20depending%20on%20the%20platform%20on%20which%20app%20is%20running.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDo%20I%20need%20to%20do%20anything%20else%20to%20package%20above%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1327506%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1327506%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F623142%22%20target%3D%22_blank%22%3E%40scoban%3C%2FA%3E%26nbsp%3BGetting%20this%20error%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ESeverity%20Code%20Description%20Project%20File%20Line%20Suppression%20State%3C%2FSPAN%3E%3CBR%20%2F%3E%3CSPAN%3EError%20PRI175%3A%200x8007000b%20-%20Processing%20Resources%20failed%20with%20error%3A%20An%20attempt%20was%20made%20to%20load%20a%20program%20with%20an%20incorrect%20format.%20AppSystem.Wap%20GENERATEPROJECTPRIFILE%201%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EPackage%20format%20selected%20is%20neutral.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1329454%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1329454%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F618460%22%20target%3D%22_blank%22%3E%40abhisinghal%3C%2FA%3E%26nbsp%3BThats%20not%20enough%20to%20go%20off%20of%2C%20do%20you%20have%20a%20sample%20project%20I%20can%20look%20at%3F%20Try%20building%20for%20x86%2Fx64%20instead%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1331395%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1331395%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F623142%22%20target%3D%22_blank%22%3E%40scoban%3C%2FA%3E%26nbsp%3BTried%20with%20that%20too%20but%20no%20change.%3C%2FP%3E%3CP%3EPFA%20a%20simple%20sample%20project%20where%20the%20error%20is%20thrown%20when%20creating%20the%20package.%3C%2FP%3E%3CP%3EPlease%20advise.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1332878%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1332878%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F618460%22%20target%3D%22_blank%22%3E%40abhisinghal%3C%2FA%3E%26nbsp%3BI%20was%20able%20to%20successfully%20package%20that%20app%20with%20a%20more%20recent%20version%20of%20Visual%20Studio%20and%20even%20tried%20with%20a%20slightly%20older%20version.%26nbsp%3B%20Try%20deleting%20your%20bin%2Fobj%20folders%20(Clean%20the%20project).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDid%20you%20see%20the%20error%20with%20the%20sample%20project%20as%20well%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1332985%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1332985%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F623142%22%20target%3D%22_blank%22%3E%40scoban%3C%2FA%3E%26nbsp%3BYes%20I%20did%20see%20that%20with%20the%20sample%20project%20before%20uploading%20it%20here.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECleaned%20and%20built%20again%20and%20saw%20the%20same%20error%20again.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EJust%20to%20make%20sure%2C%20I%20am%20building%20for%20Microsoft%20Store%20with%20the%20following%20options%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22abhisinghal_0-1587662397748.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F186234iD1A0F88AED274D35%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22abhisinghal_0-1587662397748.png%22%20alt%3D%22abhisinghal_0-1587662397748.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20my%20Visual%20Studio%20about%20box%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22abhisinghal_0-1587662556562.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F186237i2EE1785724CDF549%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22abhisinghal_0-1587662556562.png%22%20alt%3D%22abhisinghal_0-1587662556562.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPl%20advise.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1355847%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1355847%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F623142%22%20target%3D%22_blank%22%3E%40scoban%3C%2FA%3E%26nbsp%3Bawaiting%20your%20reply.%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1358410%22%20slang%3D%22en-US%22%3ERe%3A%20Pre%20Build%20Action%20in%20Windows%20Application%20Project%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1358410%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F618460%22%20target%3D%22_blank%22%3E%40abhisinghal%3C%2FA%3E%26nbsp%3BI%20was%20not%20able%20to%20reproduce%20the%20issue%20with%20the%20provided%20project.%26nbsp%3B%20I%20noticed%20you%20have%20some%20commented%20out%20prebuild%20events%20which%20could%20be%20causing%20it%20if%20you%20are%20testing%20with%20those%20uncommented.%26nbsp%3B%20I%20need%20a%20repro%20so%20that%20I%20can%20investigate%20further.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi

 

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:\vs.com\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.

 

Thanks

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. 

 

Tanaka

@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 ?

 

Thanks

@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.

<ItemGroup>
 <None Include="SomeDir\*">
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
 </None>
</ItemGroup>

 

@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 ?

 

Thanks

@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:

 

abhisinghal_0-1587662397748.png

 

Here is my Visual Studio about box:

abhisinghal_0-1587662556562.png

 

Pl advise. 

 

Thanks

@scoban awaiting your reply.

Thanks

@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.