Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
A Survey of Open Source .NET
        Development
           Andrew Troelsen
           VP of Technology
           Interte...
About Me
• Andrew Troelsen: Microsoft MVP (C#), MCT, MCSD
• Partner, .NET Trainer / architect with Intertech
  Training (w...
About You
• A am assuming you are either:
  – Currently using open source tools and wish to see
    what is available for ...
Purpose of Presentation
• To examine the open source nature of the .NET
  platform:
  – What is “open source”, why might I...
Overview of Presentation
• Understanding the “open source mindset”
• Contrast various .NET distributions
• Establishing an...
The Open Source Mindset
• Historically speaking, working with MS technologies
  demanded a tight coupling with MS products...
The Open Source Mindset
    •    With the release of the .NET platform, MS-centric developers have
         been exposed t...
The Open Source Mindset
• Beyond the core SDK, many .NET tools are open
  source…
   – In a nutshell, this means that the ...
The Open Source Mindset
• One of the major motivators of selecting open
  source is $$. Example:
  – MS’s latest and great...
The Open Source Mindset

                                                Ug…



                                          ...
The Open Source Mindset
• This is not to say open source products are a perfect
  solution however…
   – While free, they ...
Open Source .NET Distributions
• When MS released the .NET platform, they crafted a set
  of ECMA documents which describe...
Open Source .NET Distributions
• The Mono project is perhaps the most well-
  known open source distribution.
  –   Develo...
Open Source .NET Distributions
                      Mono provides a full set of
                      Command line tools ...
Open Source .NET Distributions
•     In addition to Mono, Portable.NET is another open source .NET distribution
      base...
Open Source .NET Distributions
• Each of the open source tools examined in this
  lecture can be integrated with any of th...
Open Source .NET
•   To date, there are numerous open source projects which target
    .NET.
     – Many of these projects...
Open Source .NET
• http://csharp-source.net : A detailed list of open source
  tools sorted by category.

                ...
Open Source .NET
• http://sharptoolbox.com : Huge list of .NET tools, code
  libraries, IDE plug ins, etc.

              ...
Open Source .NET
•   Given the vast number of tools we could examine, this talk will focus
    on establishing the followi...
The Basics of Mono
•   Full coverage of Mono is beyond the scope of this chat, however be
    aware of the following tools...
Open Source IDEs
•   Although you are always free to build .NET software using nothing
    more than a simple text editor ...
Open Source IDEs
 •    If you are building .NET software on Windows, the most popular
      open source IDE would be #Deve...
Open Source IDEs
• Version 1.x provided numerous features:
   –   Forms designer for SWF.
   –   Integration with preferre...
Open Source IDEs
•   Given that #Develop requires System.Windows.Forms, and given that
    Mono’s SWF implementation is no...
Open Source IDEs
• Beyond #Develop / MonoDevelop, there are many other
  open source IDEs which you should be aware of:
  ...
Free (but not-Open) IDEs
•   Finally, it is worth pointing out that MS has released numerous
    ‘Express’ IDEs
     – C# ...
Open Source Database Servers
• MS developers typically make use of MS SQL Server or
  Oracle DBMS.
   – While both product...
Open Source Database Servers
•   Beyond the MS-centric DBMS offerings, two very popular open
    source alternatives would...
Open Source Database Servers
• To date, PostgreSQL provides more features than
  MySQL, however:
   – PostgreSQL demands m...
Open Source Database Servers
• Once you have picked a DBMS, the next logical step is
  to obtain a .NET data provider.
   ...
Open Source Database Servers
Open Source Database Servers
• As a naming convention, each ‘general object’ is
  prefixed with the name of the DBMS. For
...
Open Source Database Servers
 • Despite the differences in name, each
   connection implements the IDbConnection
   interf...
Open Source Database Servers
•   Typically, you are able to obtain a .NET data provider from the
    vendor of your DBMS.
...
Open Source Web Servers
• MS-centric developers make use of IIS to build and
  expose ASP.NET web apps and XML web service...
Open Source Web Servers
• Mono ships with a C#-based web server named
  xsp.exe.
  – This web server runs on all OSs which...
Open Source Web Servers
• A more production-ready alternative is to make use of
  ASP.NET plug-ins for Apache:
   – The Mo...
Mid-Session Summary
• To sum up the story so far:
  – Various open source distributions exist today
    beyond MS .NET (Mo...
Mid-Session Summary
• With this behind us, the remainder of this chat
  will examine some select .NET development
  tools ...
Automating Builds with NAnt
• Java developers have long know of the virtues of an
  open source tool named ant.
   – Ant i...
Automating Builds with NAnt
•   Understand that NAnt is not intended to be a direct replacement for
    an IDE.
     – IDE...
Automating Builds with NAnt
• NAnt can be obtained from http://nant.sourceforge.net
   – Once installed, you will find num...
Automating Builds with NAnt
•   Like any command line tool, NAnt.exe provides numerous command
    line options.
     – Sp...
Automating Builds with NAnt
• Constructing .build files requires you to understand the
  concept of a task:
   – A task is...
Automating Builds with NAnt
•   For example, the <csc> task is used to control the C# compiler.
     – The opening element...
Automating Builds with NAnt
• Beyond <csc> there are other tasks which control other
  command line tools:
   – <al>, <vbc...
Automating Builds with NAnt
• Tasks are not processed directly by NAnt, but must be
  bundled within a target.
   – Target...
Automating Builds with NAnt
• Assume you wish to build a C# console application
  which needs to reference a set of extern...
Automating Builds with NAnt
•   The previous build script was quite simple, however, more elaborate
    scripts may requir...
<project name=quot;Hello Worldquot; default=quot;runquot;>
                                             <property name=quo...
Automating Builds with NAnt
•   Like other .NET tools, NAnt has a related *.config file which can be
    used to control h...
Automating Builds with NAnt
• If you would rather not specify a property in your .build
  files, you are also able to spec...
Automating Builds with NAnt
  •    While authoring the necessary XML by hand is not rocket science, it can be
       a bit...
Generating Help with NDoc
•   As you most likely know, C# provides an XML-based syntax to
    document your code.
      – ...
Generating Help with NDoc
• Once you have generated a *.xml file that describes your
  types, the end result is a rather b...
Generating Help with NDoc
• NDoc is a very helpful open source tool which
  will generate help systems in a variety of
  f...
Generating Help with NDoc
• NDoc has a stand alone UI which allows you to load up
  any number of assemblies to build and ...
Generating Help with NDoc
• #Develop also allows you to interact with NDoc directly
  within the IDE.
   – Right click on ...
Unit Testing with NUnit
• Before we examine the open source NUnit utility,
  we need to define ‘unit testing’ itself:
  – ...
Unit Testing with NUnit
• Unit testing is not end-user testing, QA
  testing or testing for performance / best
  practices...
Unit Testing with NUnit
•   Although it is possible for a given developer to roll their own testing
    framework, NUnit p...
Unit Testing with NUnit
• Once installed, you will find a few new
  assemblies have been installed into the
  GAC.
  – nun...
Unit Testing with NUnit
• Although you could directly build your tests
  within the production code base, recall that the
...
Unit Testing with NUnit
• The ‘test methods’ within an assembly
  make calls on the methods in the
  production assembly.
...
Unit Testing with NUnit
• For example, you might have a method which
  inserts a new record into a database.
  – The tests...
Unit Testing with NUnit
•   Consider the following scenario:
     – You have a production level assembly which contains a ...
Unit Testing with NUnit
•   When you are designing an NUnit-centric test class, your basic goal
    is to define a type wh...
Unit Testing with NUnit
• Here is a simple NUnit test-class template:
  [TestFixture]
  public class MyTester
  {         ...
Unit Testing with NUnit
• So, the next logical question would be what to place in
  the [Test] methods?
   – Typically you...
Unit Testing with NUnit
• Some tests may require you to ensure that a given
  method throws an expected exception under th...
Unit Testing with NUnit
•          In this case, you could author a test method which attempts to trip
           the MySq...
Unit Testing with NUnit
•   Once you have compiled your production and test assemblies, you
    can now make use of NUnit ...
Presentation Summary
•   The .NET platform is available for free from MS corp. As well as via
    Mono / Portable. NET dis...
Upcoming SlideShare
Loading in …5
×

.NET Open Source Training

1,689 views

Published on

http://www.Intertech.com

This is a slide deck on open source .NET development

Published in: Technology
  • IT Pathshala, Noida-Sector-63, offers Guaranteed JOB with .NET Training Programs.

    PAY US ONLY IF YOU GET A JOB!

    CALL US - +91-9871350999 or +91-8800394970

    Technology Centre Address: H-110, Sector-63, Noida (UP)

    Program Takeaways:

    - GUARANTEED JOB in your technology domain
    - Live Major Project development
    - Experience Letter on Training Completion
    - Certification on Training Completion
    - Project Source Code available in CD

    Program Highlights:

    - 100% Guaranteed Job – Don’t pay us if you don’t get a JOB!
    - Industry Ready Courses
    - LIVE International Project Experience
    - Exposure to corporate culture at our IT services facility
    - Networking & Interaction with Industry Experts
    - Training Provided by a reputed IT Company
    - Live Project Source Code made available in CD
    - Technology certification and experience letter at program completion
    - Online Study Content

    CALL US - +91-9871350999 or +91-8800394970

    Our website: www.itpathshala.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

.NET Open Source Training

  1. 1. A Survey of Open Source .NET Development Andrew Troelsen VP of Technology Intertech Training Minneapolis, MN atroelsen@intertech.com
  2. 2. About Me • Andrew Troelsen: Microsoft MVP (C#), MCT, MCSD • Partner, .NET Trainer / architect with Intertech Training (www.intertech.com). – C#, VB.NET, ASP.NET, .NET Security, 2.0 Deltas, etc. – Full J2EE curriculum to boot! • Author of numerous .NET related books and articles. – Various MSDN Online articles (www.msdn.com) – Latest book: Pro VB 2005 and the .NET 2.0 Platform, 2rd Ed.
  3. 3. About You • A am assuming you are either: – Currently using open source tools and wish to see what is available for the .NET platform. – New to the open source mindset, and want to see how this could effect your .NET development process. • No in-depth knowledge of .NET is required to glean insights from this talk. – On a similar note, no open source experience is necessary – This is primarily a tool talk…!
  4. 4. Purpose of Presentation • To examine the open source nature of the .NET platform: – What is “open source”, why might I care, what tools are available? • To expose you to several tools and leave you in a good position for further exploration. – There are thousands of open source projects in the world today, many of which are .NET specific. – Clearly there is no way to examine each and every possibility (but you’ll see many web links…).
  5. 5. Overview of Presentation • Understanding the “open source mindset” • Contrast various .NET distributions • Establishing an open source development environment (IDEs, DBMSs, Web Servers, etc). • An overview of select open source .NET tools. – NAnt, NDoc, NUnit.
  6. 6. The Open Source Mindset • Historically speaking, working with MS technologies demanded a tight coupling with MS products. – Expensive tools (Visual Studio, SQL Server, etc) with expensive licenses. • Once a company adopted the license requirements, they can become a victim of the tool’s limitations. – For example, VS 2005 has no way to swap out the underlying compiler version (1.0, 1.x or 2.0)! – While developers could build or buy extensions for MS tools, the obvious downside was additional cost. • Of course, this is not an issue found only with Microsoft corporation. – Oracle, IBM, (etc) developers also face similar issues.
  7. 7. The Open Source Mindset • With the release of the .NET platform, MS-centric developers have been exposed to a whole new world: – The .NET 2.0 SDK is free (http://msdn.microsoft.com/netframework). – Numerous free IDEs exist. – Numerous free .NET-aware DBMS / web servers exist. – Numerous free code libraries exist. – Numerous Java-centric tools have now been ported to the .NET platform (which you can use for free). The .NET 2.0 SDK provides all the core ‘stuff’ required to build .NET applications: - Command line compilers /debugger for MS .NET languages. - Full local help system (MSDN). - Code samples & white papers. - Additional command line tools for remoting, serialization, XML schema, COM interop, etc. - Graphical debugger (DbgCLR.exe) NOT a graphical IDE however.
  8. 8. The Open Source Mindset • Beyond the core SDK, many .NET tools are open source… – In a nutshell, this means that the tool / library in question ships with full source code, which may be tweaked and redistributed. – This also means that you are free to contribute to the development / support of these tools. • Understand of course that the MS distribution of the .NET platform is not open source. – As well, MS .NET can only be used on MS-specific OSs. – Thankfully, alternative .NET distributions do exist which can run on numerous operating systems.
  9. 9. The Open Source Mindset • One of the major motivators of selecting open source is $$. Example: – MS’s latest and greatest IDE (Visual Studio 2005 Team Foundations / Team Suite) is an excellent product…provided you are willing to spend for it. – While this tool has integrated unit testing, build automation (etc) it is not open source and can cost over 10K to buy the full product!!
  10. 10. The Open Source Mindset Ug… Holy Cow! (obviously, this price will decrease based on your company’s MSDN status…) http://msdn.microsoft.com/vstudio/howtobuy/Default.aspx
  11. 11. The Open Source Mindset • This is not to say open source products are a perfect solution however… – While free, they are typically not supported. – Thus, who do you call when things go wrong? (answer: try Google). • Some IT shops refuse open source products for this very reason… – And the fear that the code could be evil. • The tools / products we will examine here are very popular tools which have already been adopted by many mainstream companies, teams. – In fact, some of them do provide an option to purchase a support program (Mono).
  12. 12. Open Source .NET Distributions • When MS released the .NET platform, they crafted a set of ECMA documents which describe in gory detail the .NET framework and C# programming language: – ECMA-334: All the details of the C# language. – ECMA-335: All the details of the inner-working of the .NET platform. • These documents have made it possible for other companies to build custom distributions of the .NET / C#. – Thus, even though Microsoft was the originator of .NET, you can build .NET applications without ever installing Microsoft .NET! – Even better, these alternative .NET platforms are open source and can be installed on any number of operating systems (Linux, Mac OS X, Win32, Solaris, etc)
  13. 13. Open Source .NET Distributions • The Mono project is perhaps the most well- known open source distribution. – Developed by Ximian/Novell – Multi-platform distribution (Win32, Mac OS, Linux, etc) – Based on the ECMA/ISO standards – Open Source, Free Software – Commercially supported – www.mono-project.com
  14. 14. Open Source .NET Distributions Mono provides a full set of Command line tools which are Functionally equivalent to their MS .NET counterparts. As well, Mono ships with a full Implementation of: - mscorlib.dll - ASP.NET / web services - ADO.NET - Windows Forms (beta 2) - Remoting layer - XML manipulation - Etc. Mono also ships with numerous assemblies which are specific to A given OS (for example, Cocoa# For Mac OS X).
  15. 15. Open Source .NET Distributions • In addition to Mono, Portable.NET is another open source .NET distribution based on the ECMA specs. – http://www.dotgnu.org – Currently supported CPUs: x86, ppc, arm, parisc, s390, ia64, alpha, mips, sparc. – Supported operating systems: GNU/Linux (on PCs, Sparc, iPAQ, Sharp Zaurus, PlayStation 2, Xbox,...), *BSD, Cygwin/Mingw32, Mac OS X, Solaris, AIX. Portable indeed!
  16. 16. Open Source .NET Distributions • Each of the open source tools examined in this lecture can be integrated with any of the aforementioned .NET distributions. – Here, all code examples will be making use of the Mono C# compiler / Mono base class libraries. – If you are using another .NET distribution (MS.NET or Portable.NET), you will be able to easily modify the examples as need be.
  17. 17. Open Source .NET • To date, there are numerous open source projects which target .NET. – Many of these projects are ports of existing, well known Java tools (NAnt, NUnit, etc). – Others are specific to the .NET environment (#Develop, SAX.NET, etc). – Others still are open source projects which work equally well under J2EE or .NET (MySQL, Apache). • As mentioned, there is no possible way to cover all open source tools in detail in this session. – Thus, it is important to be aware of select web sites which provide numerous links to numerous projects. – Do know this is a small sampling of .NET open source sites, however the following two sites are quite popular.
  18. 18. Open Source .NET • http://csharp-source.net : A detailed list of open source tools sorted by category. - AOP Frameworks - Blogging tools - Build tools - Charting tools - Chat servers - CMS - Coverage tools - IDEs - Object persistence - Network frameworks - PDF libraries - Code profilers - Source code control - Unit testing - et al.
  19. 19. Open Source .NET • http://sharptoolbox.com : Huge list of .NET tools, code libraries, IDE plug ins, etc. - Very helpful search engine - Refined category listings - Cross linking to further sites Although a vast majority of tools are freely downloadable, some listings do not provide source code!
  20. 20. Open Source .NET • Given the vast number of tools we could examine, this talk will focus on establishing the following .NET environment: – Working with the open source Mono .NET distribution. – Building .NET software using the open source #Develop IDE. – Pick a web server / database server. – Transforming source code comments into help systems using NDoc. – Automating complex builds using NAnt. – Understand how to make perform unit testing (and why you might want to) using NUnit. • Also be aware that even though the examples will be preformed on Windows XP, the techniques shown here would work just about identically on other OSs. – Mac OS X, Linux / Unix distributions, Solaris, etc.
  21. 21. The Basics of Mono • Full coverage of Mono is beyond the scope of this chat, however be aware of the following tools: – mcs : C# command line compiler. – mbas : VB.NET command line compiler (currently alpha). – monodoc : Local help system. • Mono ships with a GUI toolkit named GTK#, which is a platform independent UI framework: – Mono also ships with Glade# which is an XML-based UI toolkit. – Mono’s Windows Forms implementation is almost 100% complete. • Like MS .NET, Mono supports a global assembly cache (GAC): – C:Program FilesMono-1.1.13.2libmonogac
  22. 22. Open Source IDEs • Although you are always free to build .NET software using nothing more than a simple text editor and the command line compiler, most prefer an integrated IDE. – Several free / open source IDEs exist today. – Some will only run of specific operating systems. – Others can work on any operating system when can run the .NET platform. • At minimum, most developers expect their IDE has the following core features: – Auto-complete / IntelliSense support (and other code beautifiers) – Integrated help, integrated debugger, visual designers for UI based applications.
  23. 23. Open Source IDEs • If you are building .NET software on Windows, the most popular open source IDE would be #Develop hands down. – As of version 2.0, #Develop has been updated to have full support for .NET 2.0 (IntelliSense for generics, support for partial classes, etc). – You may download the C# code or *.msi installer. -Support for multiple .NET languages. -Support for MS and Mono compilers -Designer support for SWF -Integrated debugger, code snippets, etc. In reality, this tool is as functional as Visual Studio .NET 2003 (but not quite As powerful as VS 2005)
  24. 24. Open Source IDEs • Version 1.x provided numerous features: – Forms designer for SWF. – Integration with preferred help system. – Integration with NAnt, NDoc, NUnit. – Support for C#, VB.NET, C++, CIL. • Version 2.0 has vast upgrades to 1.x: – Integrated debugger. – Project templates for MS .NET, Mono (GTK#, Glade#), WinFx. – Referencing assemblies from the Mono GAC. – Project editor, similar to Visual Studio 2005. – Added .NET languages (Boo) – Code definition window – Project => HTML #Develop / Mono Demo!
  25. 25. Open Source IDEs • Given that #Develop requires System.Windows.Forms, and given that Mono’s SWF implementation is not complete, #Develop will not run on Mac / Linux / Unix. – However, the Mono project has ported #Develop to make use of GTK+, and from this, we have MonoDevelop (www.monodevelop.com). MonoDevelop installs very simply under Linux / Unix distros, however installing this tool on Mac OS X is quite painful… Although it is possible (if you have installed XWindows & Gnome), I’d suggest other options: - Eclipse with C# plug-in. - XCode with C# plug-in. - X-Develop (not open source, but excellent) http://www.monodevelop.com/Running_On_OSX
  26. 26. Open Source IDEs • Beyond #Develop / MonoDevelop, there are many other open source IDEs which you should be aware of: – Emacs does provide a C# plug-in (as does the Windows port, NTEmacs). – VIM (VI iMproved editor) also provides a C# plug-in. – Eclipse provides a C# plug-in. http://www.improve-technologies.com
  27. 27. Free (but not-Open) IDEs • Finally, it is worth pointing out that MS has released numerous ‘Express’ IDEs – C# Express, VB 2005 Express, J# Express, C++ Express, Visual Web Developer Express. – These tools are slimmed down versions of their Visual Studio 2005 counterparts. – To date, each of these tools are free and supported by MS corp. – http://msdn.microsoft.com/vstudio/express - Visual Designers - Integrated debugger - Code completion / snippets - Integration with MSDN - etc…
  28. 28. Open Source Database Servers • MS developers typically make use of MS SQL Server or Oracle DBMS. – While both products are very good, they comes with a cost. • Recently, MS has released SQL Server 2005 Express, the heir apparent to MSDE. – http://msdn.microsoft.com/vstudio/express/sql – Database code (stored procs) can be authored in T-SQL or .NET programming languages / native XML support / UI admin tools. • While free, this tool is not intended for enterprise level development (and is not open source). – Assumption is if your database outgrows the Express limitations, you’ll upgrade to a full version of MS SQL Server.
  29. 29. Open Source Database Servers • Beyond the MS-centric DBMS offerings, two very popular open source alternatives would be: – MySQL : http://www.mysql.com – PostgreSQL : http://www.postgresql.org • Both products offer professional / enterprise-ready features. – Graphical administration tools, Tx support, stored procs, etc.
  30. 30. Open Source Database Servers • To date, PostgreSQL provides more features than MySQL, however: – PostgreSQL demands many Unix-centric services (such as Sleepycat Berkeley DB). – Given this, we do not have a native Windows PostgreSQL installation. – If you wish to install PostgreSQL on windows, you must do so via Cygwin (www.cygwin.com), a open source project which emulates Unix tools on Win32. • On the other hand, the latest version of MySQL (5.0) provides almost as many features as PostgreSQL. – Better yet, MySQL provides native Mac OS, Linux/Unix and Windows installation programs.
  31. 31. Open Source Database Servers • Once you have picked a DBMS, the next logical step is to obtain a .NET data provider. – As you may know, ADO.NET is the .NET database access API. – Unlike other MS data-access models, the API allows for multiple data provider implementations. – Thus, you are able to pick a specific data provider which targets a specific DMBS. • Thankfully, regardless of which provider you select, the all derive from the same base classes and implement the same core interfaces. – Thus, switching between data-providers is quite straightforward.
  32. 32. Open Source Database Servers
  33. 33. Open Source Database Servers • As a naming convention, each ‘general object’ is prefixed with the name of the DBMS. For example: – MySqlConnection: Connection object for MySQL – SqlConnection: Connection object for MS SQL Server – NpsSqlConnection: Connection object for PostgreSQL – OracleConnection: Connection object for Oracle. – Etc…
  34. 34. Open Source Database Servers • Despite the differences in name, each connection implements the IDbConnection interface, and therefore has the same core functionality. public interface IDbConnection : IDisposable { // Methods IDbTransaction BeginTransaction(); Simply put, a given ADO.NET provider is IDbTransaction BeginTransaction(IsolationLevel il); an implementation of core interfaces. void ChangeDatabase(string databaseName); void Close(); IDbCommand CreateCommand(); The types of a provider are logically grouped within void Open(); a specific .NET namespace, which is physically bundled into a .NET assembly. // Properties string ConnectionString { get; set; } int ConnectionTimeout { get; } string Database { get; } ConnectionState State { get; } }
  35. 35. Open Source Database Servers • Typically, you are able to obtain a .NET data provider from the vendor of your DBMS. – MySql provider can be found at www.mysql.com/products/connector • The Mono project maintains a list of ADO.NET data providers (www.mono-project.com/Database_Access). • Finally, www.sqlsummit.com/DataProv.htm provides a very comprehensive list of ADO.NET providers: MySQL + ADO.NET Demo!
  36. 36. Open Source Web Servers • MS-centric developers make use of IIS to build and expose ASP.NET web apps and XML web services: – IIS ships with the Windows operating system as a ‘free’ add on (that is once you buy the OS!) – Simply to administer multiple web sites via virtual directories. – Integrates with the .NET platform. • Of course, IIS only allows you to build and run ASP.NET sites on the Windows family of OSs. – As you would guess, there are additional open source web servers…
  37. 37. Open Source Web Servers • Mono ships with a C#-based web server named xsp.exe. – This web server runs on all OSs which support Mono. – Hosts ASP.NET and XML web services. • While xsp.exe is very useful for testing / development, this app is not intended to be a production level web server. – No support for additional web-server features (smtp, etc). – No UI management. – Not necessarily the most scalable /robust web server.
  38. 38. Open Source Web Servers • A more production-ready alternative is to make use of ASP.NET plug-ins for Apache: – The Mono project provides an ASP.NET open source plug-in for Apache (http://www.mono-project.com/ASP.NET). – As well, Covalent offers a commercially supported ASP.NET apache mod (http://www.covalent.net).
  39. 39. Mid-Session Summary • To sum up the story so far: – Various open source distributions exist today beyond MS .NET (Mono & Portable.NET being the two most notably). – Dozens of open source IDEs exist (#Develop most notably), many of which rival the functionality of costly commercial IDEs. – Finally, numerous open source DMBS and web servers work A-OK with the .NET platform.
  40. 40. Mid-Session Summary • With this behind us, the remainder of this chat will examine some select .NET development tools which are independent of the IDE you use for coding productivity. – Do be aware that each of the tools we will examine do integrate with #Develop. – As well, each tool can be run from the command line and most of these tools ship with a related UI shell.
  41. 41. Automating Builds with NAnt • Java developers have long know of the virtues of an open source tool named ant. – Ant is an fully extendable automated build tool. – The build scripts are XML-based, therefore they are quite ‘human readable’. • NAnt is a .NET port of this popular build tool. – Like ant, NAnt is an XML-based, extendable build tool. – Because .NET languages do not have a strict dependency on file names / directory names, using NAnt is simpler than ant in many cases. • NAnt is compatible with Microsoft’s .NET, the SSCLI, Mono and Portable .NET. – Therefore, NAnt can be used on Windows, Linux, Mac OS X or FreeBSD-based Unix OSs.
  42. 42. Automating Builds with NAnt • Understand that NAnt is not intended to be a direct replacement for an IDE. – IDEs offer dozens of features NAnt does not (IntelliSense, integrated debuggers / help systems, code-completion tools, snippets, etc). – After all, you need to have some way to author the code in the first place! • Rather, NAnt is concerned with automating complex builds after the code has been authored: – For example a single *.build file could build a .NET code library, create an IIS installation for an ASP.NET web app and deploy the code library to the bin folder. – As well, a single *.build file could interact with numerous .NET compilers. – Build errors could be handled by e-mailing the details to a build administrator. – External .NET tools (aximp, regsvcs, tlbexp, and so on) can also be incorperated into the ‘build’.
  43. 43. Automating Builds with NAnt • NAnt can be obtained from http://nant.sourceforge.net – Once installed, you will find numerous sample build scripts, documentation and the command line tool nant.exe. Beyond providing NAnt downloads, the NAnt Home page also provides: - Online documentation - Tutorials - Wiki / mailing lists, etc. -MS .NET 1.x, 2.0 and Mono 1.x / 2.0 distributions.
  44. 44. Automating Builds with NAnt • Like any command line tool, NAnt.exe provides numerous command line options. – Specify -help to see all your options. • By default, when NAnt is run without specifying any arguments, it will automatically look for a file with a .build extension. – Within this .build file, you will author various XML elements which instruct NAnt the tasks you wish to execute. – If the current directory has multiple .build files, you will need to specify the -buildfile option (or the shortened -f).
  45. 45. Automating Builds with NAnt • Constructing .build files requires you to understand the concept of a task: – A task is an atomic XML element which describes a specific build action. – NAnt defines numerous predefined tasks, which just so happen to be named identically to the .NET SDK command line tools. – Each task can be further qualified using numerous attributes and related sub-elements. – Obviously, consulting the NAnt documentation is critical here…
  46. 46. Automating Builds with NAnt • For example, the <csc> task is used to control the C# compiler. – The opening element tag has numerous attributes, most of which specify command line options of csc.exe. • The <csc> scope may have optional sub-elements such as: – <references> : The set of assemblies to reference for the compilation. – <sources> : The list of C# files to compile. – <resources> : The list of resources to embed. <csc target=quot;exequot; output=“MyConsoleApp.exequot; debug=quot;truequot;> <references> <include name=quot;System.Web.Services.dllquot; /> <include name=quot;System.Data.OracleClient.dllquot; /> </references> </csc>
  47. 47. Automating Builds with NAnt • Beyond <csc> there are other tasks which control other command line tools: – <al>, <vbc>, <ilasm>, <vjc>: Used to interact with assembly linker, VB.NET, CIL and J# compilers. – <aximp>, <tlbexp>, <tlbimp>: Various COM interop tools. • NAnt also supports tasks which interact with other open source tools: – <ndoc>, <nunit>: documentation and unit testing. NAnt Documentation of Tasks
  48. 48. Automating Builds with NAnt • Tasks are not processed directly by NAnt, but must be bundled within a target. – Targets are defined by the user which describe a collection of related tasks. – While there are a few attributes which can be used to qualify a <target> element, the only critical attributes are name and description. • Finally, the collection of <target>s are placed within a <project> scope. – If a <project> defines multiple <target>s, you can use the default attribute to specify the target to execute if not specified at the command line.
  49. 49. Automating Builds with NAnt • Assume you wish to build a C# console application which needs to reference a set of external assemblies: <project name=quot;EchoAppquot;> <target name=quot;BuildMyAppquot; description =quot;Compiles EchoApp.csquot;> <csc target=quot;exequot; output=quot;EchoApp.exequot;> <sources> <include name=quot;EchoApp.csquot;/> </sources> <references> <include name=quot;System.Web.Services.dllquot; /> <include name=quot;System.Data.OracleClient.dllquot; /> </references> </csc> </target> </project>
  50. 50. Automating Builds with NAnt • The previous build script was quite simple, however, more elaborate scripts may require the use of properties: – Just like properties on a component, NAnt properties can be used to change the behavior of the build. – Properties can be user defined, however NAnt has various built in properties as well. – Properties are defined and referenced using a ${propName} syntax. • To illustrate, consider the following .build file which leverages various properties which defines a property named basename and makes use of the built-in debug property. – This project defines three targets to clean, build and run the resulting apps.
  51. 51. <project name=quot;Hello Worldquot; default=quot;runquot;> <property name=quot;basenamequot; value=quot;HelloWorldquot;/> <property name=quot;debugquot; value=quot;truequot;/> This <target> will delete all *.exe and *.pdb files within the bin/HelloWorld <target name=quot;cleanquot;> <delete> folder. <fileset> <include name=quot;bin/${basename}-??.exequot;/> <include name=quot;bin/${basename}-??.pdbquot;/> </fileset> </delete> </target> <target name=quot;buildquot;> <mkdir dir=quot;binquot; /> <csc target=quot;exequot; output=quot;bin/${basename}-cs.exequot; debug=quot;${debug}quot;> This <target> compiles three code files <sources> written within three .NET languages (C#, <include name=quot;${basename}.csquot;/> </sources> VB.NET and JScript.NET). </csc> <jsc target=quot;exequot; output=quot;bin/${basename}-js.exequot; debug=quot;${debug}quot;> <sources> <include name=quot;${basename}.jsquot;/> </sources> </jsc> <vbc target=quot;exequot; output=quot;bin/${basename}-vb.exequot; debug=quot;${debug}quot;> <sources> This <target> will execute each <include name=quot;${basename}.vbquot;/> </sources> compiled application. </vbc> </target> <target name=quot;runquot; depends=quot;buildquot;> <exec program=quot;bin/${basename}-cs.exequot; basedir=quot;.quot;/> <exec program=quot;bin/${basename}-js.exequot; basedir=quot;.quot;/> <exec program=quot;bin/${basename}-vb.exequot; basedir=quot;.quot;/> </target> </project>
  52. 52. Automating Builds with NAnt • Like other .NET tools, NAnt has a related *.config file which can be used to control how the tool executes. – NAnt.exe.config • One element to be aware of is the <frameworks> element. – This element defines numerous .NET distributions. – MS .NET 1.0, 1.1, 2.0, .NET Compact Framework (CF). – Mono 1.0, 2.0. – Microsoft’s SSCLI (shared source CLI). • You can control which framework (and version) to make use for a given .build file using pre-defined properties: – ${nant.settings.currentframework.name} – ${nant.settings.currentframework.version}
  53. 53. Automating Builds with NAnt • If you would rather not specify a property in your .build files, you are also able to specify the /targetframework flag (or the shorthand /t) at the command line: NAnt.exe -t:net-1.0 • Finally, you can update nant.exe.config to specify the default framework: <frameworks> <platform name=quot;win32quot; default=quot;net-1.0quot;> ... </platform> </frameworks>
  54. 54. Automating Builds with NAnt • While authoring the necessary XML by hand is not rocket science, it can be a bit painful: – Hard to find typos, no IntelliSense out-of-the-box, verbose, etc. • Thankfully, there are UI shells which can be used to create .build files. – Nantpad is one such tool (www.nantpad.com) Be aware that this tool is not open Source and is not free (unless you Have happy with the demo version). Standard edition (single user): $90.00 Prof. edition (single user): $240.00
  55. 55. Generating Help with NDoc • As you most likely know, C# provides an XML-based syntax to document your code. – VB 2005 now supports the same feature. • Once your code files have been annotated with these XML tags, you can enable the /doc option of the compiler. – This results in an XML document which describes your code base. – As well, #Develop (and MS IDEs) use these tags to generate pop-up help for a given item. There are numerous XML elements / properties which can be used to document your code. Look up the topic “XML Documentation” in the .NET Framework SDK documentation. Also be aware that many IDEs (including #Develop) will ‘auto-complete’ XML skeleton tags.
  56. 56. Generating Help with NDoc • Once you have generated a *.xml file that describes your types, the end result is a rather bland XML document: While you are free to apply any number of XML transformations to this XML file, the NDoc utility provides an out-of the box Solution.
  57. 57. Generating Help with NDoc • NDoc is a very helpful open source tool which will generate help systems in a variety of formats: – MSDN, JavaDoc, LaTeX, etc. – http://ndoc.sourceforge.net • Even better, NDoc makes use of reflection services to build a more complete help system. – Documentation = XML comments + metadata. – Because reflection is used, it is possible to build a basic help system (albeit not terribly well commented) even if you do not make use of XML code comments.
  58. 58. Generating Help with NDoc • NDoc has a stand alone UI which allows you to load up any number of assemblies to build and configure the look of your help system.
  59. 59. Generating Help with NDoc • #Develop also allows you to interact with NDoc directly within the IDE. – Right click on your project icon from the Projects perspective and select – “Build documentation with NDoc” NDoc demo!
  60. 60. Unit Testing with NUnit • Before we examine the open source NUnit utility, we need to define ‘unit testing’ itself: – Simply put, a unit test is a piece of code which exercises (tests) a small unit of production code. – Using unit tests, developers are able to prove that a piece of production code works as intended. • When used correctly, unit tests can radically decrease the amount of debugging which is required! – Although many developers view unit testing as something which ‘gets in the way’ of coding, in reality it is real coding which can save you time in the long run.
  61. 61. Unit Testing with NUnit • Unit testing is not end-user testing, QA testing or testing for performance / best practices (necessarily). – Rather unit testing is a way for developers to test code and quash bugs before rolling code to QA.
  62. 62. Unit Testing with NUnit • Although it is possible for a given developer to roll their own testing framework, NUnit provides an out-of-the-box framework to do so. – NUnit is a .NET port of the popular JUnit testing tool for Java. – This open source tool can be driven at the command line, via a stand alone UI, or by integrating within IDEs (#Develop, Visual Studio). – www.nunit.org Supports .NET 1.x / 2.0. Supports Mono, MS .NET and therefore numerous operating systems.
  63. 63. Unit Testing with NUnit • Once installed, you will find a few new assemblies have been installed into the GAC. – nunit.framework.dll is the core assembly which defines numerous types used to build your tests.
  64. 64. Unit Testing with NUnit • Although you could directly build your tests within the production code base, recall that the test code is indented to be completely decoupled from the production code. – Thus, it is more common to build a separate assembly which references nunit.framework.dll. This assembly contains the test code. – The production assembly has no knowledge of the testing assembly.
  65. 65. Unit Testing with NUnit • The ‘test methods’ within an assembly make calls on the methods in the production assembly. – Each test attempts to verify an atomic bit of functionality of the test method. – As well, each test method must be designed to be atomic as well!
  66. 66. Unit Testing with NUnit • For example, you might have a method which inserts a new record into a database. – The tests might include seeing what happens with redundant records, what happens if a string field is empty, etc. – Obviously, it is impossible to account for every possible test, and a given test should be simple and atomic. – However, the rational is that by establishing a set of tests for given methods, you can deal with issues early on, and not have the bug in one method propagate throughout your code.
  67. 67. Unit Testing with NUnit • Consider the following scenario: – You have a production level assembly which contains a class implementing a method named InsertRecord(). – Your test assembly defines a type which invokes the InsertRecord() method via a set of NUnit test methods. – Notice how the production assembly has no clue about the testing assembly. Nunit.CarsDal.dll CarsDal.dll InsertTestRecord() InsertRecord() InsertEmptyRecord()
  68. 68. Unit Testing with NUnit • When you are designing an NUnit-centric test class, your basic goal is to define a type which is adorned with various attributes. – The NUnit test engine will be hunting for these attributes to execute your tests. – Here are some (but not all) of the useful attributes…
  69. 69. Unit Testing with NUnit • Here is a simple NUnit test-class template: [TestFixture] public class MyTester { Once NUnit is informed of the location of this assembly, [TestFixtureSetUp] we would find the following flow of execution: public void OneTimeSetup() { } OneTimeSetup() [SetUp] public void TestPrep() { } TestPrep() [Test] MyTest() public void MyTest() { } TestTerm() [Test] public void MyOtherTest() { } TestPrep() MyOtherTest() [TearDown] TestTerm() public void TestTerm() { } OneTimeTearDown() [TestFixtureTearDown] public void OneTimeTearDown() { } }
  70. 70. Unit Testing with NUnit • So, the next logical question would be what to place in the [Test] methods? – Typically your tests are trying to verify the truth or falsity of a given production method. – To facilitate this endeavor, NUnit provides the Assert type. • As you would expect, this is a highly overloaded method
  71. 71. Unit Testing with NUnit • Some tests may require you to ensure that a given method throws an expected exception under the correct circumstances. – Assume the following production level method: public void InsertNewCar(int id, string make, string color, string petName) { // Configure a connection object. MySqlConnection cn = new MySqlConnection(); cn.ConnectionString = ConnectionString; cn.Open(); // Format the SQL query. string sqlStr = string.Format(quot;Insert Into Inventory (CarID, Make, Color, PetName) Values ('{0}', '{1}', '{2}', '{3}')quot;, id, make, color, petName); MySqlCommand sql = new MySqlCommand(sqlStr, cn); // Execute the command. If a duplicate record is inserted into this sql.ExecuteNonQuery(); Table, the // Close everything down. MySqlCommand.ExecuteNonQuery() cn.Close(); method will throw a MySqlException. }
  72. 72. Unit Testing with NUnit • In this case, you could author a test method which attempts to trip the MySqlException as so: – Note the use of the [Ignore], [ExpectedException] and [Category] attributes… [TestFixture] [Ignore] is a very helpful way to tell NUnit public class InventoryDalTests { to temporally bypass a test. This will // This issues a warning that this test was skipped. issue a warning, but not an error. [Test, Ignore(quot;To be tested later...quot;), Category(quot;Database testsquot;)] public void InsertDefaultRecord() { // Attempt to insert default record. InventoryDAL i = new InventoryDAL(); i.InsertNewCar(111, quot;Jettaquot;, quot;Greenquot;, quot;Ry-Ryquot;); } // If this attribute stack is used, we get warnings! // [Test, ExpectedException(typeof(Exception)), Category(quot;Database testsquot;)] [Test, ExpectedException(typeof(MySqlException)), Category(quot;Database testsquot;)] public void InsertDupRecord() This test basically says, “These code { statements should trip a MySqlEx”, and it // Attempt to insert the same record twice. InventoryDAL i = new InventoryDAL(); does! So this test is sucessful. i.InsertNewCar(112, quot;quot;, quot;quot;, quot;quot;); i.InsertNewCar(112, quot;quot;, quot;quot;, quot;quot;); } } }
  73. 73. Unit Testing with NUnit • Once you have compiled your production and test assemblies, you can now make use of NUnit to perform the tests. – At the command line. – Using the NUnit UI shell. – Using #Develop. Categories can be selected here… Red: Failure! Yellow: Warning! Green: Success! Demos! NUnit & #Develop Integration
  74. 74. Presentation Summary • The .NET platform is available for free from MS corp. As well as via Mono / Portable. NET distributions (both open source). • #Develop is the premier open source .NET IDE (however it is Windows only). • NAnt, NDoc, NUnit are a tiny representation of all the open source tools which are available for the modern day .NET developer.

×