I have the following task in my nant script:
<nunit2 verbose="true">
<formatter type="P开发者_如何学JAVAlain" />
<test assemblyname="${output}\Test.dll" appconfig="${project.src.root}\Test\Test.config"/>
</nunit2>
Test.config is the following:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="Neutral" />
<bindingRedirect oldVersion="2.5.3.9345" newVersion="2.2.8.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I get an error when i run this task saying could not load nunit.framework. I know nunit is not in the GAC (not strongly signed). Does Nunit have to be in the GAC for this task to work?
I provide the path to my NUnit binary during compilation. When I call nunit2, the reference to the framework is present and I don't get this error. Does this help?
<target name="unit.compile" depends="sharedClasses, helpers.compile" description="compiles the unit tests" >
<copy todir="build" flatten="true">
<fileset basedir="tools\NUnit-2.5.2.9222\framework">
<include name="nunit.framework.dll" />
</fileset>
</copy>
<csc target="library" output="build\${project::get-name()}.test.unit.dll" debug="${debug}">
<sources>
<include name="source\web\tests\unit\**\*.cs" />
<exclude name="source\web\tests\unit\**\AssemblyInfo.cs" />
</sources>
<references basedir="build" >
<include name="nunit.framework.dll" />
<include name="Microsoft.Practices.EnterpriseLibrary.Common.dll" />
<include name="Microsoft.Practices.EnterpriseLibrary.Data.dll" />
<include name="${project::get-name()}.sharedClasses.dll" />
<include name="${project::get-name()}.test.helpers.dll" />
</references>
</csc>
</target>
<target name="unit.test" depends="unit.compile, helpers.compile">
<copy file="configuration\Web.Config" tofile="build\${project::get-name()}.test.unit.dll.config" />
<copy file="configuration\ui_list.config" tofile="build\ui_list.test.config" />
<nunit2>
<test
assemblyname="build\${project::get-name()}.test.unit.dll"
appconfig="build\${project::get-name()}.test.unit.dll.config"
/>
<formatter type="Plain" />
</nunit2>
</target>
Set your Nant tasks to show with verbose output (often this means just adding 'verbose=true' to the applicable tasks) and see if you can verify the paths that it's trying to use to reference nunit.framework.dll.
It's very likely that the path to nunit.framework.dll in your project is a relative path that may not work when you try to run the task from NAnt via the command line. (for example, if your .csproj is nested in a folder but your Nant script is not, or if you're moving around the build outputs prior to testing).
精彩评论