Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jsmarble/13421902ba8d9815d1fb to your computer and use it in GitHub Desktop.
Save jsmarble/13421902ba8d9815d1fb to your computer and use it in GitHub Desktop.
After-solution targets file for xUnit.net
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">.\</SolutionDir>
</PropertyGroup>
<PropertyGroup>
<xUnitPackageVersion>2.1.0</xUnitPackageVersion>
<PackageDir>$(SolutionDir)packages\xunit.runner.msbuild.$(xUnitPackageVersion)\</PackageDir>
<NUnitXslFile>$(PackageDir)build\portable-net45+win8+wp8+wpa81\NUnitXml.xslt</NUnitXslFile>
<TestResultFileXUnit>$(SolutionDir)TestResults.xunit.xml</TestResultFileXUnit>
<TestResultFileNUnit>$(SolutionDir)TestResults.nunit.xml</TestResultFileNUnit>
</PropertyGroup>
<PropertyGroup>
<!-- required for solution-level package restore -->
<ProjectDir>$(SolutionDir).nuget</ProjectDir>
<RestorePackages>true</RestorePackages>
<RequireRestoreConsent>false</RequireRestoreConsent>
</PropertyGroup>
<PropertyGroup>
<TestDependsOn>
BeforeTest;
CoreTest;
AfterTest;
</TestDependsOn>
</PropertyGroup>
<UsingTask AssemblyFile="$(PackageDir)build\portable-net45+win8+wp8+wpa81\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit" />
<Target Name="Test" AfterTargets="Build;Rebuild" DependsOnTargets="$(TestDependsOn)" />
<Target Name="BeforeTest" />
<Target Name="AfterTest" />
<Target Name="CoreTest" Inputs="@(CollectedBuildOutput)" Outputs="$(TestResultFileXUnit)">
<ItemGroup>
<TestAssemblies Include="%(CollectedBuildOutput.FullPath)" Condition="$([System.Text.RegularExpressions.Regex]::IsMatch(%(FullPath), '(?i:\.Tests\.dll)$'))"/>
</ItemGroup>
<xunit Assemblies="@(TestAssemblies)" Xml="$(TestResultFileXUnit)" />
<XslTransformation XmlInputPaths="$(TestResultFileXUnit)" XslInputPath="$(NUnitXslFile)" OutputPaths="$(TestResultFileNUnit)" />
</Target>
<Target Name="TestClean" BeforeTargets="Clean;Build;Rebuild">
<Delete Files="$(TestResultFileXUnit)" />
<Delete Files="$(TestResultFileNUnit)" />
</Target>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="Test">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(PackageDir)build\portable-net45+win8+wp8+wpa81\xunit.runner.msbuild.dll')" Text="$([System.String]::Format('$(ErrorText)', '$(PackageDir)build\portable-net45+win8+wp8+wpa81\xunit.runner.msbuild.dll'))" />
<Error Condition="!Exists('$(PackageDir)build\portable-net45+win8+wp8+wpa81\NUnitXml.xslt')" Text="$([System.String]::Format('$(ErrorText)', '$(PackageDir)build\portable-net45+win8+wp8+wpa81\NUnitXml.xslt'))" />
</Target>
</Project>
@jsmarble
Copy link
Author

I forked this and updated to work with xUnit 2.1.0 and the new nuget package for xunit.runner.msbuild. I also made a couple tweaks to the targets, opting to keep both the nunit and xunit xml files, and also to delete them even for normal builds. With the nuget changes, it was no longer necessary to validate the existence of NuGet.targets.

This works for me on Bamboo, otherwise following the instructions of the author from http://www.northcloud.com/integrating-xunit-net-into-bamboo-build-plans-with-msbuild/. Thanks @coldacid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment