Google Closure MSBuild任务错误

时间:2010-08-30 10:53:26

标签: javascript compression google-closure

我正在尝试在MSBuild文件中编写自定义任务,以使用Google Closure Compiler压缩一些js文件。我从站点下载了ClosureCompiler.dll和ClosureCompiler.tasks文件,并将它们保存在我的m / c上的文件夹中。我在csproj文件中添加了以下行

<Import Project="C:\Projects\Closure\ClosureCompiler.tasks" />
<Target Name="AfterBuild">
    <ItemGroup>
        <JS Include="test.js" />
    </ItemGroup>
    <ClosureCompiler CompilationLevel="SIMPLE_OPTIMIZATIONS" SourceFiles="@(JS)" SourceExtensionPattern="\.js$" TargetExtension=".min.js" />
</Target>

test.js文件保存在项目文件的根目录下。我不想包含可选的ApiUrl,因为我想使用ClosureCompiler.dll在本地压缩文件。 ClosureCompiler.tasks文件是

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

然而,当我尝试编译项目时,它给了我一个错误:

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

任何人都可以帮助解决问题或我做错了什么?

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,这是自定义任务代码中的一个错误。这是因为API返回错误,并且自定义代码未检查API是否返回错误。

会检查

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

如果没有名为compiledCode的节点,那将抛出一个对象而不是.InnerText的引用。您需要先检查响应中的错误。

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

答案 1 :(得分:1)

转到

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

看看你是否可以粘贴“任何东西”。你可能已达到每小时限制。如果上述情况发生并导致错误,VS2010将抛出此消息。所以...这是导致它的一件事。