I have a very simple MSBuild script that builds a bunch of .sln files:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Builds all *.sln files under this repository. -->
<ItemGroup>
<SolutionFiles Include="**/*.sln" />
</ItemGroup>
<Target Name="Build">
<MSBuild Projects="@(SolutionFiles)" Targets="Rebuild" />
</Target>
<Target Name="AfterBuild">
<Message Text="After Build" />
</Target>
<Target Name="AfterRebuild">
<Message Text="After Rebuild" />
</Target>
</Project>
The AfterBuild/AfterRebuild targets should do something else, i am just testing them now.
I'd like these targets to fire after every project build, but these are not fired.
Am i doing something wrong?
EDIT: Since each project defines its own AfterBuild target, i guess this way wouldn't really work. I tried placing the AfterBuild and AfterRebuild targets in their own file (custom.targets) and running MSBuild with /p:CustomAfterMicrosoftCommonTargets=custom.targets. This also did not work.
Any suggestions?
You have to add an <Import Project="MyCommon.proj" />
in every Project after the Microsoft.*.targets
.
Because AfterBuild
is defined in Microsoft.*.targets
It's actually documented in every project-file.
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. -->
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
import your custom or common targets like this:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MyBuildRoot)\Common.targets" />
you can even overwrite OutputPath
and IntermediateOutputPath
.
But they have to be imported before Microsoft.CSharp.targets
.
Otherwise they will not correctly processed by targets defined in Microsoft.CSharp.targets
.
<PropertyGroup>
<DocumentationFile></DocumentationFile> <!-- disables xml-doc generate -->
<ProjectRootPath>$(MSBuildThisFileDirectory)</ProjectRootPath>
</PropertyGroup>
<PropertyGroup Condition="$(BuildInOnePlace)!=''">
<BaseIntermediateOutputPath>$(ProjectRootPath)obj/<BaseIntermediateOutputPath>
<BaseOutputPath>$(ProjectRootPath)bin/<BaseOutputPath>
</PropertyGroup>
<PropertyGroup Condition="$(BuildInOnePlace)==''">
<BaseIntermediateOutputPath>obj/<BaseIntermediateOutputPath>
<BaseOutputPath>bin/<BaseOutputPath>
</PropertyGroup>
<PropertyGroup>
<OutputPath>$(BaseOutputPath)$(Configuration)/</OutputPath>
<IntermediateOutputPath>$(BaseOutputPath)$(Configuration)/</IntermediateOutputPath>
</PropertyGroup>
<Target Name="AfterBuild">
<Message Text="$(ProjectName): $(OutputPath)" />
</Target>
...
<Import Project="../Common.props" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="../Common.targets" />
...
...
<Import Project="../Common.props" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="../Common.targets" />
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With