I recently wanted to create a dependency between two projects, so that I could control the build order. I knew how to do this easily through the solution by going to "Right click solution < Properties < Project Dependencies". Here you would see something like the following:
In the above I can make a build dependency between project A and project B. So before project A is built project B has to be built. This makes no changes to the project files and is entirely on solution level. So the projects will have no references between them. But when building your solution msbuild will follow the dependencies that you have made.
Without creating dependencies through the solution
However what I wanted was to do the above without using the solution. I would like to have the dependency directly between the projects. I could just create a normal reference, however there was no need for the DLL (binary) to be copied. So I found the following solution instead, where I had to meddle with the csproj files. Here is what I have done:
<ItemGroup>
<ProjectReference Include="..\DependencyTest\ProjectA.csproj">
<Project>{2f5b7c30-e921-4ed4-ba05-266fe3e85a20}</Project>
<Name>ProjectA</Name>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>
The above is what is auto generated by visual studio when referencing another project - except for <ReferenceOutputAssembly>
. This is something I have added to avoid referencing the output DLL of Project A. Now I have a reference between project B and project A without copying the Project A DLL file.
Both solutions have their merits and flaws. The first one has a great UI to do this and through this you can easily create an overview of dependencies. The latter one is very much hidden. Future developers on your project may wonder why they cannot make this DLL show up in the output folder. However if you target your projects directly (not targeting a solution) with msbuild the second solution is the only one that will work.
I hope this helps someone, let me know if it did :) Comments are appreciated.