来自 Azure DevOps Build 的错误:无法找到程序集 "System.ComponentModel.Annotations"

An error from Azure DevOps Build: Could not locate the assembly "System.ComponentModel.Annotations"

我有一个引用 System.ComponentModel.Annotations 的 netstandard 2.0 项目。它在我的本地计算机上构建良好,但是当我尝试使用 Azure DevOps 管道构建它时,出现以下错误:

...warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.ComponentModel.Annotations". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/home/vsts/work/1/s/src/MyProj/MyProj.csproj]

...MyProj/MyClass.cs(2,29): error CS0234: The type or namespace name 'DataAnnotations' does not exist in the namespace 'System.ComponentModel' (are you missing an assembly reference?) [/home/vsts/work/1/s/src/MyProj/MyProj.csproj]

错误是不言自明的,我明白它说的是什么,但问题是我应该如何解决它以满足 Azure DevOps 构建?

发现问题。我应该安装 System.ComponentModel.Annotations NuGet package.

,而不是在我的项目依赖项中引用 System.ComponentModel.Annotations

我安装了包,Azure DevOps Build 成功构建了项目。