Tip:
First things first. Up to this point we've been talking about CC.NET Tasks. Now we are introducing the concept of MSBuild Tasks. They are not the same thing.
What I needed was an article on running NUnits via MSBuild.
Their example contains an xml file that looks like:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Import the MSBuild Tasks -->
<Import
Project
="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<ClassLibraryOutputDirectory>
bin\$(Configuration)
</ClassLibraryOutputDirectory>
<ProjectDir>ProjectName</ProjectDir >
<ProjectTestDir>ProjectNameTest</ProjectTestDir >
<ProjectFile>$(ProjectDir)\ProjectName.csproj</ProjectFile >
<TestProjectFile>$(ProjectTestDir)\ProjectNameTest.csproj</TestProjectFile >
</PropertyGroup>
<!-- Build projects by calling the Project files generated by VS -->
<Target Name="Build">
<MSBuild Projects="$(ProjectFile)" />
<MSBuild Projects="$(TestProjectFile)" />
</Target>
<!-- Run Unit tests -->
<Target Name="Test" DependsOnTargets="Build">
<CreateItem
Include="$(ProjectTestDir)\$(ClassLibraryOutputDirectory)\*.Tests.dll">
<Output TaskParameter="Include" ItemName="TestAssembly" />
</CreateItem>
<NUnit Assemblies="@(TestAssembly)" />
</Target>
</Project>
The only problem is -- its completely gibberish to me considering that I've never tangled with using MSBuild before.
So after several false starts (MSDN is complete, but not the greatest place to start if you want to understand it), I found this decent tutorial
which got me well on my way, and after digesting the tutorial, as well as this blog entry and trying a couple of variations, I ended up with ...
{TODO}
Tip:
You should definitely read those articles before continuing.
Download the MSBuild community extensions
The articles were saying that you could do a lot with just MSBuild, but why do things the hard way, so download and install the Community Tasks (that you can find here) first before continuing.
So, by now, I've created and custom xml *.build file that imports the community dll, and invokes it.
Note:
I want to re-emphasis that this *.build file has nothing to do with CC.NET at present, and you should not be using CC.NET to test it.
You should be working it out from a command prompt on your local computer, until you get it right...
Creating an MSBuild xml file: Solving Errors:
But running it gives me another error.
D:\SYS\PROFILES\S\DESKTOP\NETLIB_EXPORTED\Drawing\DoubleBuffer\trunk\CODE\proje
ct.build(56,5):
error MSB6003: The specified task executable could not be run.
The system cannot find the file specified Done
Building Project
"D:\SYS\PROFILES\S\DESKTOP\NETLIB_EXPORTED\
Drawing\Double Buffer\trunk\CODE\project.build"
(tests target(s)) -- FAILED.
Slowing down, looking carefully at the error message one can see a reference to task executable.
After scratching my head, and a little bit of messing around, I realize it was choking on the <i>specified</i>
NUnit custom Task that was specified in the imported dll...
I found the solution to that problem here, and basically stated that I had to point to the specific NUnit directory manually, using the ToolPath attribute:
<!-- VERY IMPORTANT:
Import the MSBuild Community Extension pre-defined Tasks
or Nunit testing won't work:
-->
<Import
Project
="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<!-- Run Unit tests -->
<Target Name="Tests" DependsOnTargets="Build">
<!-- Import all the NUnit Test dlls from the test dir, filtered by Name -->
<Message
Text="*** Import Test Assemblies: $(TestsOutputDir)\$(TestsNameFilter)" />
<CreateItem Include="$(TestsOutputDir)\$(TestsNameFilter)">
<Output ItemName="Tests" TaskParameter="Include" />
</CreateItem>
<Message Text="*** NUnit tests beginning..." />
<NUnit
Assemblies="Tests"
ContinueOnError="false"
OutputXmlFile="C:\Dump.xml"
ToolPath="c:\Program Files\NUnit 2.4.3\bin"
/>
<Message Text="*** NUnit tests ended." />
</Target>
Creating an MSBuild xml file: Solving Errors:"MSBuild.Community.Tasks.Targets was not found"
If you get the following error:
D:\SYS\PROFILES\S\DESKTOP\NETLIB_EXPORTED\Drawing\DoubleBuffer\trunk\CODE\proje
ct.build(27,12): error MSB4019: The imported project "C:\Program Files\MSBuild\
MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" was not found. Confirm
that the path in the <Import> declaration is correct, and that the file exists
on disk.
it's going to be because your include statement isn't working.
Maybe you didn't download the extension from the site?
Creating an MSBuild xml file: Solving Errors:NUnit finally runs, but "Unable to find fixture"
If you get the following error:
Tests:
*** IMPORT: TESTS\NUnitTests\bin\Debug
*** Ready to NUnit on 'TESTS\NUnitTests\bin\Debug'
Unable to locate fixture
...
error MSB6006: "nunit-console.exe" exited with code -3.
...
It will be because of one of two things (hopefully).
First of all, the dll's fixtures have to be <i>public</i> classes, with <i>public</i> methods that return voids such as this:
namespace NUnitTests {
[TestFixture(Description = "Some Fixture")]
public class NUnitsTest1 {
[Test(Description="Simple test to check we're up and running...")]
public void TestFromDll() {
string s = "Boo";
Assert.IsTrue(s.Length == 3);
}
}
}
Don't fret -- its a common mistake...I do it all the time unfortunately...
Ok. And if you have verified that you don't have that common error,
there's still one last thing...I made a mistake. Look at the code
<!-- VERY IMPORTANT:
Import the MSBuild Community Extension pre-defined Tasks
or Nunit testing won't work:
-->
<
Import
Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<!-- Run Unit tests -->
<Target Name="Tests" DependsOnTargets="Build">
<!-- Import all the NUnit Test dlls from the test dir, filtered by Name -->
<Message
Text="*** Import Test Assemblies: $(TestsOutputDir)\$(TestsNameFilter)" />
<CreateItem Include="$(TestsOutputDir)\$(TestsNameFilter)">
<Output ItemName="Tests" TaskParameter="Include" />
</CreateItem>
<Message Text="*** NUnit tests beginning..." />
<NUnit
Assemblies="Tests"
ContinueOnError="false"
OutputXmlFile="C:\Dump.xml"
ToolPath="c:\Program Files\NUnit 2.4.3\bin"
/>
<Message Text="*** NUnit tests ended." />
</Target>
My mistake is in how NUnit/Assemblies is referring to the CreateItem/Output tag.
It shouldn't be Tests, nor $(Tests), but @(Tests)
<NUnit
Assemblies="Tests"
ContinueOnError="false"
OutputXmlFile="C:\Dump.xml"
ToolPath="c:\Program Files\NUnit 2.4.3\bin"
/>
Once you have that, your MSBuild file works!
So, returning to CC.NET we can modify the project tag to point not to the original *.sln file, but our custom *.build xml file that points to the *.sln file. Got that? Once we've done that we can try again...
{TODO/BLOG GETTING TOO LONG AND HAVE TO FINISH THIS ANOTHER TIME}
Running CC.NET and Fixing Errors: View Statistics link failing
I also was getting an error every time I clicked the "View Statistics" link:
Unable to execute transform: ...webdashboard\xsl\statistics.xsl...etc...etc...
...
According to this <a href="http://groups.google.co.il/group/ccnet-user/browse_thread/thread/9d70968c13442c36">post</a>
All that this really meant is that i hadn't setup any statistical information.
One quick solution was to read up on the
element and do the following maneuver (which is the simplest):
<cruisecontrol>
...
<project>
...
<publishers>
<!--default statistics for capturing during the build process.-->
<statistics />
</publishers>
</project>
</cruisecontrol>
That suddenly caused CruiseControl.NET to spit out a correct page....
Running CC.NET and Fixing Errors: Fitness Report Link failing
Exception Message
XSL stylesheet file not found: E:\CruiseControl.NET\webdashboard\xsl\FitnesseReport.xsl
I didn't find a solution, but the documentation had an intriguing note was found here.