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

2024-03-08

能够在本地构建应用程序,但是当我尝试在 azure Devops 管道中构建时。它显示以下错误

我已经安装了实体框架并在 Web 配置文件中添加了 system.data.entity.design 程序集。不走运

请在此处查找管道 https://i.stack.imgur.com/jN0NM.png

NuGet 恢复任务 https://i.stack.imgur.com/IBBS8.png

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\1\s\webapp\Websites\packages与 Nuget.config 中定义的位置相同..\packages

In the 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 Build 任务中显示的这些消息,您可以看到它正在文件夹路径下查找包位置..\ThirdParty\NuGetPackages。正常情况下,该路径由<HintPath>... </HintPath>.

现在,很容易知道导致的错误:构建期间找到的包位置与其实际包恢复位置不匹配Nuget restore task.

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


为了解决这个问题,有两种解决方案。

  • 在 Visual Studio 中重新安装包

运行以下命令重新安装所有软件包 https://learn.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages, 就这样HintPath可以全部改成默认位置吗..\packages\...,可以与 Nuget.config 中的定义同步。

Update-Package -reinstall

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

执行该命令后,HintPath应该看起来像这样:

  • 修改Nuget.config file

第二个解决方案的逻辑是修改包位置定义 https://learn.microsoft.com/en-us/nuget/release-notes/nuget-2.1#specify-packages-folder-location in Nuget.config文件。使其与同步HintPath,此时恢复的包的位置将与构建时包的位置相同。

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

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

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

希望这可以帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在azure devops中构建asp.net应用程序 的相关文章

随机推荐