开发者

MSBuild several metadata requests in the same expression

开发者 https://www.devze.com 2023-02-08 14:23 出处:网络
I am writing my first MSBuild script and ran into a problem. I have several projects, defined in an itemgroup

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)\**\开发者_如何学JAVA*.*">
  <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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消