Azure Devops:构建一个Winforms项目并将发行文件复制到Azure Blob存储

Azure Devops : Build a winforms project and copy release files to Azure blob storage

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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# .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文件复制任务

我该把什么作为来源?
单击椭圆时,我看到可以从"链接的工件"文件夹中选择一个myapp(构建)文件夹。

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

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

(已编辑)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 ##[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\
1\\a\\_Viv2' to storage account: 'viv' in container: 'viv2' with blob prefix: ''
 ##[command] &"AzCopy\\AzCopy.exe" /Source:"d:\\a\
1\\a\\_Viv2" /Dest:"https://vivapps.blob.core.windows.net/viv2" /@:"d:\\a\\_temp\
40zblahblah" /XO /Y /SetContentType /Z:"AzCopy" /V:"AzCopy\\AzCopyVerbose_20blahblah.log" /S
 [2019/02/13 01:26:46][ERROR] Error parsing source location"d:\\a\
1\\a\\_Viv2": Failed to enumerate directory d:\\a\
1\\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 我也看到了

1
2
creating bin\
elease

但是如何确定应该在Source属性中输入什么呢?

尝试

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

不高兴。

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

[更新]

创建的默认YAML不包括发布构建"工件"的任务(不要与Project Artifacts混淆)

我尝试添加一个

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

但是任务日志显示

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


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

在构建管道中:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
...
- 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复制文件源应为

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

我们可以从此屏幕截图中获取源别名

enter