Msbuild: Failure using 16.0 RoslynCodeTaskFactory

Created on 22 May 2019  路  2Comments  路  Source: dotnet/msbuild

While running on AppVeyor and also on Azure Pipelines, MSBuild downloaded from the latest .NET Core SDK release from the 2.2 channel fails using a RoslynCodeTaskFactory task.

MSBuild project file

RoslynCodeTaskFactory.proj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 
  xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- This simple inline task displays "Hello, world!" -->
  <UsingTask TaskName="HelloWorld" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
    <ParameterGroup />
    <Task>
      <Reference Include="System.Xml"/>
      <Using Namespace="System"/>
      <Using Namespace="System.IO"/>
      <Code Type="Fragment" Language="cs">
        <![CDATA[  
// Display "Hello, world!"  
Log.LogError("Hello, world!");  
]]>
      </Code>
    </Task>
  </UsingTask>
  <Target Name="Hello">
    <HelloWorld />
  </Target>
</Project>

Build script

PowerShell commands to download, install and run MSBuild from .NET Core

Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -OutFile 'dotnet-install.ps1'
& ./dotnet-install.ps1 -Channel 2.2
& dotnet --version
& dotnet msbuild -version
& dotnet msbuild -t:Hello RoslynCodeTaskFactory.proj -bl:MSBuild.RoslyCodeTaskFactory.binlog

Failure

.\RoslyCodeTaskFactory.proj(20,5): error MSB3755: Could not find reference "System.Xml". If this reference is required by your code, you may get compilation errors.
.\RoslyCodeTaskFactory.proj(20,5): error MSB4175: The task factory "RoslynCodeTaskFactory" could not be loaded from the assembly "C:\Users\appveyor\AppData\Local\Microsoft\dotnet\sdk\2.2.204\Microsoft.Build.Tasks.Core.dll". The task factory must return a value for the "TaskType" property.

This seems to be a regression of https://github.com/microsoft/msbuild/issues/3726. I have also tried using MSBuild shipped with .NET Core 3.0 Preview 5, but it fails with the same error.

Test repository: https://github.com/couven92/roslyncodetaskfactory-helloworld

Attached MSBuild binlog and project file: RoslyCodeTaskFactory.zip

Most helpful comment

Appearently this issue goes away if you remove the <Reference Include="System.Xml"/> tag in the task.

All 2 comments

The same failure occurs when using the macOS-10.13 or VS2017-Win2016 images on Azure Pipelines. (Download and install using the UseDotNet@2 and DotNetCoreCLI@2 tasks as shown)

azure-pipelines.yml

jobs:
- job: Mac
  pool:
    vmImage: 'macOS-10.13'
  steps:
  - task: UseDotNet@2
    inputs:
      packageType: sdk
      version: 2.2.x
  - task: DotNetCoreCLI@2
    inputs:
      command: custom
      projects: RoslynCodeTaskFactory.proj
      custom: msbuild
      arguments: -t:Hello -bl:$(Build.ArtifactStagingDirectory)/MSBuild.RoslyCodeTaskFactory.binlog
  - task: PublishBuildArtifacts@1
    condition: succeededOrFailed()
    inputs:
      pathtoPublish: $(Build.ArtifactStagingDirectory)
      artifactName: msbuild-binlog
      publishLocation: container
- job: Windows
  pool:
    vmImage: 'VS2017-Win2016'
  steps:
  - task: UseDotNet@2
    inputs:
      packageType: sdk
      version: 2.2.x
  - task: DotNetCoreCLI@2
    inputs:
      command: custom
      projects: RoslynCodeTaskFactory.proj
      custom: msbuild
      arguments: -t:Hello -bl:$(Build.ArtifactStagingDirectory)/MSBuild.RoslyCodeTaskFactory.binlog
  - task: PublishBuildArtifacts@1
    condition: succeededOrFailed()
    inputs:
      pathtoPublish: $(Build.ArtifactStagingDirectory)
      artifactName: msbuild-binlog
      publishLocation: container

Appearently this issue goes away if you remove the <Reference Include="System.Xml"/> tag in the task.

Was this page helpful?
0 / 5 - 0 ratings