How to Install dotnet dev-certs certificate on a CI Server
Asked Answered
E

2

13

I would like to run my API using dotnet run, so I can run some tests against it. However, on Azure Pipelines and AppVeyor, they don't have a developer certificate installed and I get an error when I try to start my API. Installing a developer certificate involes running:

dotnet dev-certs https --trust

However, this shows a dialogue which the user has to click and this fails the build. How can I install the developer certificate on a CI server?

Else answered 26/7, 2019 at 14:8 Comment(2)
For Azure pipelines you can use secure filesAnorthosite
How about using the approach mentioned in this? superuser.com/questions/191038/… and #4197497Tereasaterebene
B
9

You can either use your own certificate (aspnet core listenOptions.UseHttps(new X509Certificate2(...));) in your app or export the dotnet dev certificate with:

dotnet dev-certs https --export-path <path> [--password <pass>]

This generates the certificate that you need. You can trust this certificate manually with powershell as explained here:

https://mcmap.net/q/907727/-vsts-iis-deploy-configure-iis-site-ssl-certificates or https://mcmap.net/q/907728/-how-to-trust-a-certificate-in-windows-powershell

Blanketyblank answered 30/7, 2019 at 14:49 Comment(1)
Exporting and trusting via powershell completes successfully for me, but doesn't seem to actually trust the certificateFlown
C
0

The accepted answer pointed me in the right direction, but this is the full PowerShell script that I ended up with:

 $pfxPath = Join-Path -Path $(Agent.TempDirectory) -ChildPath 'cert.pfx'
 $password = (New-Guid).ToString("N")
 dotnet dev-certs https --export-path $pfxPath --password $password -v
 $securePassword = ConvertTo-SecureString $password -AsPlainText -Force
 Import-PfxCertificate -FilePath $pfxPath -Password $securePassword -CertStoreLocation Cert:\LocalMachine\Root
Cirrus answered 30/7 at 22:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.