How to build a dependent project first with msbuild
I just started learning msbuild because I want to create my own build scripts. At the moment I can create build scripts that only compile one project, but how do I handle dependencies?
For example, what if I have two projects that are building with these two msbuild scripts?
- projectA.xml
- projectB.xml
How do I tell msbuild that when I execute projectB.xml it should execute projectA.xml first?
I have a lot for this, but it seems that he does not understand anything, as a beginner understands like me. I would be more than happy with a link to an article describing this, or maybe just a small sample code.
The reason I want this control is because of the library I am building. The library consists of several projects. The developer should be able to pull out the source code of the library and create only those libraries that he needs.
Actually I want to be able to create .net modules from different projects. This is why I want to be able to run a customized msbuild script.
source to share
I'm setting up build scripts so I have a few general targets that don't do anything, but use DependsOnTargets to set up project dependencies and run the build.
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- ************************************************************************************************ -->
<!-- Targets that run the builds -->
<!-- ************************************************************************************************ -->
<Target Name="AutoBuild" DependsOnTargets="BuildProject1;BuildProject2;BuildInstallers">
<OnError ExecuteTargets="NotifyFailure" />
</Target>
<Target Name="FullCompile" DependsOnTargets="BuildProject1;BuildProject2">
<OnError ExecuteTargets="NotifyFailure" />
</Target>
<!-- Build Project 1 -->
<Target Name="BuildProject1">
<!-- Use MSBuild task and point it to build project1.csproj, project1.sln or whatever your projects is -->
</Target>
<!-- Build Project 2 -->
<Target Name="BuildProject2">
<!-- Use MSBuild task and point it to build project2.csproj, project2.sln or whatever your projects is -->
</Target>
<Target Name="BuildInstallers">
<!-- Whatever logic you have for building installers -->
</Target>
</Project>
source to share
If you are building a solution with two projects, you can target the .sln file to msbuild rather than build projects directly, it should take care of the project dependencies :)
But if you are using standard .csproj projects ...
Ok, I looked at the project I'm working on and like this:
<ItemGroup>
<ProjectReference Include="..\SomeFolder\SomeProject.csproj">
<Project>{1A94B405-2D01-4A09-90D5-A5B31180A03B}</Project>
<Name>SomeProjectNamespace</Name>
</ProjectReference>
</ItemGroup>
source to share