通过 ClickOnce 部署 CefSharp Winform 并要求 vc redist in Visual Studio 2019 - 错误

CefSharp Winform deployment via ClickOnce and requirements vc redist in Visual Studio 2019 - Error

启动 CefSharp Winform 应用程序的 clickonce 安装程序时 return 安装 vc++ 2019 redist 时出错(vc++ 在部署要求中)。它在安装过程中生成一个空目录。

"C:\Users\xxxxxx\AppData\Local\Temp\VSD66FC.tmp\vcredist_x86\vcredist_x86.exe has changed since it was initially published."

在 Windows 7 和 10 上,同样的错误。我需要手动安装包。

我已经从要求中删除了 Visual C++“14”,但我不知道如何在应用程序代码中包含 C++ 库。

我找到了解决方法。我正在使用一项服务,但它应该可以在 winform 中工作:

 private void InstallVCredist()
    {
        string exe = @"path to exe\VC_redist.x86.exe"; //set path
        string stp = @"\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; //set subkey
        using (RegistryKey reg = Registry.LocalMachine.OpenSubKey(stp)) //recall registry
        {
            if (reg != null)
            {
                foreach (string dname in reg.GetSubKeyNames()) //loop search
                {
                    using (RegistryKey sreg = reg.OpenSubKey(dname))
                    {
                        if (sreg.GetValue("DisplayName").ToString() == "Microsoft Visual C++ 2015-2019 Redistributable (x86) - 14.23.27820") //set dispayname of version
                        {
                            vcredist = "1"; //it's mine control variable
                            break;
                        }
                    }
                }
            }
        }
        if (vcredist == "0") //now testing if it was found 
        {
            Process vc = new Process();
            vc.StartInfo.FileName = exe;
            //silent install
            vc.StartInfo.Arguments = "/install /passive /norestart";
            vc.StartInfo.UseShellExecute = false;
            vc.StartInfo.CreateNoWindow = true;
            //silent install
            vc.Start(); 
            vc.WaitForExit(); //as he says ;)
        }
    }