Moslem Ben Dhaou
Moslem Ben Dhaou

Reputation: 7005

How to automatically remove HTML comments in Release mode?

I am trying to find a way to automatically remove HTML comments in release mode for two main reasons

I am using ASP.NET MVC and looking for something in the same spirit as the bundling and minification features.

Upvotes: 4

Views: 2153

Answers (2)

Jay Douglass
Jay Douglass

Reputation: 4918

Use Razor server side comments

@*
This is a server side 
multiline comment 
*@

Upvotes: 12

Schadensbegrenzer
Schadensbegrenzer

Reputation: 950

If you are familiar with build scripts that is what I would recommend. I also use build scripts for deployment, web.config modification, creating backups etc...

Check this link. It explains how to modify a xml file during build: http://www.federicosilva.net/2013/02/msbuild-in-line-task-to-modify-file.html

You can also write an own task quite easily.

public class HtmlSanitizingTask : ITask
{
    [Required]
    public string FilePath { get; set; }

    public bool Execute()
    {
        //ToDo: Implement HTML Sanitizing here
        return true;
    }

    public IBuildEngine BuildEngine { get; set; }
    public ITaskHost HostObject { get; set; }
}

Build it and reference the DLL from a build script.

<UsingTask TaskName="MyNamespace.HtmlSanitizingTask" AssemblyName="MyNamespace.dll" />

And then call the operation

<MyNamespace.HtmlSanitizingTask FilePath="filepathHere" />

I hope it helps :)

Upvotes: 2

Related Questions