How can I use msbuild to add a security certificate that I can use in IIS

1

I have this target

<Target Name = "AddLocalCertificate">       
    <MSBuild.ExtensionPack.Security.Certificate TaskAction="Add" FileName="$(CertificateLocation)" CertPassword="$(CertificatePassword)">           
        <Output TaskParameter="Thumbprint" PropertyName="CertificateHash"/>             
    </MSBuild.ExtensionPack.Security.Certificate>
</Target>

and in another target this binding statement

<MSBuild.ExtensionPack.Web.Iis7Binding
  CertificateHash="$(CertificateHash)" 
  TaskAction="Add" MachineName="$(MachineName)" Name="$(SiteName)" BindingInformation="*:$(HttpsPort):$(SiteName)" BindingProtocol="https"/>

However when I run the targets I get the error

Creating binding with certificate: thumb print 'DBE4964B4C4D0F185E8B1D421D736390AE586EBF' in stor e 'MY' C:\Projects\RC19_Release2\ExternalBinaries\MSBuildGlobalFiles\ManageWebsite.targets(154,3): error : COMException: A specified logon session does not exist. It may already have been terminated. (Exce ption from HRESULT: 0x80070520)\r C:\Projects\RC19_Release2\ExternalBinaries\MSBuildGlobalFiles\ManageWebsite.targets(154,3): error :

When I look in IIS it has created the site and the binding is there, but it does not seem to be able to find the certificate, and if I look in the "Server Certificates" on IIS then I cannot see my certificate.

If I do MMC -> certificate snap in and go to Current User then I can see my cert in there.

How do I either access that certificate from within IIS/msbuild or have msbuild create it in the correct place for IIS to be happy?

The msbuild extension help page is this http://www.msbuildextensionpack.com/help/4.0.5.0/html/45763eac-8f14-417d-9b27-425161982ffe.htm but it has not helped me much!

Thanks

security
deployment
iis-7
msbuild
msbuildextensionpack
asked on Stack Overflow May 9, 2012 by Loofer • edited May 10, 2012 by Loofer

1 Answer

6

Well I got it working... clearly no one cares but me :D

The substantive change was to add Exportable="True" MachineStore="True" to the certificate add task like so

<MSBuild.ExtensionPack.Security.Certificate TaskAction="Add" Exportable="True" MachineStore="True" FileName="$(CertificateLocation)" CertPassword="$(CertificatePassword)">         
        <Output TaskParameter="Thumbprint" PropertyName="CertificateHash"/>             
    </MSBuild.ExtensionPack.Security.Certificate>   

and all is good in the world once again.

answered on Stack Overflow May 10, 2012 by Loofer

User contributions licensed under CC BY-SA 3.0