I have never used Nant and nunit to build C # code automatically. Today I wrote a C # program and want to build C # code with Nant and nunit. You may have trouble running unittest after writing the Build File. The command line prompts: cocould not load file or assembly 'nunit. framework, version = 2.4.3.0, culture = neutral, publickeytoken = 96d09a1eb7f44a77 'or one of its dependencies. the system cannot find the file specified.
I checked the information to solve the problem.
Solution:
1. Add the following code to the config file of the Program (if the program name is money. dll, the file name is money. dll. config:
<? 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.0.6.0" newversion = "2.4.3.0"/>
<Bindingredirect oldversion = "2.1.4.0" newversion = "2.4.3.0"/>
</Dependentassembly>
</Assemblybinding>
</Runtime>
</Configuration>
2. Use gacutil provided by vs2005 to register Nant. Core. dll and Nant. Framework. dll. The specific method is:
1. Run Visual Studio 2005 command prompt with vs in the window Start Menu.
2. Switch to the bin directory of nunit
3. Run the following commands in sequence: gacutil/I nunit. Core. dll // register the core
Gacutil/I nunit. Framework. dll // register the framework
Gacutil/L // check whether it is registered
Iii. Success.
Now it's all about running Nant unittest.
The Build File with Nant is as follows:
<? XML version = "1.0"?>
<Project name = "csharpmoney" default = "ut">
<Property name = "output. dir" value = "../bin"/>
<Property name = "output. dll" value = "../bin/cs-money.dll"/>
<Property name = "reports. dir" value = "../reports"/>
<Target name = "clean">
<Delete dir = "$ {output. dir}"/>
<Delete dir = "$ {reports. dir}"/>
</Target>
<Target name = "copyfile" depends = "clean">
<Mkdir dir = "$ {output. dir}" Unless = "$ {Directory: exists (output. DIR)}"/>
<Copy file = "../nunit/bin/nunit. Framework. dll" todir = "$ {output. dir }"
If = "$ {file: exists ('nunit/bin/nunit. Framework. dll ')}"/>
</Target>
<Target name = "build" depends = "copyfile">
<CSC target = "library" output = "$ {output. dll}" DEBUG = "true">
<Sources>
<Include name = "*. cs"/>
</Sources>
<References>
<Include name = "../nunit/bin/nunit. Framework. dll"/>
</References>
</CSC>
</Target>
<Target name = "ut" depends = "build">
<Mkdir dir = "$ {reports. dir}"/>
<Exec program = ".. nunit unit-console.exe">
<Arg value = "$ {output. dll}"/>
<Arg value = "/Config = cs-money.dll.config"/>
<Arg value = "/XML =$ {reports. dir} TestReport-Unit.xml"/>
<Arg value = "/nologo"/>
<Arg value = "/noshadow"/>
</Exec>
</Target>
</Project>