4

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.

Jacob Maki
  • 366
  • 3
  • 11

3 Answers3

4

I resolved this issue by installing the .Net 3.5 framework

cixelsyd
  • 938
  • 10
  • 12
Shawn Chen
  • 41
  • 3
1

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.

Jacob Maki
  • 366
  • 3
  • 11
0

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

If I understand your question correctly, that is because you have two reference sources for the AjaxMinTask.dll, one is the default assembly source:C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\MicrosoftAjax, another is the import reference, you will notice that the AjaxMinTask.dll is used in the AjaxMin.targets:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<UsingTask AssemblyFile="AjaxMinTask.dll" TaskName="AjaxMin" /> 
<UsingTask AssemblyFile="AjaxMinTask.dll" TaskName="AjaxMinBundleTask" />
<UsingTask AssemblyFile="AjaxMinTask.dll" TaskName="AjaxMinManifestTask" />
<UsingTask AssemblyFile="AjaxMinTask.dll" TaskName="AjaxMinManifestCleanTask" />

 ...
</Project>

So when set the import reference behind your task, MSBuild will use the default assembly source (under the VS2017 installation directory), when you set the import reference before you task, the AjaxMin.targets will rewrite the path of reference source.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • In both the non working project file and the working project file, the import of the targets file happens before the task. The only other import that changes between the working and non working project file is that in the working project file, the `AjaxMin` import happens before the `Microsoft.CSharp.Targets`. Maybe that could be related? The only other things in the project file between the working and non working import locations are your standard `PropertyGroup`s and `ItemGroups` – Jacob Maki Jun 05 '17 at 14:40
  • I did a diff between the `Microsoft.CSharp.Targets` in C:\Program Files (x86)\MSBuild\14.0\Bin\ versus C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin. The only difference was related to cross targeting (which I'm not doing). That said, the `Microsoft.CSharp.Targets` file imports a lot of other files which could be the cause... – Jacob Maki Jun 05 '17 at 14:57