无法在 azure devops 中构建 asp.net 应用程序

unable to build a asp.net app in azure devops

能够在本地构建应用程序,但是当我尝试在 azure devops 中构建时 pipeline.It 显示以下错误

我已经安装了 EntityFramework 并且在 webconfig 中添加了 system.data.entity.design 程序集 file.No luck

Please find pipeline here

NuGet Restore task

webapp\CaseDatabase.DataAccess\CaseAssignmentModule\CaseQueueDbAdapter.cs(10,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\CaseAssignmentModule\HoursEstDbAdapter.cs(4,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\CasesModule\CaseWorkflowDbAdapter.cs(2,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\ClientsAndContactsModule\ContactDefaultsDbAdapter.cs(5,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\ClientsAndContactsModule\InstructionLibraryDbAdapter.cs(4,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\DBEntityCoreModel\CaseDatabaseContext.cs(2,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\DBEntityCoreModel\ICaseDatabaseContext.cs(2,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\DBEntityCoreModel\ICaseDatabaseContext.cs(3,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\DBEntityCoreModel\ICaseDatabaseContext.cs(4,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
webapp\CaseDatabase.DataAccess\EntityRepository.cs(4,17): Error CS0234: The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

根据@Stella分享的构建日志,这个错误信息应该是包恢复路径导致的。

首先,通过Nuget restore任务恢复相关包全部成功。而且,所有需要的包都已恢复。它恢复的文件夹位置是 D:\a\s\webapp\Websites\packages 与 Nuget.config ..\packages

中定义的位置相同

Visual Studio Build 日志中,有以下消息:

Considered "..\ThirdParty\NuGetPackages\EntityFramework.6.1.2\lib\net45\EntityFramework.dll", but it didn't exist.
***
***
Considered "..\ThirdParty\NuGetPackages\EntityFramework.6.1.2\lib\net45\EntityFramework.SqlServer.dll", but it didn't exist.
***
***
***

根据 Visual Studio 构建任务中显示的这些消息,您可以看到它正在寻找文件夹路径 ..\ThirdParty\NuGetPackages 下的包位置。通常,此路径由 <HintPath>... </HintPath>.

控制

现在,很容易知道错误原因:在构建过程中找到的包位置与它在 Nuget restore 任务中实际包恢复的位置不匹配。

正常情况下,其默认位置应为..\packages\...,与Nuget.config中定义的默认位置相同。我假设它的本地回购路径应该永远改变,那么它在 csproj 文件中定义的 HintPath 也会自动改变。但是,在Nuget.config,它的包默认位置仍然保持默认。这将导致当包恢复时,它遵循 Nuget.config 中定义的位置。但是在构建期间,由于它查找具有 csproj ... 定义的包,构建无法知道实际包恢复的位置。然后导致这些错误信息。


要解决此问题,有 2 个解决方案。

  • 在 Visual Studio
  • 中重新安装软件包

运行下面的命令到reinstall all of packages,这样HintPath就可以全部改成默认位置..\packages\...,可以与Nuget.config中定义同步.

Update-Package -reinstall

此解决方案的逻辑是撤销 HintPath 作为默认位置,因此它可以与 Nuget.config 中的定义保持同步。

执行完命令后,HintPath应该和下面的一样:

  • 修改Nuget.config文件

第二个解决方案的逻辑是 modify the package location definitionNuget.config 文件中。使其与HintPath同步,此时恢复包的位置将与构建时包的位置相同。

将以下脚本添加到 Nuget.config 文件中:

<configuration>
  <config>
    <add key="repositoryPath" value="xxxx" />
  </config>
  ... 
</configuration>

只需尝试一种解决方案,然后在本地构建 Visual Studio。成功后,再push到Azure Devops中,用之前相同的任务配置构建,use nuget, nuget restore, VS build, publish artifacts.

希望这对您有所帮助。