visual-studiomsbuildvisual-studio-2017microsoft-ajax-minifier

Visual Studio 2017 not loading AjaxMin MSBuild Task from specified path


I'm attempting update an existing application so that it will load in Visual Studio 2017 (Enterprise - V15.2 (26430.12)) from Visual Studio 2015 (Enterprise) and having issues with the AjaxMin build task.

In Visual Studio 2015, the AjaxMin build task is found in C:\Program Files (x86)\MSBuild\Microsoft\MicrosoftAjax. Visual Studio 2017 looks for it in C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft. Given that all developers on the team may not have VS2017 Enterprise and we've had issues in the past with developers installing the wrong version, I'd like to have it use the AjaxMin NuGet package referenced in the solution.

There are 3 projects in the solution that use the AjaxMin task. I've updated all of them to have the following import:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
...
<Import Project="$(MSBuildProjectDirectory)\..\..\..\packages\AjaxMin.5.14.5506.26202\tools\net40\AjaxMin.targets" />
<Target Name="BeforeBuild">
  <ItemGroup>
    <JS Include="..." Exclude="..." />
  </ItemGroup>
  <ItemGroup>
    <CSS Include="..." Exclude="..." />
  </ItemGroup>
  <AjaxMin Switches="..." JsSourceFiles="@(JS)" JsCombinedFileName="..." CssSourceFiles="@(CSS)" CssCombinedFileName="..." />
</Target>
...
</Project>

However, when the build happens, I receive an error saying it can't find the AjaxMin task in the default build extensions directory:

The "AjaxMin" task could not be loaded from the assembly C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\MicrosoftAjax\AjaxMinTask.dll. Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\MicrosoftAjax\AjaxMinTask.dll' 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.

I've used the MSBuild Message Task to output the path and verified that it is correct by navigating to it from the command prompt. I also tried using the UsingTask with no luck there.

Why is Visual Studio not looking for the AjaxMin DLL in the location I specified?

Update: I moved the import tag for AjaxMin to the top (right under the project tag) and it works now. I don't understand why.


Solution

  • The issue turned out being another import for another third party build task. It appears that build task alters the build process such that the AjaxMin build task won't work after it. Having the AjaxMin build task after the Microsoft.CSharp.Targets import but before the other third party build task did the trick.