Azure Pipeline - Strong named assemblies in solution - azure-devops

I have an Azure Pipeline that builds a Winform solution with multiple projects that are Strong signed with a PFX.
I found the following link:
https://dhvik.blogspot.com/2020/01/building-strong-named-assemblies-in.html
This is my YAML file:
# .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://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
- group: 'CertPass'
steps:
- task: DownloadSecureFile#1
displayName: Download Pfx
name: myCertificatePfx
inputs:
secureFile: ventasmlcert.pfx
- task: DownloadSecureFile#1
displayName: Download sni
name: snInstallPfx
inputs:
secureFile: SnInstallPfx.exe
- task: PowerShell#2
env:
SN_INSTALL_PFX: $(snInstallPfx.secureFilePath)
MYCERTIFICATE_PFX: $(myCertificatePfx.secureFilePath)
MYCERTIFICATE_PFX_PASSWORD: $(certpass)
inputs:
targetType: 'inline'
script: '&"$($ENV:SN_INSTALL_PFX)" "$($ENV:MYCERTIFICATE_PFX)" "$($ENV:MYCERTIFICATE_PFX_PASSWORD)"'
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: 'Build .csproj file'
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
Everything works fine in the pipeline for the signing of my PFX:
But when building the solution I still get the error, but was looking that the Container where the signing was added is different from the other Containers of each project that needs to be signed.
This is the error:
Error MSB3325: Cannot import the following key file: ***cert.pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_71452E506F1E61FB
Any clue?

Related

SonarQube task causes vs test platform instailler task Azure Pipeline to fail

We are running multiple Azure pipelines on an on-prem environment, which very similar.
Today I added SonarQube tasks on one of them for integration with SonarQube.
Prepare for Analysis
Run Code Analysis
publish Quality gateway result
Now the Task for 'Visual Studio test platform installer' fails and reports
##[error]This task is supported only on Windows agents and cannot be used on other platforms.
And as soon as I remove the SonarQube tasks the pipeline works again. The pipeline never passes the first SQ task and reordering does not help.
Update:
I removed tasks 2 and 3 and the pipeline works.
As soon as a I add step 2, it fails again
Update: CI yaml content added
trigger:
branches:
include:
- develop
batch: True
name: $(date:yyyyMMdd)$(rev:.r)
resources:
repositories:
- repository: self
type: git
ref: refs/heads/develop
jobs:
- job: Phase_1
displayName: Phase 1
cancelTimeoutInMinutes: 1
pool:
name: Default
steps:
- checkout: self
- task: NodeTool#0
displayName: Use Node 14.x
inputs:
versionSpec: 14.x
checkLatest: true
- task: DotNetCoreInstaller#0
displayName: Use .NET Core sdk 6.0.101
inputs:
version: 6.0.101
- task: SonarQubePrepare#5
displayName: Prepare analysis on SonarQube
inputs:
SonarQube: XXX
projectKey: XXX
projectName: XXX
- task: VisualStudioTestPlatformInstaller#1
displayName: VsTest Platform Installer
inputs:
versionSelector: specificVersion
testPlatformVersion: 16.8.3
- task: NuGetToolInstaller#0
displayName: Use NuGet 5.8.x
inputs:
versionSpec: 5.8.x
- task: DotNetCoreCLI#2
displayName: dotnet custom
inputs:
command: custom
projects: '**/XXX.sln'
custom: restore
arguments: --source https://XXX -r win-x86
selectOrConfig: config
- task: DotNetCoreCLI#2
displayName: dotnet build
inputs:
projects: '**/XXX.sln'
arguments: /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl="bin\WebAppContent" /p:BuildPlatform="$(BuildPlatform)" /p:BuildConfiguration="$(BuildConfiguration)"
- task: MSBuild#1
displayName: Build solution **/XXX.sln
enabled: False
inputs:
solution: '**/XXX.sln'
msbuildLocationMethod: location
msbuildLocation: C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)
msbuildArguments: /p:DeployOnBuild=true /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl="bin\WebAppContent" /p:RuntimeIdentifier=win-x86
maximumCpuCount: true
logProjectEvents: true
- task: VSTest#2
name: VSTest_4
displayName: Test Assemblies **\$(BuildConfiguration)\*test*.dll;-:**\obj\**
inputs:
testAssemblyVer2: >-
**\*unittest*.dll
!**\obj\**
!**\ref\**
runOnlyImpactedTests: false
vsTestVersion: toolsInstaller
runInParallel: true
codeCoverageEnabled: true
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)
- task: SonarQubeAnalyze#5
displayName: Run Code Analysis
- task: SonarQubePublish#5
displayName: Publish Quality Gate Result
- task: ArchiveFiles#2
displayName: Archive Apps.Api
inputs:
rootFolderOrFile: source\Apps\Apps.Api\bin\WebAppContent
includeRootFolder: false
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).Apps.Api.zip
- task: ArchiveFiles#2
displayName: Archive Hub.Api
inputs:
rootFolderOrFile: source\Hub\Hub.Api\bin\WebAppContent
includeRootFolder: false
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).Hub.Api.zip
- task: ArchiveFiles#2
displayName: Archive Rmi.Api
inputs:
rootFolderOrFile: source\Rmi\Rmi.Api\bin\WebAppContent
includeRootFolder: false
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).Rmi.Api.zip
- task: ArchiveFiles#2
displayName: Archive Hub.WebClient
inputs:
rootFolderOrFile: source\Hub\Hub.WebClient\bin\WebAppContent
includeRootFolder: false
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).Hub.WebClient.zip
- task: CopyFiles#2
name: CopyFiles_5
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
enabled: False
inputs:
SourceFolder: $(build.sourcesdirectory)
Contents: '**\bin\$(BuildConfiguration)\PublishOutput\**'
TargetFolder: $(build.artifactstagingdirectory)
CleanTargetFolder: true
- task: PublishBuildArtifacts#1
name: PublishBuildArtifacts_6
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: $(build.artifactstagingdirectory)
TargetPath: '\\my\share\$(Build.DefinitionName)\$(Build.BuildNumber)'
...
SonarQube task causes vs test platform instailler task Azure Pipeline to fail
According to the document Visual Studio Test Platform Installer task:
Use this task to acquire the Microsoft test platform from nuget.org or
a specified feed, and add it to the tools cache. The installer task
satisfies the 'vstest' demand and a subsequent Visual Studio Test task
in a build or release pipeline can run without needing a full Visual
Studio install on the agent machine.
So, the task Visual Studio test platform installer is supported only on Windows agents and cannot be used on other platforms.
You could just add this task and run it on other platforms, you will get the same error:

Azure Pipeline - Self Hosted Agent YAML how to copy release files to my Azure VM

I have an Azure Pipeline using a Pool of a Self Hosted Agent and I have the following YAML that is working great:
# .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://learn.microsoft.com/azure/devops/pipelines/apps/windows/dot-net
trigger:
- master
# Al usuar el pool default, usara de la organizacion el pool que cree como Self hosted CustomAgentSelfInsurance
pool:
name: Default
#vmImage: 'windows-latest'
#container: mcr.microsoft.com/windows/servercore:ltsc2019
variables:
- group: 'CertPass'
#solution: '**/SelfInsurance.sln'
#buildPlatform: 'Any CPU'
#buildConfiguration: 'Release'
#pathToMageTool: "\"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v10.0A\\bin\\NETFX 4.8 Tools\\mage.exe\""
steps:
- task: DownloadSecureFile#1
displayName: Download Pfx
name: myCertificatePfx
inputs:
secureFile: ventasmlcert.pfx
- task: DownloadSecureFile#1
displayName: Download sni
name: snInstallPfx
inputs:
secureFile: SnInstallPfx.exe
- task: DownloadSecureFile#1
displayName: Download Testpipelineapp
name: testPipelineapp
inputs:
secureFile: TestPipelineapp.zip
- task: ExtractFiles#1
inputs:
archiveFilePatterns: '$(Agent.TempDirectory)/TestPipelineapp.zip'
cleanDestinationFolder: false
overwriteExistingFiles: true
#- task: PowerShell#2
# env:
# SN_INSTALL_PFX: $(snInstallPfx.secureFilePath)
# MYCERTIFICATE_PFX: $(myCertificatePfx.secureFilePath)
# MYCERTIFICATE_PFX_PASSWORD: $(certpass)
# inputs:
# targetType: 'inline'
# script: '&"$($ENV:SN_INSTALL_PFX)" "$($ENV:MYCERTIFICATE_PFX)" "$($ENV:MYCERTIFICATE_PFX_PASSWORD)"'
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: 'Build .csproj file'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:SkipInvalidConfigurations=false /p:OutDir="$(System.DefaultWorkingDirectory)\publish_output"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
# Command line
# Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
- task: CmdLine#2
inputs:
script: TestPipelineapp.exe #'echo Write your commands here.'
#workingDirectory: # Optional
#failOnStderr: false # Optional
What I need is to create a task that takes my build release files and copy them to a folder in my Azure VM.
Any clue and example on how can I do that?
you can use Environment to configure your VM for azure devops to have access, and use the deployment environment to run a download task -> copy to your folder.
docs: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/environments-virtual-machines?view=azure-devops

How to deploy via azure release to VM?

I'm trying to setup a release pipeline in azure devops which is supposed to deploy my web site to virtual machine, that is, update an existing web site already running on IIS.
I'm getting the following errors:
2021-02-25T20:47:55.4825268Z ##[error]Failed to deploy web package to IIS website.
2021-02-25T20:47:55.4836851Z ##[error]Error: The account 'RISK\PANDA' does not appear to be valid. The account was obtained from this location: 'system.applicationHost/applicationPools/DataConverterAPI'.
Error: Some or all identity references could not be translated.
Error count: 1.
2021-02-25T20:47:55.4839506Z ##[error]Error: The process 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' failed with exit code 4294967295
here's my build pipeline .yml file content:
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
userPassword: 'myPass'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
IIS Web App Manage task .yml:
steps:
- task: IISWebAppManagementOnMachineGroup#0
displayName: 'IIS Web App Manage'
inputs:
WebsiteName: DataConverterAPI
WebsitePhysicalPath: '%SystemDrive%\DataConverterAPI'
AddBinding: True
Bindings: '{"bindings":[{"protocol":"http","ipAddress":"All Unassigned","port":"50352","hostname":"","sslThumbprint":"","sniFlag":false}]}'
BasicAuthenticationForWebsite: true
WindowsAuthenticationForWebsite: false
ParentWebsiteNameForVD: DataConverterAPI
ParentWebsiteNameForApplication: DataConverterAPI
IIS Web App Deploy task .yml:
steps:
- task: IISWebAppDeploymentOnMachineGroup#0
displayName: 'IIS Web App Deploy'
inputs:
WebSiteName: DataConverterAPI
TakeAppOfflineFlag: True
XmlVariableSubstitution: True
someone help pls.
alright I fixed this by changing the pool identity on which my application run to 'ApplicationPoolIdentity'
and sadly I don't know yet why it solved the problem, any comments would be appreciated

How to find unit test dll in Azure Devops when copying test artifact to run on multiple agents (YAML)

I am using Azure Devops YAML build pipeline for the build and test of my SQL SSDT project. I am trying to amend my YAML code so that the test part will run on multiple Microsoft hosted agents (I have purchased 2). When I run the VSTest task as part of the first job that is run on the single agent, it runs no problems. However, when I run it as part of the second job, the unit tests do not run, with an error saying it cannot find the requisite test files. Is there something I need to add to my second job to make this work?
Many thanks.
trigger:
branches:
include:
- develop
- stage
- master
pr:
- master
- stage
- develop
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
jobs:
- job: BuildPublish
steps:
- task: NuGetToolInstaller#1
inputs:
versionSpec: '2.*'
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'select'
restoreDirectory: '$(Build.SourcesDirectory)/DIP_UsqlSln/packages'
- task: VSBuild#1
inputs:
solution: '**/*.sln'
msbuildArgs: '/p:USQLSDKPath=$(Build.SourcesDirectory)/DIP_UsqlSln/packages/Microsoft.Azure.DataLake.USQL.SDK.1.4.190703/build/runtime;USQLTargetType=SyntaxCheck;DataRoot=$(Build.SourcesDirectory) /p:EnableDeployment=true'## Heading ##
createLogFile: true
logFileVerbosity: 'detailed'
- task: CopyFiles#2
inputs:
Contents: '**'
TargetFolder: '$(build.artifactstagingdirectory)'
CleanTargetFolder: true
OverWrite: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
- job: Test
dependsOn: BuildPublish
strategy:
parallel: 2
steps:
- task: DownloadBuildArtifacts#0
displayName: 'Download Build Artifacts'
inputs:
artifactName: 'drop'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
runOnlyImpactedTests: true
runInParallel: true
How to find unit test dll in Azure Devops when copying test artifact to run on multiple agents (YAML)
That because the default Destination directory for the task DownloadBuildArtifacts is $(System.ArtifactsDirectory), however, the default Search folder for Visual Studio Test task is $(System.DefaultWorkingDirectory).
When you use the those two task in the build pipeline, the value of those two predefined variables are not same:
The value of $(System.ArtifactsDirectory) should be C:\agent\_work\r1\a.
The value of $(System.DefaultWorkingDirectory) should be c:\agent_work\1\s.
So, it will cause this issue, could not found the requisite test files.
To resolve this issue, we just need to change the default value of those two predefined variables to use same value:
- task: DownloadBuildArtifacts#0
displayName: 'Download Build Artifacts'
inputs:
artifactName: drop
downloadPath: '$(System.DefaultWorkingDirectory)'
Or
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
searchFolder: '$(System.ArtifactsDirectory)'
runOnlyImpactedTests: true
runInParallel: true
Hope this helps.

Issue in YAMEL file

I am using Azure DevOps to Build and deploy my Azure Synapse
I have two YAML files. First one works well and I need to separate Build and Release steps. because of that I wrote second YAML file. Second YAML file has this error :
##[error]No files were found to deploy with search pattern
d:\a\1\s\SQL_ASynapse\bin\Release\SQL_ASynapse.dacpacCheck out how to troubleshoot failures at
https://aka.ms/sqlazuredeployreadme#troubleshooting-
First YAML file that works well:
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: AzureKeyVault#1
inputs:
azureSubscription: 'XXX'
KeyVaultName: 'XXX-Dev'
SecretsFilter: '*'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: SqlAzureDataWarehouseDacpacDeployment#1
inputs:
azureSubscription: 'XXX'
AuthenticationType: 'server'
ServerName: 'XXX'
DataWarehouse: '$(SynapseName)'
SqlUsername: '$(SynapseSQLUsername)'
SqlPassword: '$(SynapseSQLPassword)'
deployType: 'DacpacTask'
DeploymentAction: 'Publish'
DacpacFile: 'SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac'
IpDetectionMethod: 'AutoDetect'
Second YAML file who has error:
trigger:
- master
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
# Agent VM image name
vmImageName: 'windows-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureKeyVault#1
inputs:
azureSubscription: 'XXX-Dev'
KeyVaultName: 'XXX-Dev'
SecretsFilter: '*'
- task: SqlAzureDataWarehouseDacpacDeployment#1
inputs:
azureSubscription: 'XXX-Dev'
AuthenticationType: 'server'
ServerName: 'XXX'
DataWarehouse: '$(SynapseName)'
SqlUsername: '$(SynapseSQLUsername)'
SqlPassword: '$(SynapseSQLPassword)'
deployType: 'DacpacTask'
DeploymentAction: 'Publish'
DacpacFile: 'SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac'
IpDetectionMethod: 'AutoDetect'
UPDATE #1 FOR #Levi Lu-MSFT ANSWER
I have changed my second script like below code :
...
- task: VSBuild#1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- publish: $(system.defaultworkingdirectory)\SQL_ASynapse\bin\Release ## path to a file or folder
artifact: MyBuildOutputs
...
- download: current # refers to artifacts published by current pipeline
artifact: MyBuildOutputs
- task: SqlAzureDataWarehouseDacpacDeployment#1
inputs:
azureSubscription: 'xxx-Dev'
AuthenticationType: 'server'
ServerName: 'xxx.database.windows.net'
DataWarehouse: '$(SynapseName)'
SqlUsername: '$(SynapseSQLUsername)'
SqlPassword: '$(SynapseSQLPassword)'
deployType: 'DacpacTask'
DeploymentAction: 'Publish'
DacpacFile: 'SQL_ASynapse\bin\Release\SQL_ASynapse.dacpac'
IpDetectionMethod: 'AutoDetect'
But I have still same error.
Upload task result
Download task result
SqlAzureDataWarehouseDacpacDeployment error :
##[error]No files were found to deploy with search pattern
d:\a\1\s\SQL_ASynapse\bin\Release\SQL_ASynapse.dacpacCheck out how to
troubleshoot failures at https://aka.ms/sqlazuredeployreadme#troubleshooting-
If you use Microsoft-hosted agent. Every job defined in the yaml pipeline will run on a fresh new virtual machine. The virtual machine is discarded after one use.
So that the build artifacts from Build job of Build stage doesnot exist on the agent machine of the deploy job of Deploy stage. That's why you got above error.
You need to add a publish task after Vsbuild task in Build job to publish the build results to azure devops server. You should specify the correct path(where the build artifacts reside) to publish.
- publish: $(system.defaultworkingdirectory)\SQL_ASynapse\bin\Release ## path to a file or folder
artifact: MyBuildOutputs
Then add a download task before qlAzureDataWarehouseDacpacDeployment task in Deploy job to download the build results to deploy job agent. So that the build results will be available to the deployment tasks.
- download: current # refers to artifacts published by current pipeline
artifact: MyBuildOutputs
To publish and download build artifacts, You can also use Publish Build Artifacts task, Download Build Artifacts task.
Update:
When you use download task: See here for more information.
By default, files are downloaded to $(Pipeline.Workspace)/{artifact}, where artifact is the name of the artifact. The folder structure of the artifact is always preserved.
And you can see from above updated screenshot. The artifacts is downloaded to folder D:\a\1\MyBuildOutputs
So you should set DacpacFile attribute as below:
DacpacFile : $(Pipeline.Workspace)/MyBuildOutputs/SQL_ASynapse.dacpac