Bug 56633 - CodeTaskFactory no longer exists in Microsoft.Build.Tasks.v4.0.dll
Summary: CodeTaskFactory no longer exists in Microsoft.Build.Tasks.v4.0.dll
Status: VERIFIED FIXED
Alias: None
Product: Tools
Classification: Mono
Component: msbuild ()
Version: unspecified
Hardware: PC Mac OS
: Highest critical
Target Milestone: 15.4
Assignee: Ankit Jain
URL:
Depends on:
Blocks:
 
Reported: 2017-05-18 17:58 UTC by Jonathan Pryor
Modified: 2017-09-04 11:26 UTC (History)
5 users (show)

Tags: Shiproom
Is this bug a regression?: Yes
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Jonathan Pryor 2017-05-18 17:58:03 UTC
The Microsoft.VSSDK.BuildTools NuGet package contains assemblies and MSBuild project files and targets to create Visual Studio .vsix files:

https://www.nuget.org/packages/Microsoft.VSSDK.BuildTools/

The `build/Microsoft.VSSDK.BuildTools.targets` file contains this XML fragment:

> <UsingTask TaskName="SetVsSDKEnvironmentVariables" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">

This fragment fails when running on Mono 5.2 (2017-04), *not* mono 5.0 (2017-02) or mono 4.8:

> error MSB4174: The task factory "CodeTaskFactory" could not be found in the assembly 
> "/Library/Frameworks/Mono.framework/Versions/5.2.0/lib/mono/msbuild/15.0/bin/Microsoft.Build.Tasks.v4.0.dll"

Simplified test case, courtesy Alexander Köplinger:

  <UsingTask TaskName="foo" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
     <ParameterGroup>
         <Text/>
     </ParameterGroup>
     <Task>
         <Code>
           Log.LogMessage(MessageImportance.High, Text);
         </Code>
     </Task>
  </UsingTask>
  <Target Name="BeforeBuild">
    <foo Text="Hello, World!" />
  </Target>
Comment 1 Luis Aguilera 2017-07-24 18:15:41 UTC
after discussing with Ankit, we've agreed this bug is best fixed in 15.4 given that it's not trivial and may require extensive testing.
Comment 2 Jon Douglas [MSFT] 2017-07-24 20:31:34 UTC
I can CONFIRM this issue using Jon P's basic repro in https://bugzilla.xamarin.com/show_bug.cgi?id=56633#c0

I have also identified that this happens in Mono 5.0.1, so it's likely this isn't an immediate regression.

I believe this is similar to the following:

https://stackoverflow.com/questions/31722877/cant-build-in-visual-studio-2015-because-microsoft-build-tasks-v14-0-dll-cann

In which a similar workaround could be used:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
<Choose>
  <When Condition="'$(MSBuildToolsVersion)'=='15.0'">
    <PropertyGroup>
      <TasksAssemblyName>Microsoft.Build.Tasks.Core</TasksAssemblyName>
    </PropertyGroup>
  </When>
  <Otherwise>
    <PropertyGroup>
      <TasksAssemblyName>Microsoft.Build.Tasks.v$(MSBuildToolsVersion)</TasksAssemblyName>
    </PropertyGroup>
  </Otherwise>
</Choose>
<UsingTask TaskName="foo" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\$(TasksAssemblyName).dll">
<ParameterGroup>
         <Text/>
     </ParameterGroup>
     <Task>
         <Code>
           Log.LogMessage(MessageImportance.High, Text);
         </Code>
     </Task>
  </UsingTask>
   <Target Name="BeforeBuild">
    <foo Text="$(MSBuildToolsPath)" />
  </Target>
</Project>

Either way, it looks like things were renamed and moved. Mono doesn't seem to reflect that compared to MSBuild on windows.