-->

MSBuild multiple outputpath

2019-07-01 23:12发布

问题:

I saw this S.O question and have a similar requirement. This is what I have in a .targets file -

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup Condition="$(TeamBuildOutDir) != '' ">
        <OutputPath>$(TeamBuildOutDir)\Assemblies</OutputPath>                 
    </PropertyGroup>

How can I output to multiple folders? e.g.- $(TeamBuildOutDir)\Assemblies2

TIA

Thanks Nick, The copy/paste mucked it up. This is what I tried -

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="$(TeamBuildOutDir) != '' ">
 <OutputPath>$(TeamBuildOutDir)\Assemblies</OutputPath>                   
</PropertyGroup>
<Target Name="AfterBuild">
 <Copy SourceFiles="$(OutputPath)\**\*.*" DestinationFolder="$(TeamBuildOutDir)\Assemblies2" />
</Target>
</Project>

I've also tried -

 <Copy SourceFiles="$(OutputPath)\***\*.*" DestinationFolder="$(TeamBuildOutDir)\Assemblies2" />

and -

 <Copy SourceFiles="$(OutputPath)\***\*.*" DestinationFolder="$(TeamBuildOutDir)\" />

in case the directory not being present caused an issue but still no luck.

Updated 7/28. Tried this but doesn't work still (no errors but the files are not present in the output directory. They are present in the Assemblies folder so I know the targets file is being triggered.) -

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="$(TeamBuildOutDir) != '' ">
 <OutputPath>$(TeamBuildOutDir)\Assemblies</OutputPath>                   
</PropertyGroup>
<Target Name="AfterBuild">
 <CreateItem Include="$(OutputPath)\**\*.*">
     <Output ItemName="Outfiles" TaskParameter="Include" />
 </CreateItem>
 <Copy SourceFiles="@(Outfiles)" DestinationFiles="@(Outfiles->'$(TeamBuildOutDir)\%(relativedir)%(Filename)%(Extension)')" SkipUnchangedFiles="false" />
</Target>
</Project>

回答1:

You create an AfterBuild target with a copy task the contents of $(OutputPath) to $(TeamBuildOutDir)\Assemblies2.

<Target Name="AfterBuild">
 <Copy SourceFiles="$(OutputPath)\**\*.*" DestinationFolder="$(TeamBuildOutDir)\Assemblies2" />
</Target>

Edit, updating this to include a test message, and include a "DependsOnTarget" attribute to see if we can get this to occur after the build process...

<Target Name="AfterBuild" DependsOnTarget="Build">
 <Message Text="**** TEST **** " Importance="high" />
 <Copy SourceFiles="$(OutputPath)\**\*.*" DestinationFolder="$(TeamBuildOutDir)\Assemblies2" />
</Target>