首页 文章

Jenkins / .net核心2.0 / ubuntu缺少程序集

提问于
浏览
0

我用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 Main App / 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 Main App / MySolution.Common / MySolution.Common.csproj] 16:32:27 Security / Decorators / ForbiddenResult.cs(5,28):错误CS0234:类型或命名空间名称名称空间“Microsoft.AspNetCore”中不存在“Mvc”(您是否缺少程序集引用?)[/ var / lib / jenkins / workspace / MySolution Main App / MySolution.Common / MySolution.Common.csproj] 16:32 :27 Security / Decorators / GroupMemberAttribute.cs(3,28):错误CS0234:名称空间“Microsoft.AspNetCore”中不存在类型或命名空间名称“Mvc”(您是否缺少程序集引用?)[/ var / lib / jenkins / workspace / MySolution Main App / MySolution.Common / MySolution.Common.csproj] 16:32:27 Services / Impl / TokenManagementService.cs(10,14):error CS0234:类型或命名空间名称'IdentityModel'确实命名空间'System'中不存在(你是否缺少程序集引用?)[/ var / lib / jenkins / workspace / MySolution Main App / MySolution.Common / MySolution.Common.csproj] 16:32:27 Services / Impl / TokenManagem entService.cs(12,17):错误CS0234:命名空间“Microsoft”中不存在类型或命名空间名称“IdentityModel”(您是否缺少程序集引用?)[/ var / lib / jenkins / workspace / MySolution Main App / MySolution.Common / MySolution.Common.csproj] 16:32:27 Security / Decorators / ForbiddenResult.cs(9,33):错误CS0246:找不到类型或命名空间名称'IActionResult'(你错过了吗? using指令或程序集引用?)[/ var / lib / jenkins / workspace / MySolution Main App / MySolution.Common / MySolution.Common.csproj] 16:32:27 Security / Decorators / 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 Security / Decorators / GroupMemberAttribute.cs(53,32):错误CS0246:找不到类型或命名空间名称'ActionExecutedContext'(您是否缺少using指令或程序集引用?)[/ var / lib /詹金斯/工作区/ MySolutionMain 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

1 回答

  • 1

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

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

    HOW TO CORRECT

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

    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
    

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

    我希望这可以节省一些人花费我的时间 .

相关问题