Home > Software design >  In VS Installer Project, Commit() is not working properly
In VS Installer Project, Commit() is not working properly

Time:05-04

Using the Visual Studio Installer Project, I included the initial setup project in Install and Commit in Custom Actions that will perform the downloading of the cabinet file under the Windows\Temp\Target Folder folder. Consequently, the zip file will be unzipped.

enter image description here

I used async/await for the first time in DownloadCatalog(), but the zip file wasn't properly downloaded, even though the directory was created. I assumed the installing process stopped the downloading process. I then changed it.

I created the installation file without async. Then I ran it, but the result was the same. This code works fine when running it in an independent project. Do you have any suggestions?


namespace IntialSetupApp
{
    [RunInstaller(true)]
    public partial class IntialInstallApp : System.Configuration.Install.Installer
    {
        private readonly string temp = @"C:\Windows\Temp\Target Folder\";
        private readonly string zipUrl = @"https://thank.you/so.much";
        private readonly string catalog = @"C:\Windows\Temp\Target Folder\whateverXML.xml";


        public IntialInstallApp()
        {
            InitializeComponent();
        }
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
            Directory.CreateDirectory(temp);
            DownloadCatalog();
        }

        private Task DownloadCatalog()
        {
            try
            {
                string fileName = Path.Combine(temp, "ZippedCab.cab");
                Uri uri = new Uri(url);

                using (WebClient client = new WebClient())
                {
                    client.DownloadFile(uri, fileName);
                }
                UnzipFile(fileName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            return Task.FromResult(true);
        }
        private Task UnzipFile(string filePath)
        {
            try
            {
                CabInfo cab = new CabInfo(filePath);
                cab.Unpack(temp);
                return Task.FromResult(true);
            }
            catch (Exception e)
            {

                Console.WriteLine(e.Message);
            }
            return Task.FromResult(false);
        }
    }
}

Update With the above code, I created the console project independently, and it created the folder and completed downloading the file. Therefore, it seems that installer prevents modifying other folders. Is there any workaround way?

CodePudding user response:

The reason was The request was aborted: Could not create SSL/TLS secure channel., so I updated the code with this. Then it works fine.

  • Related