Hassan
Hassan

Reputation: 2653

MSBuild several metadata requests in the same expression

I am writing my first MSBuild script and ran into a problem.

I have several projects, defined in an itemgroup

<ItemGroup>
  <Projects Include="Project1Dir\Project1.csproj"/>
  <Projects Include="Project2Dir\Project2.csproj"/>
</ItemGroup>

Then, on deployment step, I am trying to do this:

The following should collect all the files for deployment into separate itemgroups for each project ("Project1deploymentFiles" and "Project2deploymentFiles")

<CreateItem Include="$(WebPublishDir)\%(Projects.Filename)\**\*.*">
  <Output ItemName="%(Projects.Filename)deploymentFiles" TaskParameter="Include"/>
</CreateItem>

Thes line, should copy each project's files into separate folder

<Copy SourceFiles="@(%(Projects.Filename)deploymentFiles)" DestinationFolder="$(DeploymentDir)\%(Projects.Filename)\%(RecursiveDir)\" />

But it seems that MSBuild resolves %(RecursiveDir) metadata to empty string, as all the files are copied to the same root folder (different for each project).

Any suggestions what am I doing wrong here?

Upvotes: 1

Views: 162

Answers (1)

Hassan
Hassan

Reputation: 2653

I've found a solution myself:

<CreateItem Include="$(WebPublishDir)\%(Projects.Filename)\**\*.*" AdditionalMetadata="ProjectDir=%(Projects.Filename)\">
  <Output ItemName="deploymentFiles" TaskParameter="Include"/>
</CreateItem>

<Copy SourceFiles="@(deploymentFiles)" DestinationFolder="$(DeploymentDir)\%(ProjectDir)\%(RecursiveDir)\" />

Main idea here is to use one item for all projects and just add AdditionalMetadata to values, containing projectname

Upvotes: 1

Related Questions