2010-08-30 99 views
0

我想在我的MSBuild文件中編寫一個自定義任務,以使用Google Closure Compiler壓縮一些js文件。我從網站上下載了ClosureCompiler.dll和ClosureCompiler.tasks文件,並將它們保存在我的m/c上的一個文件夾中。我在我的csproj文件中添加了下面幾行Google Closure MSBuild任務錯誤

<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 

誰能幫助至於是什麼問題,或者我在做什麼錯?

回答

1

我遇到了同樣的問題,它是自定義任務代碼中的錯誤。這是因爲API正在返回錯誤,並且自定義代碼未檢查API是否返回錯誤。

它會檢查

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

這將拋出.InnerText對象不能引用,如果沒有名爲compiledCode節點。您需要首先檢查響應中的錯誤。

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

轉到

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

,看看你是否可以粘貼到 「任何東西」。你可能已經達到了每小時的限制。如果上述情況發生並且導致錯誤,VS2010將會拋出此消息。所以......有一件事會導致它。