开发者

Google Closure MSBuild Task Error

I am trying to write a custom task in my MSBuild file to compress some js files with Google Closure Compiler. I downloaded the ClosureCompiler.dll and ClosureCompiler.tasks files from the site and have kept them in a folder on my m/c. I added the below lines in my csproj file

<Import Project="C:\Projects\Closure\ClosureCompiler.tasks" />
<Target Name="AfterBuild">
    <ItemGroup>
        <JS Include="test.js" />
    </ItemGroup>
    <ClosureCompiler CompilationLevel="SIMPLE_OPTIMIZATIONS" Sou开发者_运维知识库rceFiles="@(JS)" SourceExtensionPattern="\.js$" TargetExtension=".min.js" />
</Target>

The test.js file is kept on the root of my project files. I do not want to include the optional ApiUrl since I want to compress files locally using ClosureCompiler.dll. The ClosureCompiler.tasks file is

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <UsingTask TaskName="ClosureCompiler" AssemblyFile="C:\Projects\Closure\ClosureCompiler.dll" /> 
</Project>

However when I try to compile the project, it gives me an error:

Compilation Failed: test.js, Reason: Object reference not set to instance of an object

Can anyone help as to what is the issue or what am I doing wrong?


I ran into the same issue and it is a bug in the custom task code. It is because the API is returning an error and the custom code is not checking to see if the API returns an error.

It will check

compiledSource.SelectSingleNode("//compileCode").InnerText

That will throw an object not reference for .InnerText if there is no node named compiledCode. You need to check for errors in the response first.

if (compiledSource.SelectSingleNode("//error") != null)
    throw new Exception(compiledSource.SelectSingleNode("//error").InnerText);


Go to

http://closure-compiler.appspot.com/home

And see if you can paste "Anything" in. You may have reached your hourly limit. VS2010 WILL throw this message if the aforementioned happens and causes an error. So...it is One thing that will cause it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜