我试图让 TeamCity 在构建过程中运行 XUnit 测试。所以我创建了一个单独的文件 - MyProject.msbuild - 与 .sln 文件位于同一文件夹中,如下所示:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\bin\xunit.net\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit"
/>
<Target Name="Build">
<MSBuild Projects="MyProject.sln" Targets="Build" Properties="Configuration=Release">
<xunit Assembly="MyProject.Utility.Tests\bin\Release\MyProject.Utility.Tests.dll" />
</MSBuild>
</Target>
</Project>
但是,无论我做什么,VS2010 都讨厌我在元素中包含元素。如果我在文件上运行 MSBuild,它会告诉我更多信息:
P:\MyProject\src>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe MyProject.msbuild /tv:4.0 /v:d
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.225]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 08.11.2011 21:08:46.
Project "P:\MyProject\src\MyProject.msbuild" on node 1 (default targets).
Building with tools version "4.0".
P:\MyProject\src\MyProject.msbuild(8,9): error MSB4067: The element <xunit> beneath element <MSBuild> is unrecognized.
Done Building Project "P:\MyProject\src\MyProject.msbuild" (default targets) -- FAILED.
Build FAILED.
"P:\MyProject\src\MyProject.msbuild" (default target) (1) ->
P:\MyProject\src\MyProject.msbuild(8,9): error MSB4067: The element <xunit> beneath element <MSBuild> is unrecognized.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.01
所以我目前的猜测是它没有以某种方式成功加载 xunit.runner.msbuild.dll - 或者我做了其他奇怪的事情。
但是,我认为如果它无法加载 xunit.runner.msbuild.dll,它会告诉我这件事。我确保该文件未被阻止(通过使用 7zip 解压缩 xunit 发行版)。
有什么想法可以让 MSBuild 吞下我的构建文件并运行测试吗?