diff --git a/C3D.MSBuild.Tools.EF6.GenerateViews.sln b/C3D.MSBuild.Tools.EF6.GenerateViews.sln index 476c636..4a8eb35 100644 --- a/C3D.MSBuild.Tools.EF6.GenerateViews.sln +++ b/C3D.MSBuild.Tools.EF6.GenerateViews.sln @@ -8,7 +8,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{A547D473 build\azure-pipelines.yml = build\azure-pipelines.yml Directory.Build.Props = Directory.Build.Props Directory.Build.Targets = Directory.Build.Targets - build\InstallCert.ps1 = build\InstallCert.ps1 + build\ImportCert.ps1 = build\ImportCert.ps1 build\RemoveCert.ps1 = build\RemoveCert.ps1 build\Test.snk = build\Test.snk EndProjectSection diff --git a/build/ImportCert.ps1 b/build/ImportCert.ps1 new file mode 100644 index 0000000..8d6a8e0 --- /dev/null +++ b/build/ImportCert.ps1 @@ -0,0 +1,23 @@ +$password = "$($env:password)" +$pfx64 = "$($env:pfx)" + +$PfxUnprotectedBytes = [Convert]::FromBase64String($pfx64) + +Add-Type -AssemblyName System.Security + +$Pfx = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection + +$Pfx.Import($PfxUnprotectedBytes, $null, [Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable) + +$PfxProtectedBytes = $Pfx.Export([Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $password) + +$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 +$cert.Import($PfxProtectedBytes, $password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"PersistKeySet") +$store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", CurrentUser +$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]"ReadWrite") +$store.Add($cert) +$store.Close() +Write-Host Imported certificate $cert +$thumb = $cert.Thumbprint +Write-Host ("##vso[task.setvariable variable=app_pfx_thumbprint;]$thumb") +Write-Host ("##vso[task.setvariable variable=MSBuildEmitSolution;]0") \ No newline at end of file diff --git a/build/InstallCert.ps1 b/build/InstallCert.ps1 deleted file mode 100644 index 20bd11b..0000000 --- a/build/InstallCert.ps1 +++ /dev/null @@ -1,15 +0,0 @@ -Param( - [string]$pfxpath, - [string]$password -) -Add-Type -AssemblyName System.Security -$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -$cert.Import($pfxpath, $password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"PersistKeySet") -$store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", CurrentUser -$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]"ReadWrite") -$store.Add($cert) -$store.Close() -Write-Host Imported certificate $cert -$thumb = $cert.Thumbprint -Write-Host ("##vso[task.setvariable variable=app_pfx_thumbprint;]$thumb") -Write-Host ("##vso[task.setvariable variable=MSBuildEmitSolution;]0") \ No newline at end of file diff --git a/build/RemoveCert.ps1 b/build/RemoveCert.ps1 index f80eb2c..73d2930 100644 --- a/build/RemoveCert.ps1 +++ b/build/RemoveCert.ps1 @@ -1,11 +1,13 @@ Param( - [string]$pfxpath, - [string]$password + [string]$thumb ) -Add-Type -AssemblyName System.Security -$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -$cert.Import($pfxpath, $password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"PersistKeySet") -$store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", CurrentUser -$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]"ReadWrite") -$store.Remove($cert) -$store.Close() \ No newline at end of file +if ($thumb -ne "") { + Add-Type -AssemblyName System.Security + $store = new-object system.security.cryptography.X509Certificates.X509Store -argumentlist "MY", CurrentUser + $store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]"ReadWrite") + $certs = $store.Certificates.Find([System.Security.Cryptography.X509Certificates.X509FindType]"FindByThumbprint", $thumb, $false) + if ($certs -ne $null) { + $store.RemoveRange($certs) + } + $store.Close() +} \ No newline at end of file diff --git a/build/azure-pipelines.yml b/build/azure-pipelines.yml index d9b632d..28a7a7f 100644 --- a/build/azure-pipelines.yml +++ b/build/azure-pipelines.yml @@ -19,7 +19,7 @@ pool: variables: - group: Github-Packages -- group: Signing +- group: 'c3d-devops' - name: solution value: 'C3D.MSBuild.Tools.EF6.GenerateViews.sln' - name: buildPlatform @@ -30,6 +30,8 @@ variables: value: '$(Agent.MachineName)' - name: buildUser value: '$(Build.QueuedBy)' +- name: 'timestamper' + value: 'http://timestamp.comodoca.com' steps: - checkout: self @@ -37,15 +39,15 @@ steps: submodules: true persistCredentials: true +- script: | + git config --global user.email "support@cloud3d.ltd" + git config --global user.name "Agent - $(Agent.Name)" + workingDirectory: $(Build.SourcesDirectory) + displayName: 'Git Configure' + - powershell: 'Write-Host ("##vso[task.setvariable variable=MSBuildEmitSolution;]0")' displayName: 'Ensure MSBuildEmitSolution is not set' -- task: DownloadSecureFile@1 - displayName: 'Download secure file PFX' - name: app_pfx - inputs: - secureFile: 'Cloud3D-codesign.pfx' - - task: DownloadSecureFile@1 displayName: 'Download secure file SNK' name: snk @@ -53,15 +55,17 @@ steps: secureFile: 'cloud3d-codesign.snk' - task: PowerShell@2 - displayName: 'Install Cert' + displayName: 'Install Certificate' inputs: - targetType: filePath - filePath: 'build/InstallCert.ps1' - arguments: '-pfxpath $(app_pfx.secureFilePath) -password $(pfx_password)' + targetType: 'filePath' + filePath: ImportCert.ps1 + env: + password: $(pfx-password) + pfx: $(c3d-codesign) - task: NuGetToolInstaller@0 inputs: - versionSpec: 5.10.0 + versionSpec: 5.11.0 - task: NuGetCommand@2 inputs: @@ -183,6 +187,6 @@ steps: displayName: 'Remove Cert' inputs: targetType: filePath - filePath: 'build/RemoveCert.ps1' - arguments: '-pfxpath $(app_pfx.secureFilePath) -password $(pfx_password)' + filePath: 'RemoveCert.ps1' + arguments: '-thumb $(app_pfx_thumbprint)' condition: always()