Question

In the documentation for WebGrease, it talks about using an MSBuild task to do minification at build time. However, when I add the task to my project file, it fails.

Here are the lines I've added to my project

  <UsingTask TaskName="WebGreaseTask" AssemblyName="WebGrease, Version=1.6.5135.21930, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"/>
  <Target AfterTargets="DotLessBuildTasksDotNet" Name="Minify">
    <WebGreaseTask />
  </Target>

But when I try to build, I get the following error:

The "WebGreaseTask" task could not be loaded from the assembly WebGrease, Version=1.6.5135.21930, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL. Could not load file or assembly 'WebGrease, Version=1.6.5135.21930, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. Confirm that the 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.

As far as I know, that's the correct assembly name, as I'm using the same reference in my project:

<Reference Include="WebGrease, Version=1.6.5135.21930, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\packages\WebGrease.1.6.0\lib\WebGrease.dll</HintPath>
</Reference>

And all of the code there is working fine.

I want to do the minification at compile time, which I believe is the purpose of the build task. I know there are a plethora of bundling and minification helpers out there, but I'd like to avoid pulling in more packages than I have to.

Edit:

I've tried the various NuGet commands, but those don't affect the UsingTask node in any way, and don't cause the build to work either. Still at a loss on this error.

Was it helpful?

Solution

Looking in the source code there is a class https://webgrease.codeplex.com/SourceControl/latest#WebGrease/WebGrease.Build/WebGreaseTask.cs which looks like the thing you need, but after decompiling my local WebGrease nuget package, I don't see this class or WebGrease.Build assembly there at all. As the error points out it can't find a class that implements ITask and this class exactly implements it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top