/// <summary>
        /// deployes the given deployment information
        /// </summary>
        /// <param name="deployInfo">object containing all the needed deployment information</param>
        public void Deploy(DeploymentInformation deployInfo)
        {
            Show();

            _deployInfo = deployInfo;

            Text = string.Format("Deploying {0} {1}", _deployInfo.NuSpecPackage.Metadata.Id, _deployInfo.NuSpecPackage.Metadata.Version);

            deployInfo.NuGetServer.LastAttemptedDeploy = DateTime.Now;

            OptionsManager.Instance.SaveSettings();
        }
Example #2
0
        /// <summary>
        /// builds the nuPkg file
        /// </summary>
        /// <returns>true if the nuPkg file was build, false otherwise</returns>
        private void BuildNuGetPackage(DeploymentInformation deployInfo, ref string nuPkgFilePath)
        {
            LoggingManager.Instance.Logger.Debug("creating nupkg file");

            //-----create the .nuPkg file in the folder
            string result;
            string error;
            nuPkgFilePath = Path.Combine(deployInfo.Build.BuildPath, string.Format("{0}.{1}.nupkg", deployInfo.NuSpecPackage.Metadata.Id, deployInfo.NuSpecPackage.Metadata.Version));
            string commandOne = string.Format(@"cd /D ""{0}"" ", deployInfo.Build.BuildPath);
            string commandTwo = string.Format(@" ""{0}"" pack ""{1}"" ", OptionsManager.Instance.Configuration.GeneralOptions.NuGetOptions.ExePath, deployInfo.NuSpecFileFullName);

            LoggingManager.Instance.Logger.Debug(string.Format("executing command [{0}]  and [{1}]", commandOne, commandTwo));
            CommandUtil.ExecuteCommands(new string[] { commandOne, commandTwo }, new string[] { "/C" }, out result, out error);

            //-----make sure the nuPkg file was build
            if (!string.IsNullOrEmpty(error) || !File.Exists(nuPkgFilePath))
            {
                throw new BuildNuGetPackageFailedExceptions(!string.IsNullOrEmpty(error) ? string.Format("An Error occured while creating the nuPkg file: {0}", error) :
                                                                                            string.Format("Could not create nuPkg file: {0}", nuPkgFilePath));
            }

            //-----delete the nuSpec file is possible
            if (!deployInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Metadata.UseAny && !deployInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Files.UseFromSettings)
            {
                try
                {
                    File.Delete(deployInfo.NuSpecFileFullName);
                }
                catch (Exception ex)
                {
                    LoggingManager.Instance.Logger.Warn(ex);
                }
            }

            LoggingManager.Instance.Logger.Debug("creating nupkg file finished");
        }
Example #3
0
        /// <summary>
        /// build the project using the given msbuild exe
        /// </summary>
        /// <param name="msBuildPath">full path to the msbuild exe to use</param>
        /// <returns>true if the build process was successful, false otherwise</returns>
        private void BuildProject(DeploymentInformation deployInfo)
        {
            LoggingManager.Instance.Logger.Debug("building project");

            //-----start the build process of the project
            string result;
            string error;
            if (!Directory.Exists(deployInfo.Build.BuildPath))
            {
                LoggingManager.Instance.Logger.Debug(string.Format("creating directory {0}", deployInfo.Build.BuildPath));
                Directory.CreateDirectory(deployInfo.Build.BuildPath);
            }

            string buildFileFullname = Path.Combine(deployInfo.Build.BuildPath, deployInfo.OutputFileName);

            StringBuilder command = new StringBuilder(string.Format(@"{0} ""{1}"" ", deployInfo.MsBuildFullName, deployInfo.ProjectFullName));

            command.Append(string.Format(@" /p:Configuration=""{0}"" ", deployInfo.Build.ConfigurationName));

            command.Append(string.Format(@" /p:Platform=""{0}"" ", deployInfo.Build.PlatformName));

            command.Append(string.Format(@" /p:OutputPath=""{0}"" ", deployInfo.Build.BuildPath));

            if (deployInfo.ProjectOptions.MsBuildOptions.Usage.Optimize.Useage != Enumerations.Useage.None && deployInfo.Build.Optimize != null)
                command.Append(string.Format(@" /p:Optimize={0} ", deployInfo.Build.Optimize.ToString()));

            if (deployInfo.ProjectOptions.MsBuildOptions.Usage.DebugConstants.Useage != Enumerations.Useage.None && !string.IsNullOrEmpty(deployInfo.Build.DebugConstants))
                command.Append(string.Format(@" /p:DefineConstants=""{0}"" ", deployInfo.Build.DebugConstants));

            if (deployInfo.ProjectOptions.MsBuildOptions.Usage.DebugInfo.Useage != Enumerations.Useage.None && !string.IsNullOrEmpty(deployInfo.Build.DebugInfo))
                command.Append(string.Format(@" /p:DebugSymbols=true /p:DebugType={0} ", deployInfo.Build.DebugInfo.ToString()));

            if (deployInfo.Build.DocumentationFile != null)
                command.Append(string.Format(@" /p:DocumentationFile=""{0}"" ", deployInfo.Build.DocumentationFile.Source));

            LoggingManager.Instance.Logger.Debug(string.Format("executing command [{0}]", command.ToString()));
            CommandUtil.ExecuteCommand(command.ToString(), new string[] { "/C" }, out result, out error);

            //-----make sure the build process was successfull
            if (!string.IsNullOrEmpty(error) || !File.Exists(buildFileFullname))
            {
                //HACK should be reworked since it is not very save, but currently the only way
                if (string.IsNullOrEmpty(error) && deployInfo.ProjectOptions.Identifier == Enumerations.ProjectIdentifier.CPP)
                {
                    Xml.NuGet.NuSpec.File fileDll = deployInfo.NuSpecPackage.Files.FirstOrDefault(f => f.Source == buildFileFullname);
                    Xml.NuGet.NuSpec.File filePdb = deployInfo.NuSpecPackage.Files.FirstOrDefault(f => f.Source == StringUtil.ReplaceLastOccurrence(buildFileFullname, Resources.ExtensionDLL, Resources.ExtensionPDB));

                    if (fileDll != null)
                    {
                        deployInfo.Build.BuildPath = Path.Combine(Path.GetDirectoryName(deployInfo.ProjectFullName), deployInfo.Build.PlatformName, deployInfo.Build.ConfigurationName);

                        buildFileFullname = Path.Combine(deployInfo.Build.BuildPath, deployInfo.OutputFileName);

                        LoggingManager.Instance.Logger.Warn(string.Format("could not create the orignal file for cpp project, checking if file {0} exists", buildFileFullname));

                        if (File.Exists(buildFileFullname))
                        {
                            fileDll.Source = buildFileFullname;

                            if (filePdb != null)
                                filePdb.Source = StringUtil.ReplaceLastOccurrence(buildFileFullname, Resources.ExtensionDLL, Resources.ExtensionPDB);

                            XmlUtil.Serialize(deployInfo.NuSpecFileFullName, deployInfo.NuSpecPackage);

                            return;
                        }
                    }
                }
                throw new ProjectBuildFailedExceptions(!string.IsNullOrEmpty(error) ? string.Format("An Error occured during the build process: {0}", error) :
                                                                                        string.Format("Could not create file: {0}", buildFileFullname));
            }
            LoggingManager.Instance.Logger.Debug("building project finished");
        }
        /// <summary>
        /// initializes the gui using the information provided in the transit object
        /// </summary>
        /// <param name="info"></param>
        private void InitializeUI(PackageInformation packageInfo)
        {
            _deployInfo = new DeploymentInformation(packageInfo);

            Text = string.Format("{0} - Version {1}", _deployInfo.NuSpecPackage.Metadata.Id, _deployInfo.NuSpecPackage.Metadata.Version);

            //-----set nuspec metadata
            SetNuSpecMetadataInfo(_deployInfo.ProjectOptions);
            SetNuSpecMetadata(_deployInfo.NuSpecPackage.Metadata);

            //-----set nuspec dependencies
            SetNuSpecDependenciesInfo(_deployInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Metadata);
            SetNuSpecDependencies(_deployInfo.NuSpecPackage.Metadata.DependencyGroups);

            //-----set nuspec files
            SetNuSpecFilesInfo(_deployInfo.ProjectOptions.NuGetOptions.NuSpecOptions.Files);
            SetNuSpecFiles(_deployInfo.NuSpecPackage.Files);

            //-----set build
            SetBuildInfo(_deployInfo);
            SetBuild(_deployInfo);

            //-----load all nuget servers from config
            List<Xml.Settings.General.NuGet.Server> nuGetServers = new List<Xml.Settings.General.NuGet.Server>(OptionsManager.Instance.Configuration.GeneralOptions.NuGetOptions.Servers);
            nuGetServers.Add(new Xml.Settings.General.NuGet.Server() { Url = Resources.NewEntryIndicator });
            nuGetServers.ForEach(ns => _uiNuGetServer.Items.Add(ns));
            if (_uiNuGetServer.Items.Count > 1)
            {
                Xml.Settings.General.NuGet.Server usedNugetServer = null;

                switch (OptionsManager.Instance.Configuration.GeneralOptions.NuGetOptions.ServerUsage)
                {
                    case Enumerations.NuGetServerUsage.First:
                        usedNugetServer = nuGetServers.First();
                        _toolTip.SetToolTip(_uiNuGetServerUsageInfo, string.Format("The NuGet server usage option is set to select the first server in the list"));
                        break;

                    case Enumerations.NuGetServerUsage.Preferred:
                        usedNugetServer = nuGetServers.FirstOrDefault(s => s.IsPreferred) ?? nuGetServers.FirstOrDefault();
                        _toolTip.SetToolTip(_uiNuGetServerUsageInfo, string.Format("The NuGet server usage option is set to select the prefered server"));
                        break;

                    case Enumerations.NuGetServerUsage.LastUsed:
                        usedNugetServer = nuGetServers.OrderByDescending(s => s.LastAttemptedDeploy).FirstOrDefault();
                        _toolTip.SetToolTip(_uiNuGetServerUsageInfo, string.Format("The NuGet server usage option is set to select the last used server"));
                        break;
                }

                _uiNuGetServer.SelectedItem = usedNugetServer;
            }

            //-----load all ms build exe paths from config
            List<string> msBuildPaths = new List<string>(OptionsManager.Instance.Configuration.GeneralOptions.MsBuildOptions.ExePaths);
            msBuildPaths.Add(Resources.NewEntryIndicator);
            msBuildPaths.ForEach(msb => _uiMsBuilds.Items.Add(msb));
            if (_uiMsBuilds.Items.Count > 1)
                _uiMsBuilds.SelectedIndex = 0;
        }