Open Source .NET Development [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Open Source .NET Development [Electronic resources] - نسخه متنی

Brian Nantz

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید


Useful Tools for Use with NAnt


A scriptable build gives greater opportunity to uniformly automate tasks across all projects of a product. Several tools are very useful for catching common coding mistakes and flagging potential bugs.

FxCop


FxCop (Figure 4-4) is a Microsoft tool that can check managed assemblies for common design and implementation problems. It checks for security, versioning, language interoperability, and naming guideline problems, most of which are described in the .NET Framework Design Guidelines. This tool is available for download from http://www.gotdotnet.com/team/fxcop/. The tool comes with over one hundred predefined rules. The output file is in XML (Listing 4.25), and the tool is extensible. It allows third parties to write new rules that execute during FxCop analysis. For information on developing your own rules, download and install FxCop and read the docs/FxCopSdk file.

Listing 4.25. FxCop XML Output File

<?xml version="1.0"?>
<FxCopReport Version="1.072">

<Violation Kind="AssemblyRule" Name="AssembliesHaveStrongNames" Priority="1"
FullName="Microsoft.Tools.FxCop.Rules.Standard.AssembliesHaveStrongNames, DesignRules,
Version=1.0.7.2, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<Assembly Name="log4net" FullName="log4net, Version=1.2.0.23661,
Culture=neutral, PublicKeyToken=null"/>
<Suggestion>Sign 'log4net' with a strong name key.</Suggestion>
</Violation>

<Violation Kind="AssemblyRule" Name="AssembliesHavePermissionRequests" Priority="1"
FullName="Microsoft.Tools.FxCop.Rules.Standard.AssembliesHavePermissionRequests,
UsageRules, Version=1.0.7.2, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<Assembly Name="log4net" FullName="log4net, Version=1.2.0.23661,
Culture=neutral, PublicKeyToken=null"/>
<Suggestion>Add permission requests to the assembly 'log4net'.</Suggestion>
</Violation>
....
</FxCopReport>

Figure 4-4. FxCop GUI.

[View full size image]

FxCop could be called using the exec task, or FxCop could be wrapped as a NAnt task similar to the GacTask we just looked at. This tool is invaluable at pointing out code problems, almost like a lint program that can be easily integrated into your build using NAnt's exec task. There have been a lot of requests for the creation of an FxCop task. There may even be one by the time this book reaches the shelves, but I would suggest that this task belongs in NAntContrib because FxCop is currently only available on Windows platforms.

Artistic Style


AStyle (astyle.sourceforge.net) is a free, fast auto-indention tool for C/C++/C# and Java source. This is the only resolution to the age-old tab versus spaces debate, or exactly how many spaces should be used. If your editor does not handle the automatic transformation between tabs and spaces, then this tool is for you. No matter how everyone else formats his or her code, you can reformat the code for the entire product by integrating AStyle into NAnt. But be forewarned that when you check the code back into SCM, you may upset many team members. If you are going to use this little trick, then everyone on the team should also use it and let everyone format away, to each their own.

HTML Tools


For ASP.NET projects, there are a number of helpful tools that can be automated simply using NAnt. Many of these tools are free, and some are even Open Source. The W3C has many of these tools, including:


These tools can help find countless HTML syntax errors and cut down on many problems before they reach the production Web server machine.

NAntPad


Figure 4-5 shows a graphical tool to aid in the creation of NAnt projects. NAntPad (http://www.nantpad.com) is a great way to start building NAnt .build files. Without having to look through the NAnt documentation all the time, NAntPad has a list of available tasks. This functionality allows users to quickly see the options available for each task and build targets and projects that are syntactically correct.

Figure 4-5. NAntPad.

[View full size image]

NAntMenu Shell Extension


If you spend a majority of your time creating NAnt build files, you may want to use this Windows Explorer Shell extension (Figure 4-6). NAntMenu (http://taschenorakel.de/mathias/nantmenu.enl) will give you quick actions to perform on a .build NAnt file. The extension automatically queries the build file for available targets and lists them for you to run. By following the instructions in the Readme file, you can go into the Folder Options and File Types of Windows Explorer for build files and add an edit action. This action will launch any application you browse to on your file system. A good suggestion would be a favorite text editor or NAntPad.

Figure 4-6. NAntMenu.

[View full size image]

Visual Studio.NET 2003


Visual Studio.NET 2003 is unfortunately not Open Source but is incredibly extensible. One of the extensibility features of VS.NET is that you can define new schemas and use them in an editor with complete intellisense. If you place an XSD file in the C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml directory, then you can use it in an XML file, and Visual Studio.NET will not only validate it but also will give you nice intellisense for that file. First, though, you have to add the namespace to the XML file so that Visual Studio knows which XSD Schema file to use. You do this by adding the xmlns=" in the root of node of the XML file. In Figure 4-7, you can see this in action; the root node of the XML file being edited looks like this:

<project name="GetOpenSourceProjects" default="dotnetprojects" xmlns="http://nant
.sourceforge.net/schema/ ">

Figure 4-7. Visual Studio.NET NAnt Schema.

[View full size image]

If you want to be sure you are always in sync with the latest NAnt offerings, then you can download the schema at http://nant.sf.net/schema, or you can use the <nantschema> task:

<nantschema output="c:\Program Files\Microsoft Visual Studio. NET 2003\Common7\Packages
\schemas\xml\nant-current.xsd" target-ns="http://nant.sourceforge.net/schema/"/>

This will create the file correctly for you. Be sure to change the path if you are using a version other than Visual Studio.NET 2003. I hope soon that NAntContrib tasks will also be supported!


    / 275