我需要将一系列步骤捆绑在一起,包括使用自定义MSBuild文件构建解决方案,项目和运行.cmd文件。
我的第一篇文章如下:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</PropertyGroup>
<ItemGroup>
<ProjectsToBuild Include="..\Hosts\solution1.sln"></ProjectsToBuild>
<ProjectsToBuild Include="..\..\solution2.sln"></ProjectsToBuild>
<ProjectsToBuild Include="helper1.csproj"></ProjectsToBuild>
<ProjectsToBuild Include="..\..\Sandboxes\helper2.sln"></ProjectsToBuild>
<Exec Include="" Command="CALL GetFiles.cmd"/>
<ProjectsToBuild Include="wix\proc\prod.wixproj"></ProjectsToBuild>
<Exec Command="CALL final.cmd"/>
</ItemGroup>
<Target Name="Build">
<MSBuild Projects="@(ProjectsToBuild)" Targets="Build">
<Output ItemName="ProjectOutputs" TaskParameter="TargetOutputs"/>
</MSBuild>
<Message Text="@ProjectOutputs"/>
</Target>
</Project>
由于Exec元素位于错误的位置,因此导致错误。
基本上,我需要构建solution1.sln,solution2.sln,helper1.csproj和helper2.sln(按顺序),然后运行文件GetFiles.cmd,然后构建prod.wixproj,然后运行final.cmd文件。
我查看了MSDN(here,here,here),a blog,并浏览了各种stackoverflow问题(包括this,{{ 3}},this,this),但它们都没有完全解决我想要做的事情。这是我第一次使用MSBuild,所以我可能错过了一些东西。会欣赏任何指示...
答案 0 :(得分:2)
由于ItemGroup节点可以是Target节点的子节点,因此将这些ItemGroup成员分解为单独的目标,然后使用DefaultTargets属性来控制构建这些节点的顺序。
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Target1;Target2;Target3" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5" >
<Target Name="Target1">
<Message Text="Target 1" />
</Target>
<Target Name="Target2">
<Message Text="Target 2" />
</Target>
<Target Name="Target3">
<Message Text="Target 3" />
</Target>
</Project>
答案 1 :(得分:1)
构建项目已按正确顺序查看:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</PropertyGroup>
<ItemGroup>
<ProjectsToBuild Include="..\Hosts\solution1.sln"></ProjectsToBuild>
<ProjectsToBuild Include="..\..\solution2.sln"></ProjectsToBuild>
<ProjectsToBuild Include="helper1.csproj"></ProjectsToBuild>
<ProjectsToBuild Include="..\..\Sandboxes\helper2.sln"></ProjectsToBuild>
<ProjectsToBuild Include="wix\proc\prod.wixproj"></ProjectsToBuild>
</ItemGroup>
<Target Name="Build">
<Exec Command="CALL GetFiles.cmd"/>
<Message Text="Build order: %(ProjectsToBuild.Identity)"/>
<MSBuild Projects="@(ProjectsToBuild)" Targets="Build">
<Output ItemName="ProjectOutputs" TaskParameter="TargetOutputs"/>
</MSBuild>
<Message Text="@(ProjectOutputs)"/>
<<Exec Command="CALL final.cmd"/>
</Target>
</Project>
在开始时,会显示项目组的顺序:
节点1上的项目“C:\ Test \ Testcode \ build \ testcode.msbuild”(默认目标)。
构建
构建顺序:.. \ Hosts \ solution1.sln
构建顺序:.... \ solution2.sln
构建顺序:helper1.csproj
构建顺序:.... \ Sandboxes \ helper2.sln
构建顺序:wix \ proc \ prod.wixproj
全部完成。