Пример #1
0
        /// <summary>
        /// package the nuspec file
        /// </summary>
        /// <returns>true, if successful</returns>
        private bool PublishPack(string additionalOptions, NuspecItemInfo item, string pkgFullPath, NuspecItemConfig itemConfig)
        {
            WriteOutput($"Uploading nuspec file: {pkgFullPath}");

            var startInfo        = new ProcessStartInfo(itemConfig.NuGetExe);
            var publishUrlAppend = (itemConfig.AppendV2ApiTrait ?? false) ? "api/v2/package" : "";

            startInfo.Arguments = $"push {pkgFullPath} {itemConfig.RemoteFeedApiKey} -Source {itemConfig.PublishUrl}{publishUrlAppend} {additionalOptions}";
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            startInfo.CreateNoWindow         = true;
            startInfo.UseShellExecute        = false;
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            var process = System.Diagnostics.Process.Start(startInfo);

            process.WaitForExit();

            var output = process.StandardOutput.ReadToEnd();

            WriteOutput(output);

            if (process.ExitCode == 0)
            {
                WriteOutput("Successfully published nupkg file: " + pkgFullPath);
                return(true);
            }
            else
            {
                var error = process.StandardError.ReadToEnd();
                WriteOutput("Error publish nupkg file: " + pkgFullPath + Environment.NewLine + "ERROR: " + error);
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// package the nuspec file
        /// </summary>
        /// <returns>true, if successful</returns>
        private bool Pack(string additionalOptions, NuspecItemInfo item, NuspecItemConfig itemConfig, ref string outputFile)
        {
            WriteOutput("Packing nuspec file: " + item.FileName);

            var startInfo = new ProcessStartInfo(itemConfig.NuGetExe);

            startInfo.Arguments = $"pack \"{item.FileName}\" -NoDefaultExcludes -OutputDirectory \"{itemConfig.OutputPath}\" {additionalOptions}";
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            startInfo.CreateNoWindow         = true;
            startInfo.UseShellExecute        = false;
            startInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            var process = System.Diagnostics.Process.Start(startInfo);

            process.WaitForExit();

            var output = process.StandardOutput.ReadToEnd();

            WriteOutput(output);

            if (process.ExitCode == 0)
            {
                var regx = new Regex(@"(')([^']+)\1");
                outputFile = regx.Matches(output).Cast <Match>().Select(m => m.Groups[2].Value).Last();
                WriteOutput("Successfully packed nuspec file: " + item.FileName);
                return(true);
            }
            else
            {
                outputFile = null;
                var error = process.StandardError.ReadToEnd();
                WriteOutput("Error packing nuspec file: " + item.FileName + Environment.NewLine + "ERROR: " + error);
                return(false);
            }
        }
Пример #3
0
        private bool ValidateOptions(NuspecItemInfo item, NuspecItemConfig itemConfig)
        {
            if (!File.Exists(itemConfig.NuGetExe))
            {
                WriteOutput("NuspecPackager configuration error: The path to NuGet.exe is not valid: " + itemConfig.NuGetExe);
                return(false);
            }

            //clean up path a little
            itemConfig.OutputPath = itemConfig.OutputPath.TrimEnd(new[] { '/', '\\' });

            if (!Directory.Exists(itemConfig.OutputPath))
            {
                //try to create it
                WriteOutput("NuspecPackager configuration error: The output directory does not exist, and could not be created.");
                if (!String.IsNullOrWhiteSpace(itemConfig.OutputPath))
                {
                    try
                    {
                        WriteOutput("NuspecPackager configuration warning: Trying to create the output directory: " + itemConfig.OutputPath);
                        Directory.CreateDirectory(itemConfig.OutputPath);
                    }
                    catch { }
                }
                if (!Directory.Exists(itemConfig.OutputPath))
                {
                    WriteOutput("NuspecPackager configuration error: The output directory does not exist, and could not be created.");
                    return(false);
                }
            }
            return(true);
        }
Пример #4
0
        /// <summary>
        /// build the current project before packaging
        /// </summary>
        /// <returns>true, if successful</returns>
        private bool BuildProject(NuspecItemInfo item)
        {
            var optionPage = GetOptionsPage();

            if (!optionPage.BuildBeforePackaging)
            {
                return(true);
            }

            WriteOutput("Building project: " + item.ProjectName, true);

            var dte = (DTE2)GetService(typeof(SDTE));

            dte.Events.BuildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone;
            dte.Events.BuildEvents.OnBuildDone           += BuildEvents_OnBuildDone;
            var solutionFile = dte.Solution.FullName;

            _myBuildInProgress   = true;
            _overallBuildSuccess = true;

            var activeConfigurationName = dte.Solution.SolutionBuild.ActiveConfiguration.Name;

            //dte.Solution.SolutionBuild.Clean(true);
            dte.Solution.SolutionBuild.BuildProject(activeConfigurationName, item.ProjectUniqueName, true);

            dte.Events.BuildEvents.OnBuildProjConfigDone -= BuildEvents_OnBuildProjConfigDone;
            dte.Events.BuildEvents.OnBuildDone           -= BuildEvents_OnBuildDone;

            return(_overallBuildSuccess);
        }
Пример #5
0
        internal static NuspecItemConfig GetNuspecItemConfig(NuspecItemInfo item)
        {
            var filePath = Path.Combine(item.Directory, item.Name + "." + DIRECTORY_CONFIG_FILE_NAME);

            if (File.Exists(filePath))
            {
                return(Deserialize <NuspecItemConfig>(filePath));
            }
            else
            {
                return(new NuspecItemConfig());
            }
        }
        private bool ValidateOptions(NuspecItemInfo item, NuspecItemConfig itemConfig)
        {
            if (!File.Exists(itemConfig.NuGetExe))
            {
                WriteOutput("NuspecPackager configuration error: The path to NuGet.exe is not valid: " + itemConfig.NuGetExe);
                return false;
            }

            //clean up path a little
            itemConfig.OutputPath = itemConfig.OutputPath.TrimEnd(new[] { '/', '\\' });

            if (!Directory.Exists(itemConfig.OutputPath))
            {
                //try to create it
                WriteOutput("NuspecPackager configuration error: The output directory does not exist, and could not be created.");
                if (!String.IsNullOrWhiteSpace(itemConfig.OutputPath))
                {
                    try
                    {
                        WriteOutput("NuspecPackager configuration warning: Trying to create the output directory: " + itemConfig.OutputPath);
                        Directory.CreateDirectory(itemConfig.OutputPath);
                    }
                    catch { }
                }
                if (!Directory.Exists(itemConfig.OutputPath))
                {
                    WriteOutput("NuspecPackager configuration error: The output directory does not exist, and could not be created.");
                    return false;
                }
            }
            return true;
        }
        /// <summary>
        /// package the nuspec file
        /// </summary>
        /// <returns>true, if successful</returns>
        private bool PublishPack(string additionalOptions, NuspecItemInfo item, string pkgFullPath, NuspecItemConfig itemConfig)
        {
            WriteOutput($"Uploading nuspec file: {pkgFullPath}");

            var startInfo = new ProcessStartInfo(itemConfig.NuGetExe);
            var publishUrlAppend = (itemConfig.AppendV2ApiTrait ?? false) ? "api/v2/package" : "";
            startInfo.Arguments = $"push {pkgFullPath} {itemConfig.RemoteFeedApiKey} -Source {itemConfig.PublishUrl}{publishUrlAppend} {additionalOptions}";
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
            startInfo.CreateNoWindow = true;
            startInfo.UseShellExecute = false;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            var process = System.Diagnostics.Process.Start(startInfo);

            process.WaitForExit();

            var output = process.StandardOutput.ReadToEnd();
            WriteOutput(output);

            if (process.ExitCode == 0)
            {
                WriteOutput("Successfully published nupkg file: " + pkgFullPath);
                return true;
            }
            else
            {
                var error = process.StandardError.ReadToEnd();
                WriteOutput("Error publish nupkg file: " + pkgFullPath + Environment.NewLine + "ERROR: " + error);
                return false;
            }
        }
        /// <summary>
        /// package the nuspec file
        /// </summary>
        /// <returns>true, if successful</returns>
        private bool Pack(string additionalOptions, NuspecItemInfo item, NuspecItemConfig itemConfig, ref string outputFile)
        {
            WriteOutput("Packing nuspec file: " + item.FileName);

            var startInfo = new ProcessStartInfo(itemConfig.NuGetExe);
            startInfo.Arguments = $"pack \"{item.FileName}\" -NoDefaultExcludes -OutputDirectory \"{itemConfig.OutputPath}\" {additionalOptions}";
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
            startInfo.CreateNoWindow = true;
            startInfo.UseShellExecute = false;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            var process = System.Diagnostics.Process.Start(startInfo);

            process.WaitForExit();

            var output = process.StandardOutput.ReadToEnd();
            WriteOutput(output);

            if (process.ExitCode == 0)
            {
                var regx = new Regex(@"(')([^']+)\1");
                outputFile = regx.Matches(output).Cast<Match>().Select(m => m.Groups[2].Value).Last();
                WriteOutput("Successfully packed nuspec file: " + item.FileName);
                return true;
            }
            else
            {
                outputFile = null;
                var error = process.StandardError.ReadToEnd();
                WriteOutput("Error packing nuspec file: " + item.FileName + Environment.NewLine + "ERROR: " + error);
                return false;
            }
        }
        private NuspecItemConfig GetItemConfig(NuspecItemInfo item)
        {
            var dte = (DTE2)GetService(typeof(SDTE));
            var optionPage = GetOptionsPage();
            //get the config options from VS Options Dialog
            var defaultConfig = new NuspecItemConfig
            {
                NuGetExe = optionPage.NuGetExeDir,
                OutputPath = optionPage.DefaultOutputPath,
                PackFromProject = optionPage.PackFromProject,
                AppendV2ApiTrait = optionPage.AppendV2ApiTrait,
                RemoteFeedApiKey = optionPage.RemoteFeedApiKey,
                PublishUrl = optionPage.PublishUrl,
                UploadToFeed = optionPage.UploadToFeed
            };

            if (!String.IsNullOrEmpty(optionPage.NuGetExeDir))
            {
                //use global config as default nuget exe dir
                defaultConfig.NuGetExe = Path.Combine(optionPage.NuGetExeDir, "NuGet.exe");
            }
            else
            {
                //default path is at same level as item
                defaultConfig.NuGetExe = Path.Combine(item.Directory, "NuGet.exe");

                //if exe not there, then let default path be at .nuget folder at solution level
                if (!File.Exists(defaultConfig.NuGetExe))
                {
                    WriteOutput("Could not find nuget.exe at: " + defaultConfig.NuGetExe);

                    defaultConfig.NuGetExe = Path.Combine(Path.GetDirectoryName(dte.Solution.FullName), ".nuget\\NuGet.exe");

                    if (!File.Exists(defaultConfig.NuGetExe))
                    {
                        WriteOutput("Could not find nuget.exe at: " + defaultConfig.NuGetExe);
                        WriteOutput("Create a NuspecPackager.config file or set the NugetExeDir property in the Visual Studio options page to specify a directory where nuget.exe is located.");
                    }
                }
            }

            //get config otions from folder's default config file
            var folderConfig = Util.GetDirectoryConfig(item);

            //get config options for this item's config file
            var itemConfig = Util.GetNuspecItemConfig(item);

            //merge properties from folder and default into item config's empty properties
            itemConfig.MergeFrom(folderConfig);
            itemConfig.MergeFrom(defaultConfig);

            // TODO: Resolve envrionment variable here.
            var regx = new Regex(@"\$\(([^)]*)\)");
            var envVars = regx.Matches(itemConfig.OutputPath);
            if (envVars.Count > 0)
            {
                WriteOutput($"Environment variable found in the output path. Resolving varables...");
                var prj = item.Project;
                if (prj == null)
                {
                    WriteOutput($"Failed to find the project {item.ProjectPath}...");
                }
                else
                {
                    foreach (Match match in envVars)
                    {
                        var varName = match.Groups[1].Value;
                        WriteOutput($"Resolving varable {varName}...");
                        var varValue = prj.ConfigurationManager.ActiveConfiguration.Properties.Item(varName)?.Value?.ToString();
                        WriteOutput($"Resolved varable {varName}: {varValue}.");
                        if (!string.IsNullOrEmpty(varValue))
                        {
                            itemConfig.OutputPath = match.Result(varValue);
                            WriteOutput($"Replaced string: {itemConfig.OutputPath}");
                        }
                    }
                }
            }

            itemConfig.EnsureAbsolutePaths(item);

            return itemConfig;
        }
        /// <summary>
        /// build the current project before packaging
        /// </summary>
        /// <returns>true, if successful</returns>
        private bool BuildProject(NuspecItemInfo item)
        {
            var optionPage = GetOptionsPage();

            if (!optionPage.BuildBeforePackaging)
            {
                return true;
            }

            WriteOutput("Building project: " + item.ProjectName, true);

            var dte = (DTE2)GetService(typeof(SDTE));
            dte.Events.BuildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone;
            dte.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone;
            var solutionFile = dte.Solution.FullName;
            _myBuildInProgress = true;
            _overallBuildSuccess = true;

            var activeConfigurationName = dte.Solution.SolutionBuild.ActiveConfiguration.Name;
            //dte.Solution.SolutionBuild.Clean(true);
            dte.Solution.SolutionBuild.BuildProject(activeConfigurationName, item.ProjectUniqueName, true);

            dte.Events.BuildEvents.OnBuildProjConfigDone -= BuildEvents_OnBuildProjConfigDone;
            dte.Events.BuildEvents.OnBuildDone -= BuildEvents_OnBuildDone;

            return _overallBuildSuccess;
        }
Пример #11
0
 internal void EnsureAbsolutePaths(NuspecItemInfo item)
 {
     this.NuGetExe   = Util.EnsureAbsolutePath(this.NuGetExe, item.Directory);
     this.OutputPath = Util.EnsureAbsolutePath(this.OutputPath, item.Directory);
 }
        /// <summary>
        /// package the nuspec file
        /// </summary>
        /// <returns>true, if successful</returns>
        private void Pack(string additionalOptions, NuspecItemInfo item, NuspecItemConfig itemConfig)
        {
            WriteOutput("Packing nuspec file: " + item.FileName);

            var startInfo = new ProcessStartInfo(itemConfig.NuGetExe);
            startInfo.Arguments = string.Format(
                "pack \"{0}\" -NoDefaultExcludes -OutputDirectory \"{1}\" {2}",
                item.FileName, itemConfig.OutputPath, additionalOptions);
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError = true;
            startInfo.CreateNoWindow = true;
            startInfo.UseShellExecute = false;
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            var process = System.Diagnostics.Process.Start(startInfo);

            process.WaitForExit();

            var output = process.StandardOutput.ReadToEnd();
            WriteOutput(output);

            if (process.ExitCode == 0)
            {
                WriteOutput("Successfully packed nuspec file: " + item.FileName);
            }
            else
            {
                var error = process.StandardError.ReadToEnd();
                WriteOutput("Error packing nuspec file: " + item.FileName + Environment.NewLine + "ERROR: " + error);
            }
        }
        private NuspecItemConfig GetItemConfig(NuspecItemInfo item)
        {
            var dte = (DTE2)GetService(typeof(SDTE));
            var optionPage = GetOptionsPage();
            //get the config options from VS Options Dialog
            var defaultConfig = new NuspecItemConfig
            {
                NuGetExe = optionPage.CustomNuGetExePath,
                OutputPath = optionPage.DefaultOutputPath
            };
            if (optionPage.UseDefaultNuGetExePath)
            {
                defaultConfig.NuGetExe = Path.Combine(Path.GetDirectoryName(dte.Solution.FullName), ".nuget\\NuGet.exe");
            }

            //get config otions from folder's default config file
            var folderConfig = Util.GetDirectoryConfig(item);

            //get config options for this item's config file
            var itemConfig = Util.GetNuspecItemConfig(item);

            //merge properties from folder and default into item config's empty properties
            itemConfig.MergeFrom(folderConfig);
            itemConfig.MergeFrom(defaultConfig);
            itemConfig.EnsureAbsolutePaths(item);

            return itemConfig;
        }
Пример #14
0
 internal void EnsureAbsolutePaths(NuspecItemInfo item)
 {
     this.NuGetExe = Util.EnsureAbsolutePath(this.NuGetExe, item.Directory);
     this.OutputPath = Util.EnsureAbsolutePath(this.OutputPath, item.Directory);
 }
Пример #15
0
        private NuspecItemConfig GetItemConfig(NuspecItemInfo item)
        {
            var dte        = (DTE2)GetService(typeof(SDTE));
            var optionPage = GetOptionsPage();
            //get the config options from VS Options Dialog
            var defaultConfig = new NuspecItemConfig
            {
                NuGetExe         = optionPage.NuGetExeDir,
                OutputPath       = optionPage.DefaultOutputPath,
                PackFromProject  = optionPage.PackFromProject,
                AppendV2ApiTrait = optionPage.AppendV2ApiTrait,
                RemoteFeedApiKey = optionPage.RemoteFeedApiKey,
                PublishUrl       = optionPage.PublishUrl,
                UploadToFeed     = optionPage.UploadToFeed
            };

            if (!String.IsNullOrEmpty(optionPage.NuGetExeDir))
            {
                //use global config as default nuget exe dir
                defaultConfig.NuGetExe = Path.Combine(optionPage.NuGetExeDir, "NuGet.exe");
            }
            else
            {
                //default path is at same level as item
                defaultConfig.NuGetExe = Path.Combine(item.Directory, "NuGet.exe");

                //if exe not there, then let default path be at .nuget folder at solution level
                if (!File.Exists(defaultConfig.NuGetExe))
                {
                    WriteOutput("Could not find nuget.exe at: " + defaultConfig.NuGetExe);

                    defaultConfig.NuGetExe = Path.Combine(Path.GetDirectoryName(dte.Solution.FullName), ".nuget\\NuGet.exe");

                    if (!File.Exists(defaultConfig.NuGetExe))
                    {
                        WriteOutput("Could not find nuget.exe at: " + defaultConfig.NuGetExe);
                        WriteOutput("Create a NuspecPackager.config file or set the NugetExeDir property in the Visual Studio options page to specify a directory where nuget.exe is located.");
                    }
                }
            }


            //get config otions from folder's default config file
            var folderConfig = Util.GetDirectoryConfig(item);

            //get config options for this item's config file
            var itemConfig = Util.GetNuspecItemConfig(item);

            //merge properties from folder and default into item config's empty properties
            itemConfig.MergeFrom(folderConfig);
            itemConfig.MergeFrom(defaultConfig);

            // TODO: Resolve envrionment variable here.
            var regx    = new Regex(@"\$\(([^)]*)\)");
            var envVars = regx.Matches(itemConfig.OutputPath);

            if (envVars.Count > 0)
            {
                WriteOutput($"Environment variable found in the output path. Resolving varables...");
                var prj = item.Project;
                if (prj == null)
                {
                    WriteOutput($"Failed to find the project {item.ProjectPath}...");
                }
                else
                {
                    foreach (Match match in envVars)
                    {
                        var varName = match.Groups[1].Value;
                        WriteOutput($"Resolving varable {varName}...");
                        var varValue = prj.ConfigurationManager.ActiveConfiguration.Properties.Item(varName)?.Value?.ToString();
                        WriteOutput($"Resolved varable {varName}: {varValue}.");
                        if (!string.IsNullOrEmpty(varValue))
                        {
                            itemConfig.OutputPath = match.Result(varValue);
                            WriteOutput($"Replaced string: {itemConfig.OutputPath}");
                        }
                    }
                }
            }

            itemConfig.EnsureAbsolutePaths(item);

            return(itemConfig);
        }