msbuild
msbuild copied to clipboard
Task factories Shows Misleading Errors When Failing on internal operations
Issue Description
Found in https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1272722
Building a project that uses a task factory that fails to parse its input, the error reported is misleading. See below for the error. It should be something like "TaskFactory Failed: {stack-trace-etc}".
Steps to Reproduce
Build a project/xaml file like so:
project.proj
<Project>
<Target Name="Entry">
<CudaCompile ToolExe="cmd.exe"/>
</Target>
<UsingTask TaskName="CudaCompile" TaskFactory="XamlTaskFactory" AssemblyName="Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Task>Test.xaml</Task>
</UsingTask>
</Project>
test.xaml
<ProjectSchemaDefinitions xmlns=`clr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Framework` xmlns:x=`http://schemas.microsoft.com/winfx/2006/xaml` xmlns:sys=`clr-namespace:System;assembly=mscorlib` xmlns:impl=`clr-namespace:Microsoft.VisualStudio.Project.Contracts.Implementation;assembly=Microsoft.VisualStudio.Project.Contracts.Implementation`>
<Rule Name=`CL`>
<EnumProperty Name=`GeneratePreprocessedFile` Switch=`nologo`>
<EnumValue Name=`Disabled` />
<EnumValue Name=`Yes` Switch=`P` />
<EnumValue Name=`NoLineNumbers` Switch=`EP` />
</EnumProperty>
</Rule>
</ProjectSchemaDefinitions>
Expected Behavior
Error saying the task factory itself failed on the backticks existing in the xaml file.
Actual Behavior
We get both "taskfactory couldn't be loaded" and "
Build started 5/6/2021 2:11:30 PM.
Project "C:\src\issues\cudaproject\project.proj" on node 1 (default targets).
C:\src\issues\cudaproject\project.proj(3,5): error MSB4175: The task factory "XamlTaskFactory" could not be loaded
from the assembly "Microsoft.Build.Tasks.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
'`' is an unexpected token. The expected token is '"' or '''. Line 1, position 33.
Done Building Project "C:\src\issues\cudaproject\project.proj" (default targets) -- FAILED.
Build FAILED.
Analysis
The error suggests the task factory was found just fine, but there was an error while parsing the xaml to create the task.
Versions & Configurations
msbuild --version
Microsoft (R) Build Engine version 16.10.0-dev-21205-01+86be06394 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
16.10.0.20501
Notes
Does this also happen with other TaskFactory
classes?
Saw this when working with the roslyn task factory.
To repro: Create an inline task with any compiler error.
Team Triage: We should consider changing the error message when an internal error in the factory comes up.
That message should specifically not say "could not be loaded". Loaded is misleading, especially when it's a compiler error that happened when compiling within the factory.