2011-09-15 53 views
0

使用下面的MSBuild配置:的MSBuild /的YUICompressor錯誤

<?xml version="1.0" encoding="utf-8"?> 
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003"> 

    <UsingTask 
     TaskName="CompressorTask" 
     AssemblyFile="Yahoo.Yui.Compressor.dll" /> 

    <PropertyGroup> 
     <JavaScriptOutputFile Condition=" '$(JavaScriptOutputFile)'=='' ">..\..\site.se\javascript\javascript.min.js</JavaScriptOutputFile> 
    </PropertyGroup> 

    <Target Name="CompressorTask"> 
     <ItemGroup> 
      <JavaScriptFiles Include="..\..\site.se\javascript\javascript.js"/> 
     </ItemGroup> 
     <CompressorTask 
      JavaScriptFiles="@(JavaScriptFiles)" 
      ObfuscateJavaScript="True" 
      PreserveAllSemicolons="True" 
      DisableOptimizations="False" 
      EncodingType="utf-8" 
      DeleteJavaScriptFiles="false" 
      LineBreakPosition="-1" 
      JavaScriptOutputFile="$(JavaScriptOutputFile)" 
      LoggingType="HardcoreBringItOn" 
      ThreadCulture="en-us" 
      IsEvalIgnored="false" /> 
    </Target> 

</Project> 

我得到以下錯誤:

Scripts.xml(14,11): error MSB4067: -element under -element is unknown. (translated from swedish)

我使用的MSBuild的32位.NET 2.0版本。

怎麼了?

回答

1

您不能將ItemGroup放入MSBuild for .NET 2的目標中。您必須使用CreateItem任務或將其放在目標之外。在你的情況下,你似乎不需要動態創建JavaScriptFiles項目,所以你只需要把它放在目標之外。


<ItemGroup> 
    <JavaScriptFiles Include="..\..\site.se\javascript\javascript.js"/> 
    </ItemGroup> 

    <Target Name="CompressorTask"> 
    <CompressorTask 
     JavaScriptFiles="@(JavaScriptFiles)" 
     ObfuscateJavaScript="True" 
     PreserveAllSemicolons="True" 
     DisableOptimizations="False" 
     EncodingType="utf-8" 
     DeleteJavaScriptFiles="false" 
     LineBreakPosition="-1" 
     JavaScriptOutputFile="$(JavaScriptOutputFile)" 
     LoggingType="HardcoreBringItOn" 
     ThreadCulture="en-us" 
     IsEvalIgnored="false" /> 
    </Target> 

使用CreateItem

<Target Name="CompressorTask"> 
    <CreateItem Include="..\..\site.se\javascript\javascript.js"> 
     <Output TaskParameter="Include" ItemName="JavaScriptFiles"/> 
    </CreateItem> 

    <CompressorTask 
     JavaScriptFiles="@(JavaScriptFiles)" 
     ObfuscateJavaScript="True" 
     PreserveAllSemicolons="True" 
     DisableOptimizations="False" 
     EncodingType="utf-8" 
     DeleteJavaScriptFiles="false" 
     LineBreakPosition="-1" 
     JavaScriptOutputFile="$(JavaScriptOutputFile)" 
     LoggingType="HardcoreBringItOn" 
     ThreadCulture="en-us" 
     IsEvalIgnored="false" /> 
    </Target>