首页 > 解决方案 > Azure Devops 服务管道构建失败。通过 Visual Studio 和 msbuild 命令提示符成功构建

问题描述

我有两个针对 .Net Framework 4 的项目的解决方案。该解决方案在 Visual Studio 2015 和 2017 以及 msbuild 命令行中成功构建。

但是,当它使用代理规范 vs2015-win2012r2 在 Azure DevOps Pipeline 中构建时,第一个项目失败并出现以下错误。NuGet 还原步骤显示它成功安装了 NuGet EntityFramework 5.0 包。

The type or namespace name 'Infrastructure' does not exist in the namespace 'System.Data.Entity' (are you missing an assembly reference?)
The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DbModelBuilder' could not be found (are you missing a using directive or an assembly reference?)

当我将代理规范更改为 vs2017-win2016 时,第一个项目构建没有错误,但第二个项目失败并出现以下错误:

The type or namespace name 'Description' does not exist in the namespace 'System.Web.Http' (are you missing an assembly reference?)
The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)
Error CS0234: The type or namespace name 'Http' does not exist in the namespace 'System.Net' (are you missing an assembly reference?)

我确实在包含 System.Web.Http.dll 的 csproj 文件中引用了 NuGet 包 Microsoft.Asp.Net.WebApi.Core.4.0.20710.0。


我已经打开了调试选项。以下是 NuGet 还原日志的链接https://drive.google.com/open?id=1lJWflXTjYTN_MQyLOnwMUr-8LKoR5JRo

和构建日志 https://drive.google.com/open?id=1ypAVWxniDLfBOBHc4gODdAoQOCQnphYg

标签: azure-devops

解决方案


根据您的日志,有一条警告消息。

warning MSB3267: The primary reference "System.Net.Http", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "System.Net.Http" or retarget your application to a framework version which contains "System.Net.Http". 

在本地机器上执行命令以及在代理上运行构建或发布时,一些差异是有效的。如果代理配置为在 Linux、macOS 或 Windows 上作为服务运行,则它不会在交互式登录会话中运行。如果没有交互式登录会话,则存在 UI 交互和其他限制。微软提供了一些故障排除步骤。

有一个简单的方法可以尝试解决错误。删除项目引用下的引用,然后再次将其重新添加。该引用是对解决方案的本地项目中的命名空间的引用。由于某种原因,它在本地找到,但在签入并在 VSTS 上构建时未找到。


推荐阅读