Menu

#38 Add support for ASP.NET MVC Razor .cshtml files

v1.59
closed
nobody
None
1
2023-05-10
2013-04-09
No

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.

Discussion

  • Al Danial

    Al Danial - 2013-04-10

    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.

     
  • Al Danial

    Al Danial - 2013-04-10
    • status: open --> accepted
     
  • Alexander van Trijffel

    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!

     
    • Anonymous

      Anonymous - 2013-04-10

      Hmm, something went wrong with the formatting.

      For HTML, code is commented out by opening @* and closing *@ markers.

      Alexander

       
  • Al Danial

    Al Danial - 2013-04-22
    • status: accepted --> pending
     
  • Al Danial

    Al Danial - 2013-04-22

    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.

     
  • Alexander van Trijffel

    Can you help me with an exe file for Windows for commit 330 so that i can test it?

     
  • Al Danial

    Al Danial - 2013-04-26

    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).

     
  • Anonymous

    Anonymous - 2013-04-26

    I have tested it with all Razor variations for razor code and comments and the new feature works flawlessly. Many thanks!

     
  • Al Danial

    Al Danial - 2013-08-21
    • status: pending --> closed
     
  • Al Danial

    Al Danial - 2013-08-21

    in released version 1.60

     
  • Anonymous

    Anonymous - 2021-02-19
    Post awaiting moderation.

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.