asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Using Open Source .NET Tools for Sophisticated Builds -- Cont'd
By Aaron Junod


  • email this article to a colleague
  • suggest an article

    Build a Program Solution


    Now that the build environment is setup, there needs to be something to build. We will first create a WinForms application, as well as a class library. I chose to use C# for this example because XML commenting is built into the language. For those using VB .NET, there are some packages that can help. Look into VBCommenter and VB.DOC.

    Use a consistent naming system where all solutions are in the c:\projects directory and each project is in its own directory within the solution directory. This would result in a file structure similar to

    C |
       ---Projects|
    	--- Solution|
    		--- Project1|
    		--- Project2|
    
    Create Solution

    1. Open up VS .NET and create a new solution named BuildingSolution in c:\projects.

    Create Projects

    1. Add a new C# WindowsForms project named BuildingUI to your solution.
    2. Add a new C# class project named BuildingBL to your solution.

    Add Code

    I have included a sample project with some simple code. Some of the important parts of the code are covered later in the article.

    A class has been added to represent a Person outlined as follows.

    Then create a simple WinForms application to consume the class. You didn't forget to add your XML comments did you? Those will be important later. You should already be in that habit anyway, right?

    Create First Build File And Build

    [ Easy Way :
    	Open a dos prompt, and go to c:\Projects\BuildingSolution
    	Run c:\devtools\nant\bin\nant.exe -buildfile:firstbuild.guild.xml
    ]
    

    The next step is to create the first build file. Start by grabbing the starter script from the NAnt help site [AJ2]and changing a few of the defaults. Review the BuildingSolution1.build file to see the entire build file.

    If using VS .NET to edit NAnt files, here's a tip for adding NAnt specific intellisense to the IDE. Copy the .xsd file from c:\devtools\nant\schema and paste it into C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml.

    Now create your build file in the solution directory and name it your solution name with the extension .build. Open the file with VS .NET. In the properties window for the build file, you should be able to choose the NAnt schema. This will enable the intellisense.

    Now make the following changes to the file:

    1. Create a new property for Solution.Filename and set it to the filename of your solution.
    2. Change the build task from using the <csc task to using the <solution task. The solution task will analyze the solution file and build projects in the correct orderand will set up the proper references.

    FirstBuild.Build:

    <?xml version="1.0"?>

    <project name="BuildingSolution" default="build" basedir="." xmlns="http://nant.sf.net/schemas/nant-0.85.win32.net-1.0.xsd">

        <description>This is a sample build file to be used for the BuildingSolution sample</description>

       

        <!-- ********** -->

        <!-- Properties -->

       

        <!-- Solution.Filename represents the filename of the solution to build -->

        <property name="Solution.Filename" value="C:\projects\BuildingSolution\BuildingSolution.sln"/>

        <property name="Solution.Configuration" value="DEBUG"/>

        <property name="Build.OutputFolder" value="c:\builds\buildingsolution\"/>

        <!-- End Properties -->

     

     

        <!-- ******* -->

        <!-- Targets -->

     

          <!-- Clean target will delete the current version -->

        <target name="clean" description="remove all generated files">

            <delete>

                      <fileset basedir="${Build.OutputFolder}Latest\">

                            <includes name="*.*"/>

                      </fileset>

            </delete>

        </target>

       

       

        <!-- build will trigger main build -->

        <target name="build" description="compiles the source code">

                <call target="clean"/>

                <solution solutionfile="${Solution.Filename}" outputdir="${Build.OutputFolder}latest\" configuration="${Solution.Configuration}"/>

        </target>

        <!-- End Targets -->

       

       

    </project>

    Shell out to a DOS prompt and go to the directory with the build file. Type in c:\devtools\nant\bin\nant.exe -buildfile:firstbuild.build.xml and watch the first build. You can see the product of the build in c:\builds\buildsingsolution\Latest.

    Build a Test Project with Visual Studio .NET

    Now that you have a built product, there is quite a bit more you can do with it. One of the most important things you can do with each build is run unit tests. Using NAnt, it is very simple to integrate running NUnit tests. Before you can test, though, you need some test fixtures.

    1. Create a new class library project in the solution and call it BuildingTest.
    2. Add a file reference to c:\devtools\nunit\bin\nunit.framework.dll
    3. Add a project reference to BuildingBL
    Writing unit tests provides a proactive way for software developers to test the various pieces of the application. Reviewing the results of unit tests give developers a fast and easy way to determine if changes to any part of the system has affected any other part of the system.[s3]Accurate tests and good code coverage greatly increase the effectiveness of unit testing, so keep that in mind as you plan a strategy for integrating unit testing.

    Time to write some code. First add the [TestFixture] attribute to the class. Then add some public methods to test the various aspects of the class, each marked with a [Test] attribute. Each of these simple methods will test some aspect of the class, and if all goes well, the tests will pass. Provided with this article is sample code with some sample tests.

    The class looks like this:

    So you have a class that does some stuff and a class that tests the stuff it does. The next thing to do would be to run the tests. NUnit provides a GUI to run tests, which can be found at c:\devtools\nunit\bin\nunit-gui.exe. This tool allows developers to run their own individual tests, usually before checking some code into a larger project.

    The build process allows you to run these tests at build time, though, which is the perfect time to test the integration of all the pieces of the project. NAnt provides a Nunit2 task which makes adding NUnit to your build a breeze.

        <!-- runUnitTests will run the nunit task on the test dlls -->

        <target name="runUnitTests" description="Runs unit tests on specified dlls">

                <nunit2 failonerror="false" verbose="true">

                      <formatter outputdir="${Build.OutputFolder}Latest\" usefile="true" type="Xml" extension=".xml"/>

                      <test>

                            <assemblies basedir="${Build.OutputFolder}Latest\">

                                  <includes name="*Test.dll"/>

                            </assemblies>

                      </test>

                </nunit2>

        </target>

    Each of the $ variables are defined as properties above. <Nunit2 starts the NUnit task, and the <formatter tag tells NAnt how to deal with the NUnit output. In this case an XML format hs been specified. Finally the <test and <assemblies tasks handle which files to test. This includes all dll files that match *Test.dll.

    Now if you run this build file, you should get not only the built project, but a new XML file reporting back on the result of the unit tests. At this point you could take that XML file and possibly report off it with XSLT or import it into some log, but for now you can let it sit. More on what you can do with that file later.

    << Introduction •       • Validate Coding Standards During Build with FxCop >>

  • Other Articles
    Jul 28, 2005 - N-Tier Web Applications using ASP.NET 2.0 and SQL Server 2005 - Part 2
    In the second part of his series on building N-tier web applications using ASP.NET 2.0 and SQL Server 2005, Thiru Thangarathinam covers the business logic and user interface layers. In the process, he also examines some new features in ASP.NET 2.0 that greatly simplify the development process.
    [Read This Article]  [Top]
    Jul 14, 2005 - An Innovative Technique for Creating Reusuable Page Templates in ASP.NET 1.x
    Code reusuability is one of the major goals of any good object-oriented programmer. While the ASP.NET framework has made code reusuability easier and more elegant than it was in classic ASP, one area where reusuability could be improved is at the UI level. This article outlines a technique that you can use in ASP.NET 1.x that allows every page in your web application to inherit not only the functionality of a base page, but its UI as well.
    [Read This Article]  [Top]
    Jun 23, 2005 - Monitoring SharePoint Usage through an ASP.NET Web Application
    In this article, Gayan Peiris looks at creating an ASP.NET web application that will display the usage details of a selected SharePoint site. Building such an application enables SharePoint administrators to gather all SharePoint usage data from a central location.
    [Read This Article]  [Top]
    May 12, 2005 - Retrieving SharePoint Site Information in an ASP.NET Web Application
    In this article, Gayan Peiris examines using the SharePoint Object Model to access SharePoint site information from an ASP.NET web application. It should be of particular interest to SharePoint administrators who can use the included code as a starting point for development of their own web-based SharePoint administration application.
    [Read This Article]  [Top]
    Dec 23, 2004 - Automated Deployment for Side By Side .NET Web Apps for Visual Studio .NET 2003
    In this article, David Every outlines a step-by-step account of how he solved the problems he encountered while implementing an auto-deployment process. He also describes how to create a stable process for automated remote .NET deployment featuring "side-by-side" capability.
    [Read This Article]  [Top]
    Sep 29, 2004 - Developing Web Parts with ICellConsumer Interface
    Most default SharePoint Server Web Parts can be connected across organizations. The third article in this series shows how to develop connectable Web Parts that consume information provided by other Web Parts.
    [Read This Article]  [Top]
    Aug 10, 2004 - Implementing and Promoting Daily Builds
    Automatic daily builds is a well known software engineering best practice. This article introduces a strategy for implementing and promoting daily builds and offers tips and tricks for preventing and fixing breaks.
    [Read This Article]  [Top]
    Jun 21, 2004 - Using Open Source .NET Tools for Sophisticated Builds
    Building an application can be more than pressing F5. With an increasing number of quality packages being released, developers for the .NET platform now have options to create a very sophisticated build process. Aaron Junod describes a sample build environment and shows how a number of tools can work together to make reliable, predictable, and value-added builds.
    [Read This Article]  [Top]
    Jun 24, 2003 - Programming for the Palm Part 1 - Creating the Palm Application
    The first part of this three part series walks through the process of creating a mobile blog application using a BASIC development environment for Palm OS devices called NS Basic. Subsequent articles will focus on synchronizing the data to the desktop using C# and creating an installer.
    [Read This Article]  [Top]
    Jun 18, 2003 - Online Database Functions Testing Tool
    This short article provides source code for a classic ASP online database functions testing application and shows how to configure and use the tool for either SQL Server or Oracle.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry

    internet.commediabistro.comJusttechjobs.comGraphics.com

    Search:

    WebMediaBrands Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs