Showing posts with label website. Show all posts
Showing posts with label website. Show all posts

Wednesday, June 17, 2015

Minify CSS and JS files through PowerShell scripts

The below scripts can be used in scenarios where you need to minify CSS and JavaScript files of your website using PowerShell Scripts. (For example, during Post-build PowerShell scripts in TFS build).

Pre-requisite:
Microsoft Ajax Minifier should be installed on the machine (or TFS build server) where the PowerShell scripts would be executing.
Ajax Minifier can be downloaded from here.

PowerShell scripts to minify CSS files in a directory:

function applyCssMinification($dir)
{
$Minifier = “C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier\AjaxMin.exe”
get-childitem $dir -recurse -force -include *.css -exclude *.min.css | foreach-object {&$Minifier $_.FullName -out $_.FullName -clobber}

}

PowerShell scripts to minify JavaScript files in a directory:

function applyJsMinification($dir)
{
$Minifier = “C:\Program Files (x86)\Microsoft\Microsoft Ajax Minifier\AjaxMin.exe”
get-childitem $dir -recurse -force -include *.js -exclude *.min.js | foreach-object {&$Minifier $_.FullName -out $_.FullName -clobber}
}

Once defined call these functions by providing CSS and JS directory path as a parameter:

For example,

applyCssMinification "$Env:TF_BUILD_SOURCESDIRECTORY\Website\Content\CSS"


applyJsMinification "$Env:TF_BUILD_SOURCESDIRECTORY\Website\Content\Scripts"

Friday, April 18, 2014

How to disable generating .PDB files while compiling .NET assembly/ website in Release mode

While compiling your .NET assembly or publishing ASP.NET or MVC project in Release mode, you may observe .pdb file also gets generated along with necessary .dll or supporting files.
PDB file contains debugging information and symbol which does not make any sense during deployment or release of a product.
In order to get rid of generating PDB files during publish/ build -
1. Open the project properties of a project in Visual Studio
2. Click on "Build" tab
3. Make sure the configuration selected is "Release"
4. Click on "Advanced" button
5. Select "none" in "Debug Info" selection box.
6. Click OK, and save the project
Try building the project, and you will not see PDB files.

Screenshots: