2015-09-21 17 views
7

我已經得到了下面的設置(爲簡便起見無趣的XML刪除):通過任務選擇在一個目標產生的ItemGroup文件位置

MyProject.fsproj

<Project ...> 
    <Import Project="MyTask.props" /> 
    ... 
    <ItemGroup> 
    <Compile Include="Program.fs" /> 
    </ItemGroup> 
</Project> 

MyTask.props

<Project ...> 
    <UsingTask XXX.UpdateAssemblyInfo /> 
    <Target Name="UpdateAssemblyInfo" 
      BeforeTargets="CoreCompile"> 
    <UpdateAssemblyInfo ...> 
     <Output 
     TaskParameter="AssemblyInfoTempFilePath" 
     PropertyName="AssemblyInfoTempFilePath" /> 
    </UpdateAssemblyInfo> 

    <ItemGroup> 
     <Compile Include="$(AssemblyInfoTempFilePath)" /> 
    </ItemGroup> 
    </Target> 
</Project> 

的問題是,由MyTask.props添加的ItemGroup添加最後,儘管被進口權在親最開始的JECT。我認爲這是因爲ItemGroup實際上並未導入 - 它是在任務運行時添加的。

在F#中這不是一件好事,因爲文件順序很重要 - 包括構建列表末尾的文件意味着無法構建EXE,例如(因爲入口點必須位於最後一個文件中)。

因此,我的問題 - 有沒有辦法讓我輸出一個ItemGroup作爲目標的一部分,並讓生成的ItemGroup是第一個?

回答

1

有點晚了,但這可能有助於將來的人,我沒有在這個示例中使用導入標籤,但它也會以同樣的方式工作,重要的部分是「UpdateAssemblyInfo」目標,主要思想將使用適當的排序順序清除並重新生成Compile ItemGroup。

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <ItemGroup> 
    <Compile Include="Program.cs" /> 
    <Compile Include="Properties\AssemblyInfo.cs" /> 
    </ItemGroup> 

    <Target Name="Build" DependsOnTargets="UpdateAssemblyInfo"> 

    </Target> 

    <Target Name="UpdateAssemblyInfo"> 
    <!-- Generate your property --> 
    <PropertyGroup> 
     <AssemblyInfoTempFilePath>ABC.xyz</AssemblyInfoTempFilePath> 
    </PropertyGroup> 

    <!-- Copy current Compile ItemGroup to TempCompile --> 
    <ItemGroup> 
     <TempCompile Include="@(Compile)"></TempCompile> 
    </ItemGroup> 

    <!-- Clear the Compile ItemGroup--> 
    <ItemGroup> 
     <Compile Remove="@(Compile)"/> 
    </ItemGroup> 

    <!-- Create the new Compile ItemGroup using the required order -->  
    <ItemGroup> 
     <Compile Include="$(AssemblyInfoTempFilePath)"/> 
     <Compile Include="@(TempCompile)"/> 
    </ItemGroup> 

    <!-- Display the Compile ItemGroup ordered --> 
    <Message Text="Compile %(Compile.Identity)"/> 
    </Target> 
</Project> 
相關問題