コード例 #1
0
        public void TestGetFilesSourceAppPath()
        {
            EmbedFile embedFile = new EmbedFile();

            embedFile.sourcefilepath = @"#APPPATH\InstallerLibUnitTests.dll";
            embedFile.targetfilepath = @"#APPPATH\InstallerLibUnitTests.dll";
            string supportdir = Environment.CurrentDirectory;
            Dictionary <string, EmbedFileCollection> embedFileCollection = embedFile.GetFiles(string.Empty, supportdir);

            Assert.AreEqual(1, embedFileCollection.Count);
            Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, "InstallerLibUnitTests.dll"), embedFileCollection[string.Empty][0].fullpath);
            Assert.AreEqual("InstallerLibUnitTests.dll", embedFileCollection[string.Empty][0].relativepath);
        }
コード例 #2
0
        public void TestGetFilesNoTargetPath()
        {
            EmbedFile embedFile = new EmbedFile();

            embedFile.sourcefilepath = Path.Combine(Environment.CurrentDirectory, @"InstallerLibUnitTests.dll");
            string supportdir = @"C:\SupportFiles\SupportFile";
            Dictionary <string, EmbedFileCollection> embedFileCollection = embedFile.GetFiles(string.Empty, supportdir);

            Assert.AreEqual(1, embedFileCollection.Count);
            Assert.AreEqual(1, embedFileCollection[string.Empty].Count);
            Assert.AreEqual(embedFile.sourcefilepath, embedFileCollection[string.Empty][0].fullpath);
            Assert.AreEqual(@"InstallerLibUnitTests.dll", embedFileCollection[string.Empty][0].relativepath);
        }
コード例 #3
0
        public void TestExtractCabTwoComponentsSameName()
        {
            Console.WriteLine("TestExtractCabTwoComponentsSameName");

            InstallerLinkerArguments args = new InstallerLinkerArguments();

            args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", args.config);
            args.embed    = true;
            args.apppath  = Path.GetTempPath();
            args.output   = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe");
            args.template = dotNetInstallerExeUtils.Executable;

            // create a self-extracting bootstrapper
            ConfigFile         configFile         = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();

            configFile.Children.Add(setupConfiguration);

            for (int i = 0; i < 2; i++)
            {
                ComponentCmd component = new ComponentCmd();
                component.id = "component";
                setupConfiguration.Children.Add(component);
                EmbedFile embedfile = new EmbedFile();
                embedfile.sourcefilepath = args.config;
                embedfile.targetfilepath = string.Format("component{0}\\file.xml", i);
                component.Children.Add(embedfile);
            }

            configFile.SaveAs(args.config);
            Console.WriteLine("Linking '{0}'", args.output);
            InstallerLinkerExeUtils.CreateInstaller(args);
            Assert.IsTrue(File.Exists(args.output));

            // execute dotNetInstaller
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(args.output, "/ExtractCab"));

            // this should have created a directory called SupportFiles in the current directory
            string supportFilesPath = Path.Combine(Path.GetDirectoryName(args.output), "SupportFiles");

            Console.WriteLine("Checking {0}", supportFilesPath);
            Assert.IsTrue(Directory.Exists(supportFilesPath), string.Format("Missing {0}", supportFilesPath));
            Assert.IsTrue(Directory.Exists(supportFilesPath + @"\component0"));
            Assert.IsTrue(File.Exists(supportFilesPath + @"\component0\file.xml"));
            Assert.IsTrue(Directory.Exists(supportFilesPath + @"\component1"));
            Assert.IsTrue(File.Exists(supportFilesPath + @"\component1\file.xml"));
            File.Delete(args.config);
            File.Delete(args.output);
            Directory.Delete(supportFilesPath, true);
        }
コード例 #4
0
        public void TestExtractAndRunCabPerComponent()
        {
            Console.WriteLine("TestExtractAndRunCabPerComponent");

            InstallerLinkerArguments args = new InstallerLinkerArguments();

            args.config = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
            Console.WriteLine("Writing '{0}'", args.config);
            args.embed    = true;
            args.apppath  = Path.GetTempPath();
            args.output   = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".exe");
            args.template = dotNetInstallerExeUtils.Executable;

            // create a self-extracting bootstrapper
            ConfigFile         configFile         = new ConfigFile();
            SetupConfiguration setupConfiguration = new SetupConfiguration();

            setupConfiguration.cab_path            = Path.Combine(Path.GetTempPath(), "testExtractAndRunCabPerComponent");
            setupConfiguration.cab_path_autodelete = false;
            configFile.Children.Add(setupConfiguration);
            ComponentCmd component = new ComponentCmd();

            component.command          = "cmd.exe /C copy \"#CABPATH\\component\\before.xml\" \"#CABPATH\\component\\after.xml\"";
            component.required_install = true;
            setupConfiguration.Children.Add(component);
            EmbedFile embedfile = new EmbedFile();

            embedfile.sourcefilepath = args.config;
            embedfile.targetfilepath = @"component\before.xml";
            component.Children.Add(embedfile);
            configFile.SaveAs(args.config);
            Console.WriteLine("Linking '{0}'", args.output);
            InstallerLinkerExeUtils.CreateInstaller(args);
            Assert.IsTrue(File.Exists(args.output));

            // execute dotNetInstaller
            string logfile = Path.Combine(Path.GetTempPath(), "testExtractAndRunCabPerComponent.log");

            Console.WriteLine("Log: {0}", logfile);
            Assert.AreEqual(0, dotNetInstallerExeUtils.Run(args.output, string.Format("/qb /log /logfile \"{0}\"", logfile)));
            string extractedComponentPath = Path.Combine(setupConfiguration.cab_path, "component");

            Console.WriteLine("Checking {0}", extractedComponentPath);
            Assert.IsTrue(Directory.Exists(extractedComponentPath), string.Format("Missing {0}", extractedComponentPath));
            Assert.IsTrue(File.Exists(Path.Combine(Path.GetTempPath(), @"testExtractAndRunCabPerComponent\component\before.xml")));
            Assert.IsTrue(File.Exists(Path.Combine(Path.GetTempPath(), @"testExtractAndRunCabPerComponent\component\after.xml")));
            File.Delete(args.config);
            File.Delete(args.output);
            Directory.Delete(setupConfiguration.cab_path, true);
            File.Delete(logfile);
        }
コード例 #5
0
        private void CheckForFilesToEmbed(string itemType, object itemList)
        {
            if (EmbedFile == null ||
                !string.Equals(itemType, ItemTypeNames.EmbedInBinlog, StringComparison.OrdinalIgnoreCase) ||
                itemList is not IEnumerable list)
            {
                return;
            }

            foreach (var item in list)
            {
                if (item is ITaskItem taskItem && !string.IsNullOrEmpty(taskItem.ItemSpec))
                {
                    EmbedFile.Invoke(taskItem.ItemSpec);
                }