HAd*_*des 28 c# clickonce visual-studio-2008 visual-studio
我需要对一年多未触及的ClickOnce应用程序进行一些更改,因此证书已过期.
我已经读过,使用新证书发布会使应用程序失败,因为它将使用不同的密钥进行签名.
因此,我认为我需要使用相同的证书,但不知道如何更新它.
And*_*man 14
如果您正在寻求快速解决方案,那么您可以"续订"现有证书,并为其提供更长的到期日期.
Cliff Stanford已经清理了微软的"解决方法",并将其作为一个简单的命令行exe提供 - 可在此处获取:http://may.be/renewcert/ - 好工作Cliff!
这是关于证书过期的权威MSDN文章,其中还包含指向RenewCert更新的链接.http://msdn.microsoft.com/en-us/library/ff369721.aspx这涵盖了所有情况.
如果您的目标是.NET 3.5,使用自动更新,并且没有VSTO应用程序,或者您的目标是.NET 4,则更改证书不会导致任何问题.
更新:@OceanAirdrop 完成了以下所有工作,并在 github 上提供:https : //github.com/OceanAirdrop/ExtendClickOnceCertificate,他在自述登陆页面上有使用说明。
原始细节:
正如@Andy Blackman 所说,更新 pfx 是一种方法,但是当我尝试使用它时,renewcert 在现代 Windows 上运行时出现问题。为了修复 may.be/renewcert 依赖关系,另一个人用 C# 重写了它,这样你就可以在现代 Visual Studio 上使用它:
https://nathanpjones.com/2013/01/renewing-temporary-certificate/
从他的网站下载源代码,编译并运行。
如果您在 wcslen 的 CertNameToStr 中的编组中收到“system.accessviolationexception”,则进行以下更改,以便编组不会爆炸:
在 Crypt.cs:Line 130 中,将 psz 变量更改为使用 char[] 而不是 string:
[DllImport("crypt32.dll", CharSet = CharSet.Auto)]
- internal static extern int CertNameToStr(X509Encoding dwCertEncodingType, ref CRYPT_DATA_BLOB pName, CertNameType dwStrType, ref string psz, int csz);
+ internal static extern int CertNameToStr(X509Encoding dwCertEncodingType, ref CRYPT_DATA_BLOB pName, CertNameType dwStrType, [In, Out] char[] psz, int csz);
Run Code Online (Sandbox Code Playgroud)在 Program.cs:Line 131 中使用字符缓冲区而不是字符串:
- //var buffer = new char[1024];
- string buffer = new string('\0', 1024);
+ char[] buffer = new char[1024];
+ //string buffer = new string('\0', 1024);
int d;
- if ((d = Crypt.CertNameToStr(Crypt.X509Encoding.ASN_Encodings, ref certNameBlob, Crypt.CertNameType.CERT_X500_NAME_STR, ref buffer, 1024 * sizeof(char))) != 0)
+ if ((d = Crypt.CertNameToStr(Crypt.X509Encoding.ASN_Encodings, ref certNameBlob, Crypt.CertNameType.CERT_X500_NAME_STR, buffer, 1024 * sizeof(char))) != 0)
Run Code Online (Sandbox Code Playgroud)要运行它以快速更新默认五年的证书,请使用如下命令:
"[path-to-renew-cert-proj-dir\bin\Debug\]renewCert.exe" [old-cert-path\]old_cert_name.pfx [new-cert-path\]new_cert_name.pfx
Run Code Online (Sandbox Code Playgroud)