AppVeyor Octopack - GetAssemblyVersion 失败
Posted
技术标签:
【中文标题】AppVeyor Octopack - GetAssemblyVersion 失败【英文标题】:AppVeyor Octopack - Failing GetAssemblyVersion 【发布时间】:2017-11-29 17:13:33 【问题描述】:我有一个 asp.net core 2.0 网络应用程序。我正在尝试使用 AppVeyor 使用 octopack 构建 nuget 包,因此我们的 octopus 服务器可以处理我们的部署过程。
我的 appveyor.yml 文件中列出了以下步骤来执行 nuget 恢复和发布:
before_build:
- cmd: choco install octopustools
- cmd: nuget restore
- cmd: dotnet restore MyApp/MyApp.csproj
- cmd: dotnet publish MyApp/MyApp.csproj --output published-app --configuration=%CONFIGURATION%
- cmd: octo pack --id MyApp --version %APPVEYOR_BUILD_VERSION% --basePath MyApp/published-app
但是,当构建到达站点的dotnet publish
时,它会失败并出现以下错误:
dotnet publish MyApp/MyApp.csproj --output published-app --configuration=%CONFIGURATION%
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
SendGrid.NetCore -> C:\projects\MyApp\SendGrid.NetCore\bin\Release\netcoreapp2.0\SendGrid.NetCore.dll
MyApp -> C:\projects\MyApp\MyApp\bin\Release\netcoreapp2.0\MyApp.dll
C:\Users\appveyor.nuget\packages\octopack\3.6.3\build\OctoPack.targets(47,5): error MSB4018: The "GetAssemblyVersionInfo" task failed unexpectedly. [C:\projects\MyApp\MyApp\MyApp.csproj]
C:\Users\appveyor.nuget\packages\octopack\3.6.3\build\OctoPack.targets(47,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. [C:\projects\MyApp\MyApp\MyApp.csproj]
C:\Users\appveyor.nuget\packages\octopack\3.6.3\build\OctoPack.targets(47,5): error MSB4018: File name: 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' [C:\projects\MyApp\MyApp\MyApp.csproj]
C:\Users\appveyor.nuget\packages\octopack\3.6.3\build\OctoPack.targets(47,5): error MSB4018: at OctoPack.Tasks.GetAssemblyVersionInfo.Execute() [C:\projects\MyApp\MyApp\MyApp.csproj]
C:\Users\appveyor.nuget\packages\octopack\3.6.3\build\OctoPack.targets(47,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\projects\MyApp\MyApp\MyApp.csproj]
C:\Users\appveyor.nuget\packages\octopack\3.6.3\build\OctoPack.targets(47,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__25.MoveNext() [C:\projects\MyApp\MyApp\MyApp.csproj]
C:\Users\appveyor.nuget\packages\octopack\3.6.3\build\OctoPack.targets(47,5): error MSB4018: [C:\projects\MyApp\MyApp\MyApp.csproj]
C:\Users\appveyor.nuget\packages\octopack\3.6.3\build\OctoPack.targets(47,5): error MSB4018: [C:\projects\MyApp\MyApp\MyApp.csproj]
Command exited with code 1
我不确定为什么找不到 octopack 目标,因为我正在安装最新的 octopustools,并且目标应该基于引用项目。
更新:我已将 RDP 导入构建服务器,并且能够从 powershell 控制台成功运行命令,并且它们是成功的。以下是命令,以及运行这些命令的结果:
PS C:\projects\MyApp> dotnet publish MyApp/MyApp.csproj --output published-app --configuration=Release
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
SendGrid.NetCore -> C:\projects\MyApp\SendGrid.NetCore\bin\Release\netcoreapp2.0\SendGrid.NetCore.dll
MyApp -> C:\projects\MyApp\MyApp\bin\Release\netcoreapp2.0\MyApp.dll
MyApp -> C:\projects\MyApp\MyApp\published-app\
这里是 octopack 步骤:
PS C:\projects\reportal> octo pack --id Reportal --version 2.2.2.2 --basePath Reportal/published-app
Octopus Deploy Command Line Tool, version 4.27.0
Packing Reportal version "2.2.2.2"...
Saving "Reportal.2.2.2.2.nupkg" to "C:\projects\reportal"...
Done.
*所以此时我迷失了为什么命令在 appveyor 运行时失败,但当我在 RDP 进入同一台机器时运行相同的命令时却没有。
更新 #2: 我现在意识到这些命令应该作为 ps (powershell) 命令运行,而不是标准的 cmd (bash) 命令。我将它们更正为
before_build:
- ps: echo buildNumber= $env:appveyor_build_number
- ps: echo configration= $env:configuration
- ps: choco install octopustools
- ps: choco install bower
- ps: nuget restore
- ps: dotnet restore MyApp/MyApp.csproj
- ps: dotnet publish MyApp/MyApp.csproj --output published-app --configuration $env:configuration
- ps: octo pack --id Reportal --version $env:appveyor_build_number --basePath MyApp/published-app
但输出仍然返回与上面显示的 octopack 目标相同的错误。这些命令正是我从 RDP 会话中运行它们的方式,它们正在正确构建和打包。所以迷失了为什么这个自动构建失败,但是从 RDP 手动运行相同的命令是有效的。
【问题讨论】:
【参考方案1】:所以我收到了 Octopus Deploy 的回复,说 Octopack nuget 包没有更新为与 .net 核心项目一起使用。
删除软件包后,使用 octopus 工具构建和软件包的效果非常好。以下是适用于我的项目的完整步骤:
build_script:
- ps: choco install octopustools --no-progress
- ps: choco install bower --no-progress
- ps: dotnet restore
- ps: dotnet publish MyApp/MyApp.csproj --output published-app --configuration $env:configuration
- ps: octo pack --id MyCompany.MyApp --version $env:appveyor_build_version --basePath MyApp/published-app
【讨论】:
以上是关于AppVeyor Octopack - GetAssemblyVersion 失败的主要内容,如果未能解决你的问题,请参考以下文章
Nuget 3 - Octopack - 错误的框架目标错误