Exemplo n.º 1
0
        /// <summary>
        /// Copy all referenced DLL files from the project directory into the RockWeb/bin directory.
        /// We do this by scanning each csproj file in the directory and looking for HintPath nodes.
        /// </summary>
        /// <param name="projectDirectory">The project directory to scan.</param>
        private void CopyProjectReferences(string projectDirectory)
        {
            string destPath = Path.Combine(Path.Combine(Support.GetBuildPath(), "RockWeb"), "Bin");

            foreach (var proj in Directory.EnumerateFiles(Path.Combine(Support.GetBuildPath(), projectDirectory), "*.csproj"))
            {
                //
                // Load the csproj file.
                //
                var doc = new XmlDocument();
                doc.Load(proj);
                var mgr = new XmlNamespaceManager(doc.NameTable);
                mgr.AddNamespace("df", doc.DocumentElement.NamespaceURI);

                //
                // Find and process all HintPath nodes.
                //
                foreach (XmlNode node in doc.DocumentElement.SelectNodes("//df:HintPath", mgr))
                {
                    string dllFile  = Path.Combine(Path.GetDirectoryName(proj), node.InnerText);
                    string destFile = Path.Combine(destPath, Path.GetFileName(node.InnerText));

                    //
                    // If we found a DLL in the project directory that does not exist in the RockWeb directory
                    // then copy it over.
                    //
                    if (File.Exists(dllFile) && !File.Exists(destFile))
                    {
                        File.Copy(dllFile, Path.Combine(destPath, Path.GetFileName(node.InnerText)));
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Execute NuGet to restore all package references.
        /// </summary>
        /// <returns>True if the operation succeeded.</returns>
        private bool NuGetRestore()
        {
            //
            // Execute 'nuget.exe restore' in the solution directory.
            //
            var process = new ConsoleApp(Path.Combine(Environment.CurrentDirectory, "nuget.exe"))
            {
                WorkingDirectory = Support.GetBuildPath()
            };

            process.StandardTextReceived += Console_StandardTextReceived;
            process.ExecuteAsync("restore");

            //
            // Wait for it to finish.
            //
            while (process.Running)
            {
                Thread.Sleep(100);
            }

            //
            // Make sure it worked.
            //
            if (process.ExitCode != 0)
            {
                UpdateStatusText("NuGet Restore Failed.");
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Unpack the ZIP file into the Build directory.
        /// </summary>
        /// <param name="filename">The full path to the ZIP file.</param>
        private void UnpackRelease(string filename)
        {
            UpdateStatusText("Unpacking...");

            Directory.Delete(Support.GetBuildPath(), true);
            ExtractZipFile(filename, Support.GetBuildPath());

            BuildRelease();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Build the release so we have compiled DLLs.
        /// </summary>
        private void BuildRelease()
        {
            //
            // Restore any NuGet packages.
            //
            UpdateStatusText("Restoring References");
            if (!NuGetRestore())
            {
                BuildCompleted?.Invoke(this, new EventArgs());
                return;
            }

            //
            // For some reason, MSBuild fails completely and the devenv build method
            // does not copy indirect DLL references (e.g. the NuGet DLLs) into the
            // RockWeb folder, so we need to do that manually.
            //
            foreach (var d in Directory.EnumerateDirectories(Support.GetBuildPath()))
            {
                CopyProjectReferences(d);
            }

            //
            // Launch a new devenv.com process to build the solution.
            //
            UpdateStatusText("Building...");
            var process = new ConsoleApp(DevEnvExecutable);

            process.StandardTextReceived += Console_StandardTextReceived;
            process.WorkingDirectory      = Support.GetBuildPath();
            process.ExecuteAsync("Rock.sln", "/Build");

            //
            // Wait for it to complete.
            //
            while (process.Running)
            {
                Thread.Sleep(100);
            }

            //
            // Check if our build worked or not.
            //
            if (process.ExitCode != 0)
            {
                UpdateStatusText("Build Failed.");
                BuildCompleted?.Invoke(this, new EventArgs());
                return;
            }

            BuildTemplate();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Compress the RockWeb folder into a ZIP file as a template. Then do final cleanup.
        /// </summary>
        private void BuildTemplate()
        {
            //
            // Compress the RockWeb folder into a template ZIP file.
            //
            UpdateStatusText("Compressing RockWeb...");
            var zipFile = Path.Combine(Support.GetTemplatesPath(), TemplateName + ".zip");
            var rockWeb = Path.Combine(Support.GetBuildPath(), "RockWeb");

            Support.CreateZipFromFolder(zipFile, rockWeb);

            //
            // Cleanup temporary files.
            //
            UpdateStatusText("Cleaning up...");
            Directory.Delete(Support.GetBuildPath(), true);
            string tempfilename = Path.Combine(Support.GetDataPath(), "temp.zip");

            File.Delete(tempfilename);

            UpdateStatusText("Template has been created.");

            BuildCompleted?.Invoke(this, new EventArgs());
        }