Ejemplo n.º 1
0
        /// <summary>
        /// validate the options and show message for the first invalid option.
        /// </summary>
        public bool ValidateOptions()
        {
            //can't validate relative, because it is dynamic depending on the .nuspec file being packaged
            if (Path.IsPathRooted(this.DefaultOutputPath) && !Directory.Exists(this.DefaultOutputPath))
            {
                MessageBoxHelper.ShowMessageBox("Default Output Path must specify an existing directory.  This setting can be changed in the Visual Studio Options dialog.", OLEMSGICON.OLEMSGICON_CRITICAL);
                return(false);
            }

            if (!String.IsNullOrWhiteSpace(this.NuGetExeDir) && !Directory.Exists(this.NuGetExeDir))
            {
                MessageBoxHelper.ShowMessageBox("NuGet.exe Path must either be empty or specify an existing directory.  This setting can be changed in the Visual Studio Options dialog.", OLEMSGICON.OLEMSGICON_CRITICAL);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private void PackageNuspecFiles(List <NuspecItemInfo> nuspecItems, string additionalOptions = "", bool buildFromProject = false)
        {
            Logger.Clear();
            WriteOutput("Nuspec Packager starting...", true);
            var hasErrors = false;

            try
            {
                foreach (var item in nuspecItems)
                {
                    WriteOutput("Processing nuspec file: " + item.FileName);

                    //get configuration for this nuspec file and make sure it is valid
                    NuspecItemConfig itemConfig = GetItemConfig(item);
                    if (!ValidateOptions(item, itemConfig))
                    {
                        hasErrors = true;
                        WriteOutput("Skipping nuspec file: " + item.Name);
                        continue;
                    }

                    //build the project
                    var buildSuccess = BuildProject(item);
                    if (!buildSuccess)
                    {
                        hasErrors = true;
                        WriteOutput("Skipping nuspec file: " + item.Name);
                        continue;
                    }

                    var outputPkgPath = "";
                    if (buildFromProject || (itemConfig.PackFromProject ?? false))
                    {
                        var actualFileToProcess = item.ProjectPath;
                        WriteOutput("Handling file: " + actualFileToProcess);
                        hasErrors = !Pack(additionalOptions, new NuspecItemInfo()
                        {
                            Project           = item.Project,
                            FileName          = actualFileToProcess, // item.ProjectItem.Properties.Item("FullPath").Value,
                            ProjectPath       = item.ProjectPath,
                            ProjectUniqueName = item.ProjectUniqueName,
                            ProjectName       = item.ProjectName
                        }, itemConfig, ref outputPkgPath) || hasErrors;
                    }
                    else
                    {
                        //process the nuspec file and keep track if any errors occur
                        var actualFileToProcess = item.FileName;
                        WriteOutput("Handling file: " + actualFileToProcess);
                        hasErrors = !Pack(additionalOptions, item, itemConfig, ref outputPkgPath) || hasErrors;
                    }

                    WriteOutput($"Trying to upload {outputPkgPath}...{itemConfig.UploadToFeed}");
                    if ((itemConfig.UploadToFeed ?? false) && !hasErrors && !string.IsNullOrEmpty(outputPkgPath))
                    {
                        hasErrors = !this.PublishPack(additionalOptions, item, outputPkgPath, itemConfig) || hasErrors;
                    }
                }
            }

            catch (Exception ex)
            {
                var message = string.Format(CultureInfo.CurrentCulture, "Exception during NuspecPackagerFiles() of {0}: {1}", this.ToString(), ex.Message);
                WriteOutput(message);
                MessageBoxHelper.ShowMessageBox(message, OLEMSGICON.OLEMSGICON_CRITICAL);
                hasErrors = true;
            }

            //display final result
            var msg = "Nuspec Packager finished " + (hasErrors ? "with errors." : "successfully.");

            WriteOutput(msg, showInStatus: true);
        }