【问题标题】:Jenkins/ .net core 2.0/ ubuntu missing assembliesJenkins/.net core 2.0/ubuntu 缺少程序集
【发布时间】:2018-05-02 07:02:23
【问题描述】:

我用 Jenkins、nodejs 和 .net core 2.0 设置了一个 ubuntu 16.04 机器,然后尝试让它构建我的 .net core 2.0 Web 应用程序。它失败并显示以下消息:

16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): 警告 MSB3245:无法解析此引用。找不到 程序集“Microsoft.AspNetCore.Authorization”。检查以确保 该程序集存在于磁盘上。如果您需要此参考 代码,你可能会得到编译错误。 [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): 警告 MSB3245:无法解析此引用。找不到 程序集“Microsoft.AspNetCore.Mvc.Abstractions”。检查制作 确保程序集存在于磁盘上。如果需要此参考 你的代码,你可能会得到编译错误。 [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): 警告 MSB3245:无法解析此引用。找不到 程序集“Microsoft.IdentityModel.Tokens”。检查以确保 程序集存在于磁盘上。如果您的代码需要此参考, 你可能会得到编译错误。 [/var/lib/jenkins/workspace/MySolution 主应用程序/MySolution.Common/MySolution.Common.csproj] 16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): 警告 MSB3245:无法解析此引用。找不到 程序集“System.IdentityModel.Tokens.Jwt”。检查以确保 程序集存在于磁盘上。如果您的代码需要此参考, 你可能会得到编译错误。 [/var/lib/jenkins/workspace/MySolution 主应用程序/MySolution.Common/MySolution.Common.csproj] 16:32:27 安全/装饰器/ForbiddenResult.cs(5,28):错误 CS0234:类型 或命名空间名称“Mvc”在命名空间中不存在 'Microsoft.AspNetCore'(您是否缺少程序集参考?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 安全/装饰器/GroupMemberAttribute.cs(3,28):错误 CS0234: 命名空间中不存在类型或命名空间名称“Mvc” 'Microsoft.AspNetCore'(您是否缺少程序集参考?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Services/Impl/TokenManagementService.cs(10,14):错误 CS0234:类型 或命名空间名称“IdentityModel”在命名空间中不存在 “系统”(您是否缺少程序集参考?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Services/Impl/TokenManagementService.cs(12,17):错误 CS0234:类型 或命名空间名称“IdentityModel”在命名空间中不存在 'Microsoft'(您是否缺少程序集参考?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 安全/装饰器/ForbiddenResult.cs(9,33):错误 CS0246:类型 或找不到命名空间名称“IActionResult”(您是否缺少 using 指令或程序集引用?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 安全/装饰器/ForbiddenResult.cs(18,40):错误 CS0246:类型 或找不到名称空间名称“ActionContext”(您是否缺少 using 指令或程序集引用?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/GroupMemberAttribute.cs(8,51):错误 CS0246: 找不到类型或命名空间名称“IActionFilter”(您是 缺少 using 指令或程序集引用?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/GroupMemberAttribute.cs(33,33):错误 CS0246: 找不到类型或命名空间名称“ActionExecutingContext” (您是否缺少 using 指令或程序集引用?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 安全/装饰器/GroupMemberAttribute.cs(53,32):错误 CS0246: 找不到类型或命名空间名称“ActionExecutedContext”(是 您缺少 using 指令或程序集引用?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/GroupMemberAttribute.cs(58,24):错误 CS0246: 找不到类型或命名空间名称“ActionExecutingContext” (您是否缺少 using 指令或程序集引用?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj]

在我的开发机器上,我环顾四周,找不到这些程序集,但我肯定在引用它们,所以我猜它们藏在某个公共位置。

我需要做什么才能让 Jenkins 找到所有引用的程序集并成功构建我的项目?我在网上看到的所有文档似乎都引用了 .net core 1.0 或 1.1,现在看来很多这些东西都不同了。

我的构建步骤非常简单(只有一个)。要做的脚本:

dotnet clean
dotnet restore
dotnet build

【问题讨论】:

  • 您能分享一下您在 Jenkins 构建步骤中的内容吗?

标签: c# jenkins asp.net-core continuous-integration


【解决方案1】:

所以事实证明这是一个错误(可能是 ReSharper 的错误),如果您第一次在项目的解决方案中引用库,并自动更新引用,则引用不会完全正确添加; IOW,MySolution.Common 项目没有将依赖程序集显式添加到项目文件中,即使它们是解决方案的一部分并且可用。

在我的开发机器上,这并不重要; Visual Studio 能够很好地找到依赖项。然而,在我的构建服务器上,这是缺少的一条关键信息。

如何改正

如果我们看一下第一个错误:

16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.AspNetCore.Authorization". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj]

...我们可以看到在构建MySolution.Common项目时出现了问题,缺少的程序集是Microsoft.AspNetCore.Authorization

有两种方法可以完成这项工作。一种是手动编辑 .csproj 文件。如果您在PackageReference ItemGroup 中添加该行,如下所示:

<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="2.0.1" />

...问题(对于缺少的参考)将消失。这就是我最初所做的,并且它有效,但后来我发现我可以通过简单地转到我的包管理控制台并执行以下操作来做到这一点而不会弄乱该文件:

cd MySolution.Common
dotnet add reference Microsoft.AspNetCore.Authorization

...这会将它与正确的版本和所有内容一起正确添加到项目文件中,所以我认为这是一个更好的方法。

我希望这可以节省我花费的时间。

【讨论】:

  • 感谢您 - 我们通过删除不可靠的引用(在我们的案例中为 Microsoft.IdentityModel.Tokens 和 System.IdentityModel.Tokens.Jwt)并通过包管理器添加所需的 nuget 包来纠正了类似的问题.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-28
  • 1970-01-01
  • 2019-03-29
  • 1970-01-01
  • 1970-01-01
  • 2018-12-13
  • 2018-01-24
相关资源
最近更新 更多