1

我有一个 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 手动运行相同的命令是有效的。

4

1 回答 1

2

所以我得到了 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
于 2017-12-01T15:28:51.560 回答