我们最近从MSBuild 2005升级到2008.从那时起,MSBuild在构建解决方案时停止了第一个错误。 2005年的情况并非如此。 有没有办法解决旧行为?
编辑:我们从命令行调用MSBuild:
MSBuild.exe xyz.sln /p:Platform=Win32 /p:Configuration=Debug
答案 0 :(得分:4)
<MSBuild Projects="@(Solution)" ContinueOnError="false" StopOnFirstFailure="true"></MSBuild>
您必须在脚本
上更改此设置答案 1 :(得分:1)
我有一种有点复杂的解决方案,但它有效:
使用解决方案文件调用MSBuild时,它会在内部从该解决方案生成项目文件并构建该项目文件。将环境变量msbuildemitsolution设置为1时,它会将该项目文件输出到名为解决方案文件的硬盘上,但后跟.proj。 此外,它始终生成.cache文件,以防止它始终重新生成项目文件。 所以我先做的是:
IF EXIST xyz.sln.proj DEL xyz.sln.proj
IF EXIST xyz.sln.cache DEL xyz.sln.cache
SET msbuildemitsolution=1
MSBuild.exe xyz-sln /t:_xxxxx_ /noconsolelogger
目标 xxxx 不应存在的位置。然后MSBuild生成一个xyz.sln.proj并输出许多错误,因为缺少目标。我忽略了错误,因为我想要的是项目文件。 实际上我在C#程序中执行上述操作但为了更容易理解,我在这里选择了BAT语法。
xyz.sln.proj由许多目标组成:“Build”,“Clean”,“Rebuild”和“Publish”和“”,“:Clean”,“:Rebuild”,“:Publish”,“” ... 我感兴趣的只是“Build”,“Rebuild”和“Clean”的目标。 这些目标包含几个构建csproj文件集的MSBuild任务。这些集合称为BuildLevelX(其中X是数字)。对于C ++项目,Build / Rebuild / Clean目标包含直接调用任务的CallTarget任务。 我文件中的一个片段:
<Target Name="Build" Condition="'$(CurrentSolutionConfigurationContents)' != ''" Outputs="@(CollectedBuildOutput)">
<MSBuild Condition="@(BuildLevel0) != ''" Projects="@(BuildLevel0)" Properties="Configuration=%(Configuration); Platform=%(Platform); BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="true" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" ContinueOnError="true">
<Output TaskParameter="TargetOutputs" ItemName="CollectedBuildOutput" />
</MSBuild>
<Message Text="The project "%(SkipLevel0.Identity)" is not selected for building in solution configuration "$(Configuration)|$(Platform)"." Condition="@(SkipLevel0) != ''" />
<Warning Text="The project configuration for project "%(MissingConfigLevel0.Identity)" was not specified in the solution file for the solution configuration "$(Configuration)|$(Platform)"." Code="MSB4121" HelpKeyword="MSBuild.SolutionProjectConfigurationMissing" Condition="@(MissingConfigLevel0) != ''" />
<MSBuild Condition="@(BuildLevel1) != ''" Projects="@(BuildLevel1)" Properties="Configuration=%(Configuration); Platform=%(Platform); BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="true" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" ContinueOnError="true">
<Output TaskParameter="TargetOutputs" ItemName="CollectedBuildOutput" />
</MSBuild>
<Message Text="The project "%(SkipLevel1.Identity)" is not selected for building in solution configuration "$(Configuration)|$(Platform)"." Condition="@(SkipLevel1) != ''" />
<Warning Text="The project configuration for project "%(MissingConfigLevel1.Identity)" was not specified in the solution file for the solution configuration "$(Configuration)|$(Platform)"." Code="MSB4121" HelpKeyword="MSBuild.SolutionProjectConfigurationMissing" Condition="@(MissingConfigLevel1) != ''" />
<CallTarget Targets="SomeLib" RunEachTargetSeparately="true" ContinueOnError="true" />
<MSBuild Condition="@(BuildLevel2) != ''" Projects="@(BuildLevel2)" Properties="Configuration=%(Configuration); Platform=%(Platform); BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="true" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" ContinueOnError="true">
<Output TaskParameter="TargetOutputs" ItemName="CollectedBuildOutput" />
</MSBuild>
<Message Text="The project "%(SkipLevel2.Identity)" is not selected for building in solution configuration "$(Configuration)|$(Platform)"." Condition="@(SkipLevel2) != ''" />
<Warning Text="The project configuration for project "%(MissingConfigLevel2.Identity)" was not specified in the solution file for the solution configuration "$(Configuration)|$(Platform)"." Code="MSB4121" HelpKeyword="MSBuild.SolutionProjectConfigurationMissing" Condition="@(MissingConfigLevel2) != ''" />
<CallTarget Targets="SomeProgram" RunEachTargetSeparately="true" ContinueOnError="true" />
<MSBuild Condition="@(BuildLevel3) != ''" Projects="@(BuildLevel3)" Properties="Configuration=%(Configuration); Platform=%(Platform); BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="true" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" ContinueOnError="true">
<Output TaskParameter="TargetOutputs" ItemName="CollectedBuildOutput" />
</MSBuild>
<Message Text="The project "%(SkipLevel3.Identity)" is not selected for building in solution configuration "$(Configuration)|$(Platform)"." Condition="@(SkipLevel3) != ''" />
<Warning Text="The project configuration for project "%(MissingConfigLevel3.Identity)" was not specified in the solution file for the solution configuration "$(Configuration)|$(Platform)"." Code="MSB4121" HelpKeyword="MSBuild.SolutionProjectConfigurationMissing" Condition="@(MissingConfigLevel3) != ''" />
<MSBuild Condition="@(BuildLevel4) != ''" Projects="@(BuildLevel4)" Properties="Configuration=%(Configuration); Platform=%(Platform); BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="true" UnloadProjectsOnCompletion="$(UnloadProjectsOnCompletion)" UseResultsCache="$(UseResultsCache)" ContinueOnError="true">
<Output TaskParameter="TargetOutputs" ItemName="CollectedBuildOutput" />
</MSBuild>
<Message Text="The project "%(SkipLevel4.Identity)" is not selected for building in solution configuration "$(Configuration)|$(Platform)"." Condition="@(SkipLevel4) != ''" />
<Warning Text="The project configuration for project "%(MissingConfigLevel4.Identity)" was not specified in the solution file for the solution configuration "$(Configuration)|$(Platform)"." Code="MSB4121" HelpKeyword="MSBuild.SolutionProjectConfigurationMissing" Condition="@(MissingConfigLevel4) != ''" />
</Target>
我加载proj文件并将ContinueOnError =“true”添加到Build / Rebuild / Clean目标中的所有MSBuild和CallTarget任务:
XmlDocument msBuildProject = new XmlDocument();
msBuildProject.Load(Tools.getFullPath(m_strBaseDir, strSolutionProjFile));
foreach (XmlNode nodeL0 in msBuildProject.ChildNodes)
{
XmlElement elementL0 = nodeL0 as XmlElement;
if ((elementL0 != null) && (String.CompareOrdinal(nodeL0.Name, "Project") == 0))
{
foreach (XmlNode nodeL1 in elementL0.ChildNodes)
{
XmlElement elementL1 = nodeL1 as XmlElement;
if ((elementL1 != null) && (String.CompareOrdinal(nodeL1.Name, "Target") == 0))
{
if ((String.CompareOrdinal(elementL1.Attributes["Name"].Value, "Build") == 0) ||
(String.CompareOrdinal(elementL1.Attributes["Name"].Value, "Rebuild") == 0) ||
(String.CompareOrdinal(elementL1.Attributes["Name"].Value, "Clean") == 0) ||
(String.CompareOrdinal(elementL1.Attributes["Name"].Value, "Publish") == 0))
{
foreach (XmlNode nodeL2 in elementL1.ChildNodes)
{
XmlElement elementL2 = nodeL2 as XmlElement;
if ((elementL2 != null) &&
((String.CompareOrdinal(nodeL2.Name, "MSBuild") == 0) ||
(String.CompareOrdinal(nodeL2.Name, "CallTarget") == 0)))
{
elementL2.SetAttribute("ContinueOnError", "true");
}
}
}
}
}
}
}
msBuildProject.Save(Tools.getFullPath(m_strBaseDir, strSolutionProjFile));
之后,我使用配置调用MSBuild。
这很好但是因为它不是很容易我永远不会将其标记为我的问题的答案: - )