5

一連の .sln ファイルをビルドする非常に単純な MSBuild スクリプトがあります。

<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 ターゲットは別の処理を行う必要があります。現在テスト中です。

プロジェクトのビルドごとにこれらのターゲットを起動したいのですが、起動しません。

私は何か間違ったことをしていますか?

編集: 各プロジェクトは独自の AfterBuild ターゲットを定義するため、この方法は実際には機能しないと思います。AfterBuildおよびAfterRebuildターゲットを独自のファイル (custom.targets) に配置し、/ p:CustomAfterMicrosoftCommonTargets =custom.targets で MSBuild を実行してみました。これもうまくいきませんでした。

助言がありますか?

4

1 に答える 1

8

<Import Project="MyCommon.proj" />の後にすべてのプロジェクトでを追加する必要がありMicrosoft.*.targetsます。AfterBuildで定義されているため、Microsoft.*.targets

実際には、すべてのプロジェクト ファイルに文書化されています。

<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 Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MyBuildRoot)\Common.targets" />

OutputPathとを上書きすることもできますIntermediateOutputPath。ただし、前にインポートする必要がありますMicrosoft.CSharp.targets。そうしないと、 で定義されたターゲットによって正しく処理されませんMicrosoft.CSharp.targets

Common.props

<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" />
...
于 2014-01-22T20:21:15.607 に答える