msdeploy - Using Microsoft AJAX Minifier with Visual Studio 2010 1-click publish -
the microsoft ajax minifier provides build task can used in tfs or local build definitions.
i have succsfully used in both local project file (building seperate files) , in tfs build definitions (overwriting existing js files).
i'd move using visual studio 2010's 1-click publish feature rather tfs build definition, adding minification task afterbuild target in project file doesn't appear effect 1-click publish feature.
using information found in this thread , these articles, tried creating file named '[projectname].wpp.targets in wap root directory, , used following xml:
<project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <import project="$(msbuildextensionspath)\microsoft\microsoftajax\ajaxmin.tasks" /> <target name="minify" beforetargets="msdeploypublish"> <itemgroup> <js include="**\*.js" exclude="**\*.min.js;**\*vsddoc.js;**\*debug.js" /> </itemgroup> <itemgroup> <css include="**\*.css" exclude="**\*.min.css" /> </itemgroup> <ajaxmin jssourcefiles="@(js)" jssourceextensionpattern="\.js$" jstargetextension=".min.js" csssourcefiles="@(css)" csssourceextensionpattern="\.css$" csstargetextension=".min.css" /> </target> </project>
this doesn't appear have effect, , unfortunately visual studio doesn't give in way of feedback or debugging info these tools.
has had success minifying javascript / css using visual studio 2010 1-click publish feature?
i wrote detailed blog entry on how @ http://sedodream.com/2011/02/25/howtocompresscssjavascriptbeforepublishpackage.aspx , http://blogs.msdn.com/b/webdevtools/archive/2011/02/24/how-to-compress-css-javascript-before-publish-package.aspx.
here contents
today saw post on stackoverflow.com asking using microsoft ajax minifier visual studio 2010 1-click publish. response question. web publishing pipeline pretty extensive easy hook in in order perform operation such these. 1 of extension points, we’ve blogged before, creating .wpp.targets file. if create file in same directory of project name {projectname}.wpp.targets file automatically imported , included in build/publish process. makes easy edit build/publish process without having edit project file itself. use technique demonstrate how compress css & javascript files project contains before published/packaged.
eventhough question states microsoft ajax minifier decided use compressor contained in packer.net (link in resources section). did because when looked @ msbuild task ajax minifier didn’t control output location of compressed files. instead write same folder extension .min.cs or .min.js. in case, when publish/package web application project (wap) files copied temporary location before publish/package occurs. default value location obj{configuration}\package\packagetmp\ {configuration} build configuration using wap. need allow wpp copy files location , after can compress css , javascript goes in folder. target copies files location copyallfilestosinglefolderforpackage. (to learn more these targets take @ file %program files (x86)%\msbuild\microsoft\visualstudio\v10.0\web\microsoft.web.publishing.targets.) make our target run after target can use msbuild aftertargets attribute. project created demonstrate called compressbeforepublish, because of create new file named compressbeforepublish.wpp.targets contain changes.
<project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <usingtask taskname="smallsharptools.packer.msbuild.packer" assemblyfile="$(msbuildthisfiledirectory)..\contrib\smallsharptools.packer\smallsharptools.packer.dll" /> <!-- target run after files copied packagetmp folder --> <target name="compressjsandcss" aftertargets="copyallfilestosinglefolderforpackage"> <!-- discover files compress --> <itemgroup> <_javascriptfiles include="$(_packagetempdir)\scripts\**\*.js" /> <_cssfiles include="$(_packagetempdir)\content\**\*.css" /> </itemgroup> <message text="compressing javascript files" importance="high" /> <!-- compress javascript files. not usage of %(javascript.identity causes task run once per .js file in javascriptfiles item list. more info on batching: http://sedotech.com/resources#batching --> <packer inputfiles="%(_javascriptfiles.identity)" outputfilename="@(_javascriptfiles->'$(_packagetempdir)\scripts\%(recursivedir)%(filename)%(extension)')" mode="jsmin" verbose="false" condition=" '@(_javascriptfiles)' != ''" /> <message text="compressing css files" importance="high" /> <packer inputfiles="%(_cssfiles.identity)" outputfilename="@(_cssfiles->'$(_packagetempdir)\content\%(recursivedir)%(filename)%(extension)')" mode="cssmin" verbose="false" condition=" '@(_cssfiles)' != '' "/> </target> </project>
here i’ve created 1 target, compressjsandcss, , have included aftertargets=”copyallfilestosinglefolderforpackage” causes executed after copyallfilestosinglefolderforpackage. inside target 2 things, gather files need compressed , compress them.
1. gather files compressed
<itemgroup> <_javascriptfiles include="$(_packagetempdir)\scripts\**\*.js" /> <_cssfiles include="$(_packagetempdir)\content\**\*.css" /> </itemgroup>
here use item list both javascript files css files. notice using _packagetempdir property pickup .js & .css files inside temporary folder files written packaged. reason i’m doing instead of picking source files because build may outputting other .js & .css files , going published. note: since property _packagetempdir starts underscore not guaranteed behave (or exist) in future versions.
2. compress files
i use packer task compress .js , .css files. both sets of files usage pretty similar @ first usage.
<packer inputfiles="%(_javascriptfiles.identity)" outputfilename="@(_javascriptfiles->'$(_packagetempdir)\scripts\%(recursivedir)%(filename)%(extension)')" mode="jsmin" verbose="false" condition=" '@(_javascriptfiles)' != ''" />
here task fed .js files compression. take note how passed files task using, %(_javascriptfiles.identity), in case cause task executed once per .js file. %(abc.def) syntax invokes batching, if not familiar batching please see below. value of output file use _packagetempdir property again. in case since item resides there have simplified @(_javascriptfiles->’%(fullpath)’) thought might find expression helpful in case compressing files not exist in _packagetempdir folder.
now have added target .wpp.targets file can publish/package our web project , contained .js & .css files compressed. note: whenever modify .wpp.targets file have unload/reload web project changes picked up, visual studio caches projects.
in image below can see difference compressing these files made.
you can download entire project below, take @ other resources have might interested in.
resources
Comments
Post a Comment