3

I use Asp.net 4 C# and MicrosoftAjax Minifier.

Please look at my code here; Using <Target Name="AfterBuild"> I'm able to minify all files .js and .css. The problem is that this code minify even the original files in my project solution, so would be almost impossible to edit theme once again.

I need instead minify all .js and .css on my solution after publishing it to a local folder.

In this way I can keep my original files in my project folder intact and have instead the site compiled and minified into another local folder.

I change my scripting using <Target Name="Publish">, I do not receive any error but It does not work.

Could you tell me what I'm missing here, and if there is a better approach to solve this problem? Thanks

<!-- Minify all JavaScript files that were embedded as resources -->
<Import Project="$(MSBuildExtensionsPath)\Microsoft\MicrosoftAjax\ajaxmin.tasks" />
<Target Name="Publish">
    <ItemGroup>
        <JS Include="**\*.js" Exclude="**\*.min.js;Scripts\*.js" />
    </ItemGroup>
    <ItemGroup>
        <CSS Include="**\*.css" Exclude="**\*.min.css" />
    </ItemGroup>
    <AjaxMin
        JsSourceFiles="@(JS)"  JsSourceExtensionPattern="\.js$" JsTargetExtension=".js"
        CssSourceFiles="@(CSS)" CssSourceExtensionPattern="\.css$" CssTargetExtension=".css"  />
</Target>
7
  • Just a guess, having never used MSAjax to minify, but shouldn't the target filenames include .min so you don't overwrite the source files? eg. JsTargetExtension=".min.js" and CssTargetExtension=".min.css" ? Commented Oct 19, 2011 at 10:36
  • VS do not let me publish the file with extension .min.js, for this reason I wrote this question. Commented Oct 19, 2011 at 10:38
  • at the moment I'm using also a version with -min.css and -min.js, this allowed be to have file automatically published, but I think it is not a clean solution plus I have to change the path for my resources. Commented Oct 19, 2011 at 10:40
  • This article on the MS Ajax site shows how to do this: asp.net/ajaxlibrary/ajaxminquickstart.ashx Commented Oct 19, 2011 at 10:43
  • 1
    Does this article help? (sorry, it's big) stackoverflow.com/questions/5043504/… Commented Oct 19, 2011 at 10:58

1 Answer 1

3

(copied from questions)

To deal with losing the original js/css files, ensure the target filenames include .min, eg. JsTargetExtension=".min.js" and CssTargetExtension=".min.css". See article on using MsAjax minifier: http://www.asp.net/ajaxlibrary/ajaxminquickstart.ashx

To then be able to publish the minified files, see this article: Using Microsoft AJAX Minifier with Visual Studio 2010 1-click publish

At my workplace, we are solving the minifying issue quite differently by using Chirpy addin for Visual Studio. It automatically minifies files to a .min version upon saving. See http://chirpy.codeplex.com/

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks wil for your answer, interesting app chirpy I will have a look for sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.