The "translate" Microsoft Ajax Minifier Quick Use Guide (with VS integration) compiles the project's JS or CSS files directly after compiling

Source: Internet
Author: User

Online looking for a long time finally found a can with VS integration use JS and CSS compression tool, because afraid to forget, so to forward over, by the way, the university when learning English basically has been back to the teacher, so the translation is not very good, but can read, right?

Original address: Http://www.asp.net/ajaxlibrary/AjaxMinQuickStart.ashx

One, use in the command line

After the download installation completes the Microsoft Ajax Minifier, you can use it in a command way. Click Start-All Programs-Microsoft Ajax Minifier-Microsoft Ajax minifier Command Prompt, enter the filename (including the file directory) and the file name to output in the window that opens. For example: "ajaxmin test.js-o test.min.js" and then enter, the Microsoft Ajax Minifier gives a compression rate and generates a new compressed file.

Similarly, CSS files can be compressed using the same commands.

Execution effect

Ii. integration with Visual Studio (VS)

After consolidating Microsoft Ajax Minifier in VS, each time the project is built, it will automatically generate a compressed version of all the JS files and CSS files.

Use the following steps:

1. In VS, click "Tools"--"options"--"projects and solutions"--check "Always show solution"

2. Right-click the current solution and select "Uninstall Project"

3. Right click on the project you just uninstalled, select "Edit *.csproj" and:

4. Add the following code before the </Project> tag:

<import project= "$ (msbuildextensionspath) \microsoft\microsoftajax\ajaxmin.tasks"/>
<target name= "Afterbuild" >
<ItemGroup>
<js include= "**\*.js" exclude= "**\*.min.js; Scripts\*.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 ">
</AjaxMin>
</Target>

These codes represent the import of a custom MSBuild named Ajaxmin. Its main task is to compress all JavaScript and CSS files in the project, all JS files and CSS files will be renamed to *.min.js and *.min.css.

5. Right-click your solution and select Reload Project.

After completing these steps, each time the project is built, all JS and CSS files in the project will be compressed and a. Min.js (CSS) file is generated, and of course, if you need to display these compressed files in your project, you will need to select the "Show All Files" option in your project

Third, use the Microsoft Ajax Minifier in the source code controller

Because these compressed files are files that are output in a build operation, it is recommended that you treat these compressed files as if they were other vs auto-generated files, and do not include them in the VS project, and do not use source code manager.

If you include these compressed files in your project, and you use source code Manager to manage them, you will face some trouble. When you check out these files from Source Manager, their properties are read-only, so when you try to build the operation again, Microsoft Ajax Minifier generates an "attempt to write a read-only file" error.

Original address: http://blog.sina.com.cn/s/blog_4c19412f010176hm.html

The "translate" Microsoft Ajax Minifier Quick Use Guide (with VS integration) compiles the project's JS or CSS files directly after compiling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.