Reputation: 12932
I have a build task that I would like to include into my msbuild script. I would like the CI to compile the Build tasks first before trying to use them so that any new build tasks added would be avalible and the actual assembly would not have to be compile and committed to the CI machine. I tried something like this.
<Target Name="SetupEnv">
<MSBuild Targets="Build" Projects="FooBuildTasks\BuildTasks.sln" />
<UsingTask TaskName="Foo.BarTask" AssemblyFile="$(MSBuildProjectDirectory)\BuildTasks\FooBuildTasks\bin\Release\FooBuildTasks.dll"/>
<BarTask Variable="Test" Value="I'm Alive" />
</Target>
This builds the tasks assembly file but then it seems like the UsingTask task can't be run in a Target.
error MSB4036: The "UsingTask" task was not found. Check the following: 1.) The name of the task in the project file is the sa...
Is there any good solution around this? If I run the UsingTask under Project it works fine if I have precompiled the Tasks assembly before hand.
The msbuild platform used is 3.5
Upvotes: 3
Views: 2701
Reputation: 14164
Set the OutDir
property explicitly:
<MSBuild Targets="Build" Projects="FooBuildTasks\BuildTasks.sln"
Properties="Configuration=Release;OutDir=$(MSBuildProjectDirectory)\BuildTasks\FooBuildTasks\bin\Release\" />
Also, the <UsingTask>
element must be declared outside the <Target>
Upvotes: 4
Reputation: 9938
You need a two step build or use inline tasks. A two-step build involves splitting your build into a "Configure" target that pre-builds your build tasks, and a "CoreBuild" target that performs your build.
Using either technique below you need to ensure that your "Confugure" target does not require any of your custom tasks that are built by it.
1) Use your "Build" target to drive the two step build:
<Target Name="Configure">
<MSBuild Projects="PathTo/CustomBuidTasks.csproj" Target="Build" />
</Target>
<Target Name="CoreBuild">
<MSBuild Projects="@(ItemsToBuild)" Target="Build" />
</Target>
<Target Name="Build">
<MSBuild Projects="$(MSBuildThisFile)" Target="Configure" />
<MSBuild Projects="$(MSBuildThisFile)" Target="CoreBuild" />
</Target>
2) Set up your CI system to perform the two-step build for you, essentually duplicating the above using the CI workflow, first executing MSBuild with the "Configure" target, then separately executing a more traditional "Build" target.
3) Another approach is to use inline tasks in your MSBuild. By putting the task code in the MSBuild file, the engine will compile it for you when the task is first executed.
Excerpted from MSBuild Trickery tricks #6 and #32
Upvotes: 3