Add support for ASP.NET MVC Razor .cshtml files
Brought to you by:
alnd
First of all, thanks for the excellent tool cloc. I am using it frequently to analyse solutions.
Currently only .asax and .aspx files are counted for the ASP.NET language. Since a couple years ASP.NET MVC Razor became very popular for ASP.NET programming. With Razor, the file extensions for ASP.NET are .asax and .cshtml. It would be great if .cshtml files are counted also by cloc.
For an overview of the cshtml file specification refer to http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx.
Anonymous
The Introducing "Razor" article at the link you point to makes no mention of special comment markers for cshtml so I'll implement the cshtml counter using standard HTML comments.
Razor does have special comment markers. For HTML, code is commented out by opening @ and closing @ markers. The code below shows all possible code comment styles within a cshtml file.
@{
// This is a Razor code block
/* Which also supports this style of comments */
ViewBag.Title = "Customers";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@* This is commented out HTML and C#
The version: @VersionResolver.Version *@
Thanks for adding this feature!
Hmm, something went wrong with the formatting.
For HTML, code is commented out by opening @* and closing *@ markers.
Alexander
svn commit 330 associates the cshtml extension with the language Razor, and Razor's comment definitions are the came as C++'s, with the addition of
@ .. @. I'd appreciate it if you'd test it out for me though.
Can you help me with an exe file for Windows for commit 330 so that i can test it?
I've attached an executable of the latest svn version. Please rename the file to cloc.exe to make it useful (I abbreviated the extension to try to avoid problems with some download filters).
I have tested it with all Razor variations for razor code and comments and the new feature works flawlessly. Many thanks!
in released version 1.60