2012-01-24 25 views
1

私は以下のMSBuildターゲットを使用しています。MSBuild - ItemGroupを別ファイルに保存

<Target Name="MyTarget"> 
    <ItemGroup> 
     <ExcludeList Include="$(ProjectPath)\**\.svn\**"/> 
     <ExcludeList Include="$(ProjectPath)\**\obj\**"/> 
     <ExcludeList Include="$(ProjectPath)\**\*.config"/> 
     <ExcludeList Include="$(ProjectPath)\**\*.cs"/> 
     <ExcludeList Include="$(ProjectPath)\**\*.csproj"/> 
     <ExcludeList Include="$(ProjectPath)\**\*.user"/> 
    </ItemGroup> 

    <ItemGroup> 
     <ZipFiles Include="$(ProjectPath)\**\*.*" Exclude="@(ExcludeList)" /> 
    </ItemGroup> 

    <Zip Files="@(ZipFiles)" 
     WorkingDirectory="$(ProjectPath)" 
     ZipFileName="$(PackageDirectory)\$(ProjectName).package.zip" 
     ZipLevel="9" /> 
</Target> 

私はすべてがそのリストを使用する必要が別々のファイルで複数のMSBuildの目標を持つことになりますので、私は、別のファイルにExcludeList ItemGroupを保存したいのですが、私はそれを再作成し、維持する必要はありません複数のコピー。

ItemGroupを外部化し、複数のmsbuildスクリプトにロードする最も良い方法は何ですか?

答えて

2

ItemGroupを別のmsbuildファイルに作成してから、Import Element文で含めることができます。

Make.targets

<Project DefaultTargets = "Build" 
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003" > 
    <ItemGroup Condition="'$(ProjectPath)' != ''"> 
     <ExcludeList Include="$(ProjectPath)\**\.svn\**"/> 
     <ExcludeList Include="$(ProjectPath)\**\obj\**"/> 
     <ExcludeList Include="$(ProjectPath)\**\*.config"/> 
     <ExcludeList Include="$(ProjectPath)\**\*.cs"/> 
     <ExcludeList Include="$(ProjectPath)\**\*.csproj"/> 
     <ExcludeList Include="$(ProjectPath)\**\*.user"/> 
     <ExcludeList Include="$(ProjectPath)\**\*.proj"/> 
    </ItemGroup> 
</Project> 

Make.proj

<Project DefaultTargets = "Build" 
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003" > 

    <PropertyGroup> 
     <ProjectPath>D:\Temp</ProjectPath> 
    </PropertyGroup> 

    <Import Project=".\Make.targets" Condition="'$(ProjectPath)' != ''" /> 

    <Target Name = "Build"> 
     <Message Text="Exclude = @(ExcludeList)" /> 
    </Target> 
</Project> 

私はDからのMSBuildを実行すると:(そうでない場合は二つのファイルと、空の)\ tempに私が取得:

Build started 24-01-2012 16:50:33. 
Project "D:\Temp\Make.proj" on node 1 (default targets). 
Build: 
    Exclude = D:\Temp\Make.proj 
Done Building Project "D:\Temp\Make.proj" (default targets). 


Build succeeded. 
    0 Warning(s) 
    0 Error(s) 
+0

@ Hussom私はそれを試みた。 ItemGroup要素を別のファイルに移動してからImportを使用すると、元のターゲットからExcludeListプロパティが空になりました。あなたの答えに現役のサンプルを含めることができますか? – RationalGeek

+0

@ Hussomありがとう。そのサンプルは私のために働く。今では私の実際のスクリプトではうまくいかない理由を理解するために... – RationalGeek

+0

Projectアトリビュートで正しいパスが指定されていますか? – Huusom

関連する問題