Azure DevOps找不到已还原的NuGet软件包。

3

我为一个C#项目创建了构建流程。

我引用了不同的nuget包,例如Entity Framework和一些位于feed中的自己的包。

本地整个解决方案可以成功构建和运行。

在构建流程中,nuget restore也能够正常工作。但是构建失败了,因为它找不到nuget包。

这种情况发生在像Entity Framework这样的公共包以及来自我的feed的包中。

nuget版本:

  • 检测到的NuGet版本为 4.1.0.2450 / 4.1.0

我尝试了不同的构建版本、构建代理或创建了自己的nuget.config文件。

我还卸载了nuget包,删除了所有引用并重新安装了每个包。

例如:

##[error]paybla.Repository.EntityFramework\RepositoryBase.cs(3,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
RepositoryBase.cs(3,19): error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) [d:\a\3\s\paybla.Repository.EntityFramework\paybla.Repository.EntityFramework.csproj]
##[error]paybla.Repository.EntityFramework\UnitOfWorkBase.cs(3,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
UnitOfWorkBase.cs(3,19): error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) [d:\a\3\s\paybla.Repository.EntityFramework\paybla.Repository.EntityFramework.csproj]
##[error]paybla.Repository.EntityFramework\UnitOfWorkBase.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?)
UnitOfWorkBase.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?) [d:\a\3\s\paybla.Repository.EntityFramework\paybla.Repository.EntityFramework.csproj]
##[error]paybla.Repository.EntityFramework\UnitOfWorkBase.cs(5,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
UnitOfWorkBase.cs(5,19): error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) [d:\a\3\s\paybla.Repository.EntityFramework\paybla.Repository.EntityFramework.csproj]
##[error]paybla.Repository.EntityFramework\UnitOfWorkBase.cs(6,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
UnitOfWorkBase.cs(6,19): error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) [d:\a\3\s\paybla.Repository.EntityFramework\paybla.Repository.EntityFramework.csproj]
##[error]paybla.Repository.EntityFramework\RepositoryBase.cs(11,26): Error CS0246: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?)
RepositoryBase.cs(11,26): error CS0246: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) [d:\a\3\s\paybla.Repository.EntityFramework\paybla.Repository.EntityFramework.csproj]
##[error]paybla.Repository.EntityFramework\UnitOfWorkBase.cs(15,26): Error CS0246: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?)
UnitOfWorkBase.cs(15,26): error CS0246: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) [d:\a\3\s\paybla.Repository.EntityFramework\paybla.Repository.EntityFramework.csproj]
##[error]paybla.Repository.EntityFramework\UnitOfWorkBase.cs(157,19): Error CS0246: The type or namespace name 'IDbSet<>' could not be found (are you missing a using directive or an assembly reference?)
UnitOfWorkBase.cs(157,19): error CS0246: The type or namespace name 'IDbSet<>' could not be found (are you missing a using directive or an assembly reference?) [d:\a\3\s\paybla.Repository.EntityFramework\paybla.Repository.EntityFramework.csproj]
Done Building Project "d:\a\3\s\paybla.Repository.EntityFramework\paybla.Repository.EntityFramework.csproj" (default targets) -- FAILED.

在构建流水线中,NuGet还原正在工作。它是“working”(正在工作),还是“succeeding”(成功)?这两件事情并不相同;即使构建活动没有按照您的期望执行,它也可能会成功。请查看还原日志。它是否正在还原所有软件包?是否有任何警告? - Daniel Mann
这是一个非常好的答案!实际上,我在日志中没有看到任何恢复的软件包。我不知道为什么我没有注意到这个。。配置链接: http://und-dann-los.de/wp-content/uploads/2019/06/Unbenannt.png日志结束时说:packages.config 中列出的所有软件包都已安装。老实说..我不知道问题出在哪里。 - Andre Fritzsche
使用您自己的构建代理来重现问题,然后您可以进入实际的工作目录进行进一步分析。在互联网上讨论这样的问题太过宽泛。 - Lex Li
你是在使用 Nuget Restore 还是 dotnet restore? - Nirav Mistry
2个回答

1
请尝试检查您是否已将\packages文件夹添加到源代码控制中,如果是,请从源代码控制中删除整个\packages文件夹以查看是否可以解决此问题。

0
可能与你的情况无关,但有时候(特别是当允许 R# 引用缺失包时),csproj 文件可能会包含对本地驱动器上程序集的引用 - 类似于这样。
<ItemGroup>
  <Reference Include="name">
    <HintPath>../../your/local/path</HintPath>
  </Reference>
</ItemGroup>

删除所有这样的节点,然后通过NuGet UI手动添加包,在我的情况下有所帮助。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接