views:

784

answers:

1

Currently I have set up a Web Deployment Project which compiles code into the .\Release folder. After the build I want to copy the files over to another machine (because whichever directory you build to is deleted then recreated).

The ItemGroup for defining which files to copy is set up as follows:

<ItemGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
 <ReleaseFiles Include=".\Release\**\*" />
 <OverrideFiles Include="..\website\App_Code\override\site.com\**\*" />
</ItemGroup>

'website' is code that is used for multiple sites, so there are several web deployment projects set up within the solution.

Then, I have the AfterBuild target to copy the files:

<Target Name="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
 <Copy SourceFiles="@(ReleaseFiles)" ContinueOnError="true" SkipUnchangedFiles="true" DestinationFiles="@(ReleaseFiles->'\\server\web\site.com\%(RecursiveDir)%(Filename)%(Extension)')" />
 <Copy SourceFiles="@(OverrideFiles)" DestinationFiles="@(OverrideFiles->'\\server\web\site.com\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>

However, the ReleaseFiles aren't copied, what can be the cause of that? I have had the error .\TempBuildDir\folder\subfolder - The process cannot access the file because it is being used by another process. where folder\subfolder can be different each time, but even when that message doesn't appear the files still aren't copied.

Problem is, it has worked before.

+3  A: 

The core trouble is that the ItemGroup in your sample is being evaluated at the time the MSBuild file is loaded - and at that time, most likely, those files don't exist yet.....

Therefore your "ReleaseFiles" and "OverrideFiles" collections are empty, and then nothing gets copied.

What you need to do is create your ItemGroups dynamically after the build has happened (and the files referenced here are indeed present):

<CreateItem Include=".\Release\**\*">
   <Output TaskParameter="Include" ItemName="ReleaseFiles"/>
</CreateItem>
<CreateItem Include="..\website\App_Code\override\site.com\**\*">
   <Output TaskParameter="Include" ItemName="OverrideFiles"/>
</CreateItem>

Now you should be fine, and the copy task should work.

Marc

marc_s
Does CreateItem go under ItemGroup or Target?
Sam
You should put it into the `AfterBuild` target, before the Copy tasks.
marc_s
That fixed it for me
Sam
Also fixed it for me. Yay Google.
roufamatic