Getting errors when trying to build

Aug 20, 2012 at 8:54 PM

I believe I have followed the instructions on how to use the YUI compressor for .NET, but I keep getting an error that says it could not load CompressorTask.

error MSB4062: The "CompressorTask" task could not be loaded from the assembly C:\Project\src\Project.UI\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll.  Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask

Here is my relevant xml..

<UsingTask TaskName="CompressorTask" AssemblyFile="Project\src\Project.UI\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll" />

 

 <Target Name="Project" DependsOnTargets="Bridge;">

  <ItemGroup>
   <CssFiles Include="Project\src\Project.UI\Content\*.css" />

   <JavaScriptFiles Include="Project\src\Project.UI\Models\*.js" />
   <JavaScriptFiles Include="Project\src\Project.UI\Common\*.js" />
   <JavaScriptFiles Include="Project\src\Project.UI\Services\*.js" />
   <JavaScriptFiles Include="Project\src\Project.UI\ViewModels\*.js" />
   <JavaScriptFiles Include="Project\src\Project.UI\View\*.js" />
  </ItemGroup>
  <CompressorTask
            CssFiles="@(CssFiles)"
            DeleteCssFiles="false"
            CssOutputFile="Project\Scr\Project.UI\Content\css\Project.min.css"
            JavaScriptFiles="@(JavaScriptFiles)"
            JavaScriptOutputFile="Project\src\Project.UI\Scripts\Project.min.js"
            LoggingType="ALittleBit"
            />
 </Target>

Any suggetsions?

Thanks in advance,

Keith

Coordinator
Aug 21, 2012 at 11:01 PM
Hi,

If you are using the latest compressor code then the instructions are out of date - still a work in progress (eh PK? ;)).

The 2.x code base has separate CSS and JavaScript compressors, so the XML you quote will not work with that.
If you are using an older version, please state which one it is.

Your best bet is to download the latest source and build that and look at the samples.
If you run up the sample website, that has a page with some instructions on it, or just look at the build XML files.

On 21 Aug 2012, at 22:16, 94stangfan <notifications@codeplex.com> wrote:

From: 94stangfan

I believe I have followed the instructions on how to use the YUI compressor for .NET, but I keep getting an error that says it could not load CompressorTask.

error MSB4062: The "CompressorTask" task could not be loaded from the assembly C:\Project\src\Project.UI\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask

Here is my relevant xml..

<UsingTask TaskName="CompressorTask" AssemblyFile="Project\src\Project.UI\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll" />

<Target Name="Project" DependsOnTargets="Bridge;">

<ItemGroup>
<CssFiles Include="Project\src\Project.UI\Content\*.css" />

<JavaScriptFiles Include="Project\src\Project.UI\Models\*.js" />
<JavaScriptFiles Include="Project\src\Project.UI\Common\*.js" />
<JavaScriptFiles Include="Project\src\Project.UI\Services\*.js" />
<JavaScriptFiles Include="Project\src\Project.UI\ViewModels\*.js" />
<JavaScriptFiles Include="Project\src\Project.UI\View\*.js" />
</ItemGroup>
<CompressorTask
CssFiles="@(CssFiles)"
DeleteCssFiles="false"
CssOutputFile="Project\Scr\Project.UI\Content\css\Project.min.css"
JavaScriptFiles="@(JavaScriptFiles)"
JavaScriptOutputFile="Project\src\Project.UI\Scripts\Project.min.js"
LoggingType="ALittleBit"
/>
</Target>

Any suggetsions?

Thanks in advance,

Keith

Coordinator
Aug 21, 2012 at 11:56 PM

Keith, one other thing to add to what Freeranger said :

I noticed that all your 'paths' were like this... Project\src\....

What this means is that the library will look for those places from the -current- location where the .dll exists. So this means, if the dll is in the \bin directory .. then it will try and look for ...YourMainProjectFolder\TheProject\src\Project.UI\bin\Project\src\... etc.

Try using C:\YourMainProjectFolder\TheProject\src\Project.UI\..... etc...

Sep 19, 2012 at 11:15 PM

Hi,

I got the Yahoo.Yui.Compressor.Build.MsBuild.dll from NuGet. After compiling the project I see the following error

"D:\JsCssCompressor\JsCssCompressor\MsBuild\MsBuild.xml" (default target) (1) -
>
(MyTaskTarget target) ->
  D:\JsCssCompressor\JsCssCompressor\MsBuild\MsBuild.xml(76,5): error MSB4062:
The "CompressorTask" task could not be loaded from the assembly D:\JsCssCompres
sor\JsCssCompressor\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll.  Confirm that t
he <UsingTask> declaration is correct, that the assembly and all its dependenci
es are available, and that the task contains a public class that implements Mic
rosoft.Build.Framework.ITask.

My XML file is below

**********************************************
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003">
  <UsingTask TaskName="CompressorTask"
             AssemblyFile="D:\JsCssCompressor\JsCssCompressor\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll" />

  <Target Name="MyTaskTarget">
    <ItemGroup>
      <JavaScriptFiles Include="C:\Work\Purchase_Flow\eBizSol_App\Release\WebSites\Websites\McAfee.Consumer.Website\UIDesign\LegacySite\Scripts\FlexDashboard\AddDevice.js"/>
    </ItemGroup>
    <CompressorTask
        JavaScriptCompressionType="YuiStockCompression"
        JavaScriptFiles="@(JavaScriptFiles)"
        ObfuscateJavaScript="True"
        PreserveAllSemicolons="False"
        DisableOptimizations="Nope"
        EncodingType="Default"
        DeleteJavaScriptFiles="false"
        LineBreakPosition="-1"
        JavaScriptOutputFile="C:\Work\Purchase_Flow\eBizSol_App\Release\WebSites\Websites\McAfee.Consumer.Website\UIDesign\LegacySite\Scripts\FlexDashboard\MAA2.0.js"
        LoggingType="ALittleBit"
        ThreadCulture="en-us"
        IsEvalIgnored="false"
            />
  </Target>
</Project>

*********************************************

Any idea why I am getting the compilation error?.


Deepak

Coordinator
Sep 20, 2012 at 3:30 AM

Hi Deepakkb.

 

ok the first thing i want to confirm with you are these things :-

 

1. Are you sure the file is located at : D:\JsCssCompressor\JsCssCompressor\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll

2. What is the version of that file? Right click the file => properties =>Details

Sep 20, 2012 at 7:13 PM

I'm getting the same error...

Sep 20, 2012 at 7:16 PM

The file version for Yahoo.Yui.Compressor.Build.MsBuild is 2.0.0.0

Sep 20, 2012 at 10:17 PM

The MsBuild version is following: -

Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.269]
Copyright (C) Microsoft Corporation 2007. All rights reserved.

 

The sample project is in VS2010 and using .NET 4.0

Coordinator
Sep 21, 2012 at 7:55 AM

 

Looks like exactly the same problem 94stangfan had, who started this thread.  The documentation on this site is out of date - PureKrome is working on updating it,

In the mean time, download the latest source code and look at the example web project included in that.  This example works and, if you run it, the web page provides some documentation on how it works. 

Sep 21, 2012 at 1:48 PM

I could not download de example web project. My firewall said that there's a virus:

 

Accesss to the page has been denied 

because the following virus was detected 
Clamd: Heuristics.Broken.Executable

Coordinator
Sep 21, 2012 at 2:30 PM

Strange - there are no executables in the source code download....

Ok, look at this source file directly:

http://yuicompressor.codeplex.com/SourceControl/changeset/view/78915#1293368

Sep 21, 2012 at 5:59 PM

Hi freeranger,

After downloading the source code on my machine, when I run the following command, it works fine.

C:\Users\dbal.MCAFEE\Desktop\yuicompressor-78915\Documentation\MsBuild Example>m
sbuild.exe MsBuildSample.xml

The javascript and css files are getting compressed. I think the documentation needs to be updated on the web site about the msbuild.xml.

Deepak

Coordinator
Sep 21, 2012 at 6:58 PM

Thanks for letting us know that works for you.  We are aware the documentation needs to be sorted....

Feb 15, 2013 at 12:06 PM
Edited Feb 15, 2013 at 12:06 PM
I have installed the latest YUICompressor.NET and YUICompressor.NET.MSBuild and installed through the http://yuicompressor.codeplex.com/ and the xml file file is
  <?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003">
  <UsingTask
      TaskName="CompressorTask"
      AssemblyFile="..\..\lib\yui\Yahoo.Yui.Compressor.Build.MsBuild.dll" />


  <PropertyGroup>
    <JavaScriptOutputFile Condition=" '$(JavaScriptOutputFile)'=='' ">..\scripts-min\myfile.min.js</JavaScriptOutputFile>
  </PropertyGroup>


  <Target Name="MyTaskTarget">

    <ItemGroup>


<JavaScriptFiles Include="$(SourceLocation)..\scripts\myfile.js"/>



</ItemGroup>
<CompressorTask
    CssFiles="@(CssFiles)"
    DeleteCssFiles="false"
    CssOutputFile="$(CssOutputFile)"
    CssCompressionType="YuiStockCompression"
    JavaScriptFiles="@(JavaScriptFiles)"
    ObfuscateJavaScript="True"
    PreserveAllSemicolons="False"
    DisableOptimizations="Nope"
    EncodingType="Default"
    DeleteJavaScriptFiles="false"
    LineBreakPosition="-1"
    JavaScriptOutputFile="$(JavaScriptOutputFile)"
    LoggingType="ALittleBit"
    ThreadCulture="en-au"

            />
</Target>

</Project>
but it is still showing the error

Error 18 The "CompressorTask" task could not be loaded from the assembly D:\Projects\YUI....\lib\yui\Yahoo.Yui.Compressor.Build.MsBuild.dll. Could not load file or assembly 'Yahoo.Yui.Compressor, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null'or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Coordinator
Feb 15, 2013 at 12:26 PM
Hello,

It looks like you are trying to use the lastest code with an old version of an msbuild file.
Since 2.x, the compressor task has been broken out into separate css and javascript compressors - see the documentation pages or download samples for examples of how to use msbuild in 2.x versions of YUICompressor.Net

thanks
Feb 18, 2013 at 9:16 AM
Thanks for the reply. I have changed the xml file in the below format
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/MsBuild/2003">

  <UsingTask TaskName="CssCompressorTask" AssemblyFile="..\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll" />
  <UsingTask TaskName="JavaScriptCompressorTask" AssemblyFile="..\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll" />


  <PropertyGroup>
    <CSSOutputFile Condition=" '$(CSSOutputFile)'=='' ">..\Min\site.min.css</CSSOutputFile>

    <JavascriptOutputFile Condition=" '$(JavascriptOutputFile)'=='' ">..\Min\jquery.min.js</JavascriptOutputFile>
    
  </PropertyGroup>

  <Target Name="Minify">
  
    <ItemGroup>
   
      <CssFiles Include="..\Content\Site.css"/>
     
      <JavaScriptFiles Include="..\Scripts\jquery-1.6.2.js"/>
    </ItemGroup>

    <CssCompressorTask
          SourceFiles="@(CssFiles)"
          DeleteSourceFiles="false"
          OutputFile="$(CSSOutputFile)"
          CompressionType="Standard"
          LoggingType="Info"
          PreserveComments="false"
          LineBreakPosition="-1"
       />

  
 

    <JavaScriptCompressorTask
        SourceFiles="@(JavaScriptFiles)"
        DeleteSourceFiles="false"
        OutputFile="$(JavascriptOutputFile)"
        CompressionType="Standard"
        ObfuscateJavaScript="True"
        PreserveAllSemicolons="False"
        DisableOptimizations="No"
        EncodingType="Default"
        LineBreakPosition="-1"
        LoggingType="Info"
        ThreadCulture="en-au"
        IsEvalIgnored="false"
            />

 
  </Target>
</Project>
But it is showing the below error

The "JavaScriptCompressorTask" task could not be loaded from the assembly D:\Projects\YUI..\bin\Yahoo.Yui.Compressor.Build.MsBuild.dll. Could not load file or assembly 'Yahoo.Yui.Compressor, Version=2.2.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. D:\Projects\YUI\myfile.xml
Coordinator
Feb 18, 2013 at 9:26 AM
Hi pankajsaha,

I have a few questions - please answer them.
  1. The -exact- full path of where the xml file is located.
  2. The -exact- full path of where Yahoo.Yui.Compressor.Build.MsBuild.dll. is located
  3. The -exact- full path of the core Yahoo.Yui.Compressor dll
  4. The -exact- full path of where you are 'running' msbuild against that xml file.
cheers!
Feb 18, 2013 at 11:27 AM
I got the solution. Previously I have added the old versions and added only new version of Yahoo.Yui.Compressor.Build.MsBuild.dll. I have removed all the old version files and again added new versions and it is working fine. The files are added here are

EcmaScript.NET.dll
Iesi.Collections.dll
NAnt.Core.dll
Yahoo.Yui.Compressor.Build.MsBuild.dll
Yahoo.Yui.Compressor.dll

Thanks all :)