powershellasp.net-coresslcontinuous-integrationdotnet-dev-certs

Run `dotnet dev-certs https --trust` without showing user prompt


When I run

dotnet dev-certs https --trust

I see this message

Trusting the HTTPS development certificate was requested. A confirmation prompt will be displayed if the certificate was not previously trusted. Click yes on the prompt to trust the certificate.

But I run this on CI and so nobody can interact with this. How can I workaround this?

--quiet option doesn't help.

I also tried to do this with this PS script but have the same problem

$output = dotnet dev-certs https --check | Out-String
$thumbprint = [Regex]::Match($output, "(?<=A valid certificate was found: )[^\s]*").Value
$cert = Get-ChildItem Certificate::CurrentUser\My\$thumbprint
$store1 = New-Object System.Security.Cryptography.X509Certificates.X509Store "Root","CurrentUser"
$store1.Open("ReadWrite")
$store1.Add($cert) << getting prompt here
$store1.Close()

Solution

  • $output = dotnet dev-certs https --check | Out-String
    $thumbprint = [Regex]::Match($output, "(?<=A valid certificate was found: )[^\s]*").Value
    
    Get-ChildItem -Recurse cert:\CurrentUser\ |where {$_.Thumbprint -Match $thumbprint} | Select PSParentPath,Subject,Thumbprint,FriendlyName | ft -AutoSize
    
    $mypwd = ConvertTo-SecureString -String '1234' -Force -AsPlainText
    
    $params = @{
     Cert = "Cert:\CurrentUser\My\$thumbprint"
     FilePath = "c:\myexport.pfx"
     ChainOption = 'EndEntityCertOnly'
     NoProperties = $true
     Password = $mypwd
     }
    
    Export-PfxCertificate @params
    
    Get-ChildItem -Path c:\myexport.pfx | Import-PfxCertificate -CertStoreLocation Cert:\\LocalMachine\\Root -Exportable -Password $mypwd
    Get-ChildItem -Path c:\myexport.pfx | Import-PfxCertificate -CertStoreLocation Cert:\\LocalMachine\\trustedpublisher -Exportable -Password $mypwd