MSBuild copy output from another project into the output of the current project

前端 未结 2 984
小鲜肉
小鲜肉 2020-12-18 04:41

I have a situation where I want to copy the output assembly from one project into the output directory of my target application using MSBuild, without hard-coding paths in m

相关标签:
2条回答
  • 2020-12-18 05:20

    I have made this work, though I would love to find a cleaner solution that takes advanctage of the built-in parameters within MSBuild (like $(TargetDir), etc but to point at the project I want to grab the output for). Anyway, here is what I've done:

    <Target Name="AfterBuild">
    <Copy SourceFiles="$(SolutionDir)MyProject.Dal.Linq\bin\$(Configuration)\MyProject.Dal.Linq.dll" DestinationFolder="$(TargetDir)"/>
    </Target>
    

    I would love to see a cleaner solution, but this should do for now.

    0 讨论(0)
  • 2020-12-18 05:46

    So, you want to have a reference, but not have it visible in VS. So you want it built if needed, and copied to output like any other Content file. Here's how you'd do it:

    <Target Name="IncludeDALImplementation" BeforeTargets="AfterBuild">
      <MSBuild Projects="..\DalImplementation\DAL.csproj" BuildInParallel="$(BuildInParallel)" Targets="Build">
        <Output TaskParameter="TargetOutputs" ItemName="DalImplementationOutput" />
      </MSBuild>
    
      <ItemGroup>
        <Content Include="@(DalImplementationOutput)" />
      </ItemGroup>
    </Target>
    
    0 讨论(0)
提交回复
热议问题