Nitriq is a product by

Nitriq Console Edition

Screenshot of the Console Edition output

Nitriq Console Edition for automated build servers is the easiest way for you to enforce coding standards throughout your organization.

With Nitriq Console Edition, you will define all the queries important to your organization's coding standards. After every check-in to your automated build server, Nitriq Console Edition will perform code review and report whether any of your rules have been broken. The report is clean and easy to read and generated automatically for you. You simply add a task to your continuous integration build to launch Nitriq Console Edition with the a couple parameters, specifying the location of your project, your queries and where you want the output file to be saved.

Nitriq Console Edition also comes with a Pro Developer Edition license. The included Pro Developer Edition gives you all the tools you need to set up your project and write your own Linq queries.

Download It Now

Getting Started with Nitriq Console Edition

Step 1

Install the Nitriq Console Edition onto your build server. The most current version of Nitriq can be found on the on the download page.

Step 2

Copy your Nitriq license files (*.license) into the installation directory. Your install directory should look like the following:

Screenshot of the Console Edition output

Step 3

Nitriq Console Edition is not a stand-alone application. It complements the Developer Edition, bringing the power of Nitriq queries to the command line. Before running Nitriq Console Edition, you will first create a Nitriq Project using the Nitriq Developer Edition that was added to your build server during installation. Once you save a Nitriq project from the Developer Edition and export your Nitriq queries, you're ready to run Nitriq Console Edition from the command line.

Step 4

To run Nitriq Console Edition, open a command prompt and use the following command syntax:

path\to\Nitriq.Console.exe path\to\Nitriq_project_file.nitriqProj path\to\Nitriq_query_file.nq path\to\output_document.html

The three required parameters are as follows:

1) The path to the Nitriq project file (*.nitriqProj)
2) The path to the Nitriq query file (*.nq)
3) The path to the HTML output file (the file will be created if it does not exist at the specified path).

The default installation directory for Nitriq Console Edition on a 32-bit operating system is "C:\Program Files\Nitriq Console + Pro\".
For a 64-bit operating system (used in this example), the default install path is "C:\Program Files (x86)\Nitriq Console + Pro\".

For example, I created a Nitriq project called sample.nitriqProj and saved it to My Documents. After changing the current directory to My Documents, my command looked like this:

"C:\Program Files (x86)\Nitriq Console + Pro\Nitriq.Console.exe" sample.nitriqProj myQueries.nq output.html

Step 5

Once Nitriq Console Edition has finished running (it may take a few seconds to complete), you can check the output HTML file to see the results of the queries.

Step 6

Clicking on any link will take you to a summary of the executed query and its results. For example, I clicked on “Types to Refactor” since I saw that a warning was thrown on that query:

Results of Types to Refactor query

Incorporating Nitriq Console Edition on your Automated Build Server

Now that the basics of Nitriq Console Edition have been covered, here is an example of integrating Nitriq into a continuous integration process. This example uses a basic ASP.NET Web Application created in Visual Studio 2008 and NAnt as the project build tool. You can download the example here.

Step 1

Open up the Nitriq Developer Edition application ([install location]\Nitriq.exe), select “New” and find the DLL that was created after building the Web Application:

Select the project DLL in the Assembly Picker

Step 2

Click “Analyze” in the Assembly Picker dialog so that Nitriq Developer Edition can load the application into the Nitriq Project. Once Nitriq finished analyzing the assembly, add any queries you wish and then proceed to save the project as well as the queries. To do so, click “Save” and choose a location to store the .nitriqProj file (this example used {project base directory}\Nitriq\):

Save the Nitriq project

Step 3

To save the queries, click “Export Queries” in Nitriq Developer Edition and chose a location to store the .nq file (again, this example used {project base directory}\Nitriq\):

Save the Nitriq queries

Step 4

You can now exit Nitriq Developer Edition once you have saved everything. If you desire, you can copy the Nitric.Console.exe and the corresponding license file into the application:

The contents of the Nitriq folder in the example project

Step 5

The next step is to set up Nitriq Console in NAnt. In this example, the NAnt files are in the util folder and the project.build configuration file is in the base directory. The project.build file for NAnt that has two targets: Build and RunNitriqConsole. Taking a look at the project.build file shows how simple it is to include Nitriq as a part of your NAnt build process:

<target name="RunNitriq">
    <echo message="Running Nitriq Console application" />
    <exec
     program="Nitriq\Nitriq.Console.exe"
     commandline="Nitriq\example.nitriqProj Nitriq\queries.nq Nitriq\output.html"
     timeout="30000"
     failonerror="true"
     resultproperty="returnCode">
    </exec>
    <fail if="${returnCode != '0'}" message="${returnCode}" />
</target>

Simply add a new target that has a path to the Nitriq Console executable and the appropriate command line parameters that were detailed in the first tutorial. Nitriq Console Edition will return a value of zero when all queries succeed without error.

Step 6

Executing the RunNitriqConsole target (path\to\NAnt.exe RunNitriqConsole) with the basic queries results in the following:

Compile:
 
     [echo] Building Application
     [echo] Location: D:\WebApplication1\src\WebApplication1.sln
 
Clean:
 
     [exec] Microsoft (R) Build Engine Version 3.5.30729.4926
     [exec] [Microsoft .NET Framework, Version 2.0.50727.4927]
     [exec] Copyright (C) Microsoft Corporation 2007. All rights reserved.
 
Rebuild:
 
     [exec] Microsoft (R) Build Engine Version 3.5.30729.4926
     [exec] [Microsoft .NET Framework, Version 2.0.50727.4927]
     [exec] Copyright (C) Microsoft Corporation 2007. All rights reserved.
 
RunNitriq:
 
     [echo] Running Nitriq Console application
     [exec] Nitriq Analysis Completed with Analysis Errors
 
BUILD FAILED
 
D:\WebApplication1\project.build(24,4):
External Program Failed: D:\WebApplication1\Nitriq\Nitriq.Console.exe (return code was 1)

It appears that at least one of the queries failed, causing NAnt to fail the build. Looking at the Nitriq output file (output.html in our case), we can see that two tests failed: “Collections should implement generic interface” and “Enum storage should be Int32”:

Output from first run of Nitriq Console Edition

Step 7

Since our project does not currently use any Collection variables (i.e. IEnumerable) or any enums, we can safely remove these queries without affecting the coverage quality of the Nitriq queries. For the sake of this tutorial, the two failing queries were commented out using Nitriq Developer Edition:

//"Collections should implement generic interface" query
 
/*
var iEnumOfT = Types.FullNameIs("System.Collections.Generic.IEnumerable`1").FirstOrDefault();
var ienumerable = Types.FullNameIs("System.Collections.IEnumerable").FirstOrDefault();
IEnumerable results = null;
if (ienumerable != null)
{
    results = 
    from type in ienumerable.DerivedTypes
    where !type.Interfaces.Contains(iEnumOfT) && type.IsInCoreAssembly
    select new { type.TypeId, type.Name, type.FullName };
}
Warn(results, 0);
*/
 
var results = new int[]{};

A simple short-circuit of setting “results” to an empty array will allow the test to pass. We can always re-enable the query by removing the comment marks. However, it is also easy in Nitriq to maintain several query files (*.nq). We could simply create a new Nitriq query file without the unnecessary queries - the choice is yours.

Step 8

After removing these two unnecessary queries, running NAnt with the RunNitriqConsole target again results in the following:

Compile:
 
     [echo] Building Application
     [echo] Location: D:\WebApplication1\src\WebApplication1.sln
 
Clean:
 
     [exec] Microsoft (R) Build Engine Version 3.5.30729.4926
     [exec] [Microsoft .NET Framework, Version 2.0.50727.4927]
     [exec] Copyright (C) Microsoft Corporation 2007. All rights reserved.
 
Rebuild:
 
     [exec] Microsoft (R) Build Engine Version 3.5.30729.4926
     [exec] [Microsoft .NET Framework, Version 2.0.50727.4927]
     [exec] Copyright (C) Microsoft Corporation 2007. All rights reserved.
 
RunNitriq:
 
     [echo] Running Nitriq Console application
     [exec] Nitriq Analysis Completed
 
RunNitriqConsole:
 
 
BUILD SUCCEEDED
 
Total time: 8.2 seconds.

Success! As you can see, all of the Nitriq queries ran without error because NAnt reported a good build.