不执行覆盖AfterBuild目标的MSBuild脚本 [英] Overridden AfterBuild target in MSBuild script is not executed

查看:468
本文介绍了不执行覆盖AfterBuild目标的MSBuild脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的MSBuild脚本,它建立了一堆的.sln文件:

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>

在AfterBuild / AfterRebuild目标应该做些别的事情,我只是测试它们了。

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.

我是做错了什么?

编辑:由于每个项目定义了自己的AfterBuild目标,我想这样一来就没有真正的工作。 我试着放置的 AfterBuild AfterRebuild 的目标在自己的文件(custom.targets)和/p:CustomAfterMicrosoftCommonTargets=custom.targets运行的MSBuild 。这还没有工作。

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.

有什么建议?

推荐答案

您必须添加一个&LT;导入项目=MyCommon.proj/&GT; 在每后微软*项目,目标。 因为 AfterBuild 中定义微软。*。目标

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" />

你甚至可以覆盖 OutputPath IntermediateOutputPath 。 但是他们有前 Microsoft.CSharp.targets要导入。 否则,他们将无法正常通过 Microsoft.CSharp.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>

Common.targets

<Target Name="AfterBuild">
  <Message Text="$(ProjectName): $(OutputPath)" />
</Target>

SubProject1 \ SubProject1.csproj

...
<Import Project="../Common.props" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="../Common.targets" />
...

SubProject2 \ SubProject2.csproj

...
<Import Project="../Common.props" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="../Common.targets" />
...

这篇关于不执行覆盖AfterBuild目标的MSBuild脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆