I need to create post build event to perform the following:
sn -i MyKey.pfx MyKeyContainerName
tlbimp $(ConfigurationName)\\MyCom.tlb /out:$(ConfigurationNam
I needed this to be automatized and found this question. Following this answer (many thanks @Thomas Rijsewijk) I've written my version of it:
# Start the sn.exe process
Start-Process $SnExePath -ArgumentList "-i $PfxCertificatePath $LocalContainerName" -NoNewWindow
# Wait for the process to start
Start-Sleep 2
# This workaround allows to forward the password to the standard input
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("$($PfxCertificatePassword){ENTER}")
Start-Sleep 2
# This ENTER is to return from the sn.exe process
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
Using the -Wait
switch of the Start-process
command did not solve the problem because the PS script was waiting the sn.exe process to terminate before forwarding the password to it.