views:

2449

answers:

1

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 my MSBuild Copy task. Here's the scenario:

  • Project A - Web Application Project
  • Project B - Dal Interface Project
  • Project C - Dal Implementation Project

There is a Business layer too, but has no relevance for the MSBuild problem I'm looking to solve.

My business layer has a reference to my Dal.Interface project. My web project has a reference to the Business layer and as it stands, doing a build will pull the business layer and Dal.Interface projects into the output. So far, so good. Now in order for the web app to run, it needs the Dal implementation. I don't want the implementation referenced anywhere since I want to enforce coding to the interface and not having a reference means it won't show up in intellisense, etc.

So I figured I could handle this through the MSBuild copy operation as an AfterBuild task (I have the Dal Implementation setup to build when the web project builds, just not referenced). I don't want to hard code paths or anything else in the MSBuild params, so I'm trying to figure out how to reference the output of the Dal project from the Web Application Project's MSBuild file.

So based on the projects mentioned above this is what I want to see happen:

  1. Web app build is kicked off
  2. All required projects build (already configured, so this is done)
  3. MSBuild "AfterBuild" task kicks off and the output from Project C (Dal Implementation) is copied to the Bin directory of Project A (web app)

Part 3 is where I'm stuck.

I'm sure this can be done, I'm just not finding a good reference to help out. Thanks in advance for any help.

+3  A: 

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.

Andrew Van Slaars
I +1'd this ages ago. As you've suggested this isnt clean - obviously this breaks if the OutDir changes, e.g. when building with TeamBuild. (Just in case others see this and dont realise the shortcomings). See also http://stackoverflow.com/questions/2325598/determining-outputs-of-a-projectreference-in-msbuild/2325620#2325620
Ruben Bartelink
See http://stackoverflow.com/questions/2325598/determining-outputs-of-a-projectreference-in-msbuild/2325620#2325620 for an example of a way of addressing the concern I mentioned
Ruben Bartelink