3

I am building .wsp files and then copying to a "Deployment" folder but facing a strange problem, I run build command of solution file from MSBuild target and before it creates any .wsp file on the file system, copy target executes, at that time because there is no file created on the file system, so nothing is copied to the "Deployment" folder, right after that I see wsp files on file system, If I run build process again It copies files created by last build process.

Question is, Can i instruct copy command to wait until all wsp files have been created on the file system?

<Target Name="BuildWebPackage">
    <MSBuild Projects="Intranet.sln" Properties="Configuration=Release;IsPackaging=True;" />
    <Copy SourceFiles="@(WSP)" DestinationFiles="@(WSP ->'Deployment\$(SolutionsDir)\%(Filename)%(Extension)')" />
</Target>
1

Instead of running the copy command from outside, you can run/put Copy command in "Post build event" of the project.

Example:

IF "$(ConfigurationName)" == "Release" (
    Echo Copying wsp file...
    Copy $(ProjectDir)$(ProjectName).wsp <Destination Folder>
)

This is what we do for our projects and it never fails.

Update:

If above does not work, you can create a batch file which will continuously check of the presence of WSP file and if it finds the file, it'll copy the WSP.

<Target Name="BuildWebPackage">
<MSBuild Projects="Intranet.sln" Properties="Configuration=Release;IsPackaging=True;" />
<Exec Command='copywsp.bat "{WSP file name}" "Deployment\$(SolutionsDir)\%(Filename)%(Extension)" ' />
<!-- <Copy SourceFiles="@(WSP)" DestinationFiles="@(WSP ->'Deployment\$(SolutionsDir)\%(Filename)%(Extension)')" /> -->

Content of batch file:

@echo off
echo Waiting for WSP file %1...
:check_again
if not exist %1 (
    goto check_again
) else (
    echo Copying WSP to destination
    copy %1 %2 >nul
)
  • But how that would make any difference? – Ali May 1 '14 at 7:03
  • Because Post build event only gets fired when all assemblies are compiled and package creation are done. Btw, how are you making the WSP manually (by writing custom cab ddf file) or compiling the project making the WSP automatically? – Rahul Kumar May 1 '14 at 11:38
  • the above command "<MSBuild Projects="Intranet.sln" Properties="Configuration=Release;IsPackaging=True;" />" will build the solution and makes a package as well, see "IsPackage=true" attribute. – Ali May 1 '14 at 23:54
  • 1
    I updated the answer, please check. – Rahul Kumar May 2 '14 at 7:20
  • msdn.microsoft.com/en-us/library/… – Ali Apr 8 '15 at 7:41
1

You might be able to create a new target for your copy command and have it depend on your BuildWebPackage target. That way the copy will only happen after the package target completes.

<Target Name="BuildWebPackage">
    <MSBuild Projects="Intranet.sln" Properties="Configuration=Release;IsPackaging=True;" />
</Target>
<Target Name="CopyWebPackage" DependsOnTargets="BuildWebPackage">
    <Copy SourceFiles="@(WSP)" DestinationFiles="@(WSP ->'Deployment\$(SolutionsDir)\%(Filename)%(Extension)')" />
</Target>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.