Example #1
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);
        }