Build a C # project with Nant and nunit for the first time

Source: Internet
Author: User
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>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.