msbuild
msbuild copied to clipboard
Better error when UsingTask Reference Include is empty
<Project>
<UsingTask
TaskName="WriteAttributes"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<Task>
<Reference Include="$(CppCodeProvider)" />
<Code Type="Class" Language="cs">
<![CDATA[
public class WriteAttributes : Task
{
public override bool Execute()
{
return true;
}
}
]]>
</Code>
</Task>
</UsingTask>
<Target Name="Build">
<WriteAttributes />
</Target>
</Project>
The error isn't great here:
Team triage: Let's re-phrase the message. Seems quite repetitive.
While looking into this issue, bug #10389 was found.
@baronfel would you like to suggest a better error message when UsingTask Reference Include is empty?
The problem is that Include is required for the Reference element here, but it evaluated to empty?
UsingTask'sReferencecannot be empty, but was set to$(CppCodeProvider)which evaluated to empty.
Template:
(Task)'s (Metadata) cannot be empty, but was set to (UnEvaluatedItemSpec) which evaluated to empty.
CodeTaskFactory claims The "Include" attribute has been set even if the attribute has not been set at all. In this case, there wouldn't be an UnEvaluatedItemSpec for the task factories to log.
Adapted from https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2022:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This simple inline task does nothing. -->
<UsingTask
TaskName="DoNothing"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup />
<Task>
<Reference />
<Using Namespace="" />
<Code Type="Fragment" Language="cs">
</Code>
</Task>
</UsingTask>
<Target Name="first">
<DoNothing/>
</Target>
</Project>
MSBuild version 17.10.4+10fbfbf2e for .NET Framework
Build started 21.8.2024 18.02.58.
Project "[REDACTED]\gug.proj" on node 1 (default targets).
[REDACTED]\gug.proj(16,5): error MSB3752: The "Include" attribute has been set but is empty. If the "Include" attribute is set it must not be empty.
[REDACTED]\gug.proj(16,5): error MSB4036: The "DoNothing" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64" directory.
Done Building Project "[REDACTED]\gug.proj" (default targets) -- FAILED.
Build FAILED.
"[REDACTED]\gug.proj" (default target) (1) ->
(first target) ->
[REDACTED]\gug.proj(16,5): error MSB3752: The "Include" attribute has been set but is empty. If the "Include" attribute is set it must not be empty.
[REDACTED]\gug.proj(16,5): error MSB4036: The "DoNothing" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the
"C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64" directory.
0 Warning(s)
2 Error(s)
RoslynCodeTaskFactory in .NET SDK 9.0.100-preview.7.24407.12 (MSBuild 17.12.0.37402) likewise:
gug failed with 2 error(s) (0,1s)
[REDACTED]\gug.proj(16,5): error MSB3752: The "Include" attribute of the <Reference> element has been set but is empty. If the "Include" attribute is set it must not be empty.
[REDACTED]\gug.proj(16,5): error MSB4036: The "DoNothing" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\Program Files\dotnet\sdk\9.0.100-preview.7.24407.12" directory.
Build failed with 2 error(s) in 0,2s