コード例 #1
0
        /// <summary>
        /// This method will set the active package source of PowerShell Console by source name.
        /// </summary>
        /// <param name="projectNames">The project name to be set to.</param>
        /// <returns>Boolean indicating success or failure.</returns>
        protected bool SetPackageSourceByName(string sourceName)
        {
            var    host           = PowerShellHostService.CreateHost(PowerConsoleHostName, false);
            var    allSourceNames = host.GetPackageSources().ToList();
            string match          = allSourceNames.Where(p => string.Equals(p, sourceName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (string.IsNullOrEmpty(match))
            {
                Log(MessageLevel.Error, Resources.Cmdlet_PackageSourceNotFound, sourceName);
                return(false);
            }
            else
            {
                try
                {
                    host.ActivePackageSource    = match;
                    this.ActiveSourceRepository = GetActiveRepository(match);
                    Log(MessageLevel.Info, Resources.Cmdlet_PackageSourceSet, match);
                    return(true);
                }
                catch (Exception ex)
                {
                    WriteError(ex);
                    return(false);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// This method will set the default project of PowerShell Console by project name.
        /// </summary>
        /// <param name="projectNames">The project name to be set to.</param>
        /// <returns>Boolean indicating success or failure.</returns>
        protected bool SetProjectsByName(string projectName)
        {
            var    host = PowerShellHostService.CreateHost(PowerConsoleHostName, false);
            var    allValidProjectNames = host.GetAvailableProjects().ToList();
            string match = allValidProjectNames.Where(p => string.Equals(p, projectName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            int    matchIndex;

            if (string.IsNullOrEmpty(match))
            {
                ErrorHandler.WriteProjectNotFoundError(projectName, terminating: false);
                return(false);
            }
            else
            {
                try
                {
                    matchIndex = allValidProjectNames.IndexOf(match);
                    host.SetDefaultProjectIndex(matchIndex);
                    _solutionManager.DefaultProjectName = match;
                    Log(MessageLevel.Info, Resources.Cmdlet_ProjectSet, match);
                    return(true);
                }
                catch (Exception ex)
                {
                    WriteError(ex);
                    return(false);
                }
            }
        }
コード例 #3
0
        private static IHost CreatePowerShellHost(bool @async)
        {
            // backdoor: allow turning off async mode by setting enviroment variable NuGetSyncMode=1
            string syncModeFlag = Environment.GetEnvironmentVariable("NuGetSyncMode", EnvironmentVariableTarget.User);

            if (syncModeFlag == "1")
            {
                @async = false;
            }

            return(PowerShellHostService.CreateHost(PowerConsoleHostName, @async));
        }