【问题标题】:Azure Devops : Build a winforms project and copy release files to Azure blob storageAzure Devops:构建一个 winforms 项目并将发布文件复制到 Azure blob 存储
【发布时间】:2019-07-06 18:04:48
【问题描述】:

我想为 winforms 项目 Dot Net Framework 4.5.2 设置 CI CD 以构建项目,然后将发布文件复制到 Azure blob。

当我创建一个新的构建管道并选择我的 Azure Repo 时,会创建以下 YAML

# .NET Desktop
# Build and run tests for .NET Desktop or Windows classic desktop solutions.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/windows/dot-net

trigger:
- master

pool:
  vmImage: 'VS2017-Win2016'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@0

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '**\*.sln'

    feedsToUse: config

    nugetConfigPath: 'NuGet.config'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

管道构建成功

但是,我在设置发布管道以将发布文件复制到 Azure blob 存储时遇到问题。

我创建了一个带有空作业的新发布管道。 然后我添加了一个 Azure 文件复制任务

我将什么作为来源? 当我单击椭圆时,我看到我可以从 Linked artifacts 文件夹中选择一个 myapp (Build) 文件夹。

我能够设置存储和容器名称,但将 Blob 前缀留空。

当我运行代理作业时,AzureBlob 文件复制出现错误

(已编辑)

 ##[section]Starting: AzureBlob File Copy
 ==============================================================================
 Task         : Azure File Copy
 Description  : Copy files to Azure blob or VM(s)
 Version      : 2.1.3
 Author       : Microsoft Corporation
 Help         : [More Information](https://aka.ms/azurefilecopyreadme)
 ==============================================================================
 ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\AzureRM\2.1.0\AzureRM.psd1 -Global
 ##[warning]The names of some imported commands from the module 'AzureRM.Websites' include unapproved verbs that might make them less discoverable. To find the commands with unapproved verbs, run the Import-Module command again with the Verbose parameter. For a list of approved verbs, type Get-Verb.
 ##[command]Import-Module -Name C:\Program Files\WindowsPowerShell\Modules\AzureRM.Profile\2.1.0\AzureRM.Profile.psm1 -Global
 ##[command]Add-AzureRMAccount -ServicePrincipal -Tenant *** -Credential System.Management.Automation.PSCredential -EnvironmentName AzureCloud @processScope
 ##[command] Select-AzureRMSubscription -SubscriptionId blahblah -TenantId ***
 Uploading files from source path: 'd:\a\r1\a\_Viv2' to storage account: 'viv' in container: 'viv2' with blob prefix: ''
 ##[command] & "AzCopy\AzCopy.exe" /Source:"d:\a\r1\a\_Viv2" /Dest:"https://vivapps.blob.core.windows.net/viv2" /@:"d:\a\_temp\n40zblahblah" /XO /Y /SetContentType /Z:"AzCopy" /V:"AzCopy\AzCopyVerbose_20blahblah.log" /S
 [2019/02/13 01:26:46][ERROR] Error parsing source location "d:\a\r1\a\_Viv2": Failed to enumerate directory d:\a\r1\a\_Viv2\ with file pattern *. The system cannot find the path specified. (Exception from HRESULT: 0x80070003) For more details, please type "AzCopy /?:Source" or use verbose option /V.
 ##[error]Upload to container: 'vivj2' in storage account: 'vivapps' with blob prefix: '' failed with error: 'AzCopy.exe exited with non-zero exit code while uploading files to blob storage.' For more info please refer to https://aka.ms/azurefilecopyreadme
 ##[section]Finishing: AzureBlob File Copy

[更新] 我认为问题必须与Source有关

查看构建日志,我看到类似“D:\a\1\s\blahblah”的路径名 我也看到了

creating bin\Release

但是我如何确定我应该在 Source 属性中添加什么?

尝试

 $(System.DefaultWorkingDirectory)/_Viv2/bin/Release

不开心。

HRESULT 异常:0x80070003 表示系统找不到指定的文件。

[更新]

创建的默认 YAML 不包括发布构建“工件”的任务(不要与项目工件混淆)

我尝试添加一个

   - task: PublishBuildArtifacts@1    
  displayName: 'Publish Artifact: drop'
  inputs:
  PathtoPublish: '$(build.artifactstagingdirectory)'
  artifactName: drop

但是任务日志说

##[warning]Directory 'D:\a\1\a' is empty. Nothing will be added to build artifact 'drop'

【问题讨论】:

标签: azure-devops


【解决方案1】:

请尝试在构建管道中的 VS 构建任务之后附加复制文件并发布构建工件任务。

在构建管道中:

...
- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: CopyFiles@2
  displayName: 'Copy Files'
  inputs:
    SourceFolder: '$(build.sourcesdirectory)'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'

在发布管道中:

Azure 拷贝文件源应该是

$(System.DefaultWorkingDirectory)/{Source alias}/drop/xx/xxx/bin/Release

我们可以从这个截图中得到源别名

构建成功后,我们就可以选择源路径了。

它在我这边工作正常,我从发布日志和天蓝色存储容器中检查它

【讨论】:

  • 谢谢,谢谢,谢谢!
猜你喜欢
  • 2020-08-18
  • 1970-01-01
  • 2019-07-28
  • 2021-07-29
  • 2019-04-01
  • 2017-05-06
  • 1970-01-01
  • 2020-11-01
  • 1970-01-01
相关资源
最近更新 更多