I have two projects (csproj) that I would like to combine and compile into one assembly, but I would like to continue to have them as separate projects as well. I thought this would be pretty straightforward with MSBuild, but it isn't working like I expected.
A minimal example demonstrating what I was hoping to do is the following:
[Full.proj]
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Proj1/Proj1.proj"/>
<Import Project="Proj2/Proj2.proj"/>
<Target Name="Build">
<Message Text="%(Compile.FullPath)"/>
</Target>
</Project>
Proj1.proj and Proj2.proj look like the following:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Include="Test#.cs"/>
</ItemGroup>
</Project>
So, Full.proj simply Imports both of the other projects which I was hoping would include all of their Compile items into one set, and the standard MSBuild scripts for C# projects would take care of the rest. The problem, is that the Compile item definitions end up being relative to Full.proj rather than relative to the project where they are defined (which surprised me).
Executing MSBuild.exe Full.proj will result in:
C:\users\mpflug\Desktop\msbuildtest\Test1.cs
C:\users\mpflug\Desktop\msbuildtest\Test2.cs
What I was expecting:
C:\users\mpflug\Desktop\msbuildtest\Proj1\Test1.cs
C:\users\mpflug\Desktop\msbuildtest\Proj2\Test2.cs
Is there a straightforward way to accomplish this?