WebGrease是mvc4中的一个程序集,但它可以像Yahoo.Yui.Compressor一样使用吗?我想在C#控制台程序中使用webgrease.dll,并将一个javascript字符串压缩成另一个。
class Program
{
static void Main(string[] args)
{
Yahoo.Yui.Compressor.JavaScriptCompressor c = new Yahoo.Yui.Compressor.JavaScriptCompressor();
string s = "function hello (name) { return 'hello '+ name + '!'; }";
s = c.Compress(s);
Console.WriteLine(s);
}
}发布于 2014-03-20 14:57:48
这是可能的,也是相当容易的。您可以在Visual Studio文件夹中找到WG.EXE。WG.EXE实际上是调用相同缩减库的命令行缩减器。您可以从命令行、MSBuild或您选择的任何脚本中使用它来执行缩减。
这是WG团队写的一篇关于如何从命令行使用WG的好文章:https://kenhaines.net/webgrease-as-seen-in-visual-studio-2012/
您也可以查看https://webgrease.codeplex.com/documentation
获取详细信息
发布于 2014-02-21 13:13:27
这应该是可能的-当你使用NuGet包含webgrease时,你也会得到"WG“命令行工具,它完全可以完成上面你想要完成的任务。webgrease dll和WG实用程序的代码可以在CodePlex上找到。其中没有特定的ASP.Net dll引用。
如果你有ILSpy或Reflector,看看"WebGrease.Program.ProcessJsFileSet“的代码,看看如何压缩Javascript。在CodePlex上也可以看到WebGrease.Activities.MinifyJSActivity类的用法。
https://stackoverflow.com/questions/21925218
复制相似问题