【问题标题】:Emulate Devenv/Runexit under MSBuild在 MSBuild 下模拟 Devenv/Runexit
【发布时间】:2015-06-19 19:54:25
【问题描述】:

我是 MSBuild 新手,忙于 Visual Studio 解决方案的自动化测试。

我之前使用过Devenv 的命令行,它提供了一种方便的/Runexit 操作模式。来自手册:

/Runexit (devenv.exe)  
Compiles and runs the specified solution, minimizes the IDE when the solution is run,
and closes the IDE after the solution has finished running. 

这正是我需要的功能。我现在正在迁移到 MSBuild。我发现解决方案中的项目文件可以直接用于构建,因为默认的目标正是构建。

我可以做些什么来处理不同的目标,这将与/Runexit 具有相同的效果?你能帮我穿过迷宫吗?

【问题讨论】:

  • 究竟有什么不同的目标?假设您运行测试的目标是Test,那么您将运行msbuild /t:Rebuild;Test 先重建然后测试..
  • @stijn 我的问题正是如何创建一个将执行构建结果的目标,即Test.exe。项目文件中默认没有这样的target。

标签: visual-studio msbuild build-automation


【解决方案1】:

这是运行项目输出文件的最基本目标:

<Target Name="RunTarget">
  <Exec Command="$(TargetPath)" />
</Target>

对于 c++ 单元测试,我使用类似这样的东西;它是一个属性表,因此无需手动修改即可轻松添加到任何项目中。它会在构建后自动运行输出,因此无需指定额外的目标,它对 VS 和命令行的工作方式相同。此外,在 VS 中,您会立即在错误列表中显示来自 Unittest++ 或 Catch 等框架的单元测试错误,因此您可以双击它们。此外,UnitTestExtraPath 属性可以设置在其他地方以防万一(例如,在构建服务器上,我们总是希望保持 PATH 干净,但有时我们确实需要对其进行修改以运行构建的 exe)。

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup />
  <ItemGroup />
  <!--Used to be AfterTargets="AfterBuild", but that is unusable since a failing test marks the build as unsuccessful,
      but in a way that VS will always try to build again. As a consequence debugging in VS is impossible since
      VS will build the project before starting the debugger but building fails time and time again.-->
  <Target Name="RunUnitTests" AfterTargets="FinalizeBuildStatus">
    <Exec Condition="$(UnitTestExtraPath)!=''" Command="(set PATH=&quot;%PATH%&quot;;$(UnitTestExtraPath)) &amp; $(TargetPath)" />
    <Exec Condition="$(UnitTestExtraPath)==''" Command="$(TargetPath)" />
  </Target>
</Project>

【讨论】:

  • 现在工作。你让我开心,谢谢。我必须添加一个WorkingDirectory 属性和拼写完全像&lt;Target Name="RunTarget"&gt; &lt;Exec Command='"$(TargetPath)"' WorkingDirectory="$(ProjectDir)" /&gt; &lt;/Target&gt;
猜你喜欢
  • 2011-01-28
  • 2011-05-10
  • 1970-01-01
  • 2023-03-30
  • 2014-09-16
  • 1970-01-01
  • 1970-01-01
  • 2011-03-03
  • 1970-01-01
相关资源
最近更新 更多