Ejemplo n.º 1
0
        protected override void ProcessRecord()
        {
            WriteDebug("Process record");

            var globalProperties = Property?.Cast <DictionaryEntry>().ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());

            globalProperties = globalProperties ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            var projects = string.IsNullOrEmpty(Project)
                ? new[] { SessionState.Path.CurrentFileSystemLocation.Path }
                : new[] { Project };
            var projectFile = MSBuildApp.ProcessProjectSwitch(projects, IgnoreProjectExtensions, Directory.GetFiles);

            if (!string.IsNullOrEmpty(Configuration))
            {
                globalProperties[nameof(Configuration)] = Configuration;
            }

            if (!string.IsNullOrEmpty(Platform))
            {
                globalProperties[nameof(Platform)] = Platform;
            }

            string outputFile = null;

            if (!string.IsNullOrEmpty(OutputFile))
            {
                outputFile = Path.GetFullPath(Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, OutputFile));
            }

            if (FileUtilities.IsSolutionFilename(projectFile))
            {
                PreprocessSolution(projectFile, globalProperties, ToolsVersion, outputFile);
            }
            else
            {
                PreprocessProject(projectFile, globalProperties, ToolsVersion, outputFile);
            }
        }
        public IEnumerable <CompletionResult> CompleteArgument(
            string commandName,
            string parameterName,
            string wordToComplete,
            CommandAst commandAst,
            IDictionary fakeBoundParameters)
        {
            var property                = GetParameter <Hashtable>(fakeBoundParameters, nameof(InvokeMSBuild.Property));
            var toolsVersion            = GetParameter <string>(fakeBoundParameters, nameof(InvokeMSBuild.ToolsVersion));
            var projectPath             = GetParameter <string>(fakeBoundParameters, nameof(InvokeMSBuild.Project));
            var ignoreProjectExtensions = GetParameter <string[]>(fakeBoundParameters, nameof(InvokeMSBuild.IgnoreProjectExtensions));
            var target        = GetParameter <string[]>(fakeBoundParameters, nameof(InvokeMSBuild.Target));
            var configuration = GetParameter <string>(fakeBoundParameters, nameof(InvokeMSBuild.Configuration));
            var platform      = GetParameter <string>(fakeBoundParameters, nameof(InvokeMSBuild.Platform));

            var properties = property?.Cast <DictionaryEntry>().ToDictionary(x => x.Key.ToString(), x => x.Value.ToString(), StringComparer.OrdinalIgnoreCase);

            properties = properties ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            if (!string.IsNullOrEmpty(configuration))
            {
                properties[nameof(InvokeMSBuild.Configuration)] = configuration;
            }

            if (!string.IsNullOrEmpty(platform))
            {
                properties[nameof(InvokeMSBuild.Platform)] = platform;
            }

            if (string.IsNullOrEmpty(toolsVersion))
            {
                toolsVersion = InvokeMSBuildParameters.DefaultToolsVersion;
            }

            var sessionState = new SessionState();
            var projects     = string.IsNullOrEmpty(projectPath)
                ? new[] { sessionState.Path.CurrentFileSystemLocation.Path }
                : new[] { Path.Combine(sessionState.Path.CurrentFileSystemLocation.Path, projectPath) };
            var projectFile = MSBuildApp.ProcessProjectSwitch(projects, ignoreProjectExtensions, Directory.GetFiles);

            var parameters = new InvokeMSBuildParameters
            {
                Properties   = properties,
                ToolsVersion = toolsVersion,
                Project      = projectFile,
                Target       = target
            };

            var completionResults = FileUtilities.IsSolutionFilename(projectFile)
                ? GetSolutionCompletionResults(parameters)
                : GetProjectCompletionResults(parameters);

            if (!string.IsNullOrEmpty(wordToComplete))
            {
                completionResults = completionResults.Where(x => x.StartsWith(wordToComplete, StringComparison.InvariantCultureIgnoreCase));
            }

            return(completionResults
                   .OrderBy(x => x)
                   .Select(x => new CompletionResult(EscapeIfRequired(x), x, CompletionResultType.ParameterValue, "tool tip"))
                   .ToArray());
        }
Ejemplo n.º 3
0
        protected override void ProcessRecord()
        {
            WriteDebug("Process record");

            var properties = Property?.Cast <DictionaryEntry>().ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());

            properties = properties ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            var projects = string.IsNullOrEmpty(Project)
                ? new[] { SessionState.Path.CurrentFileSystemLocation.Path }
                : new[] { Project };
            var project = MSBuildApp.ProcessProjectSwitch(projects, IgnoreProjectExtensions, Directory.GetFiles);

            if (!string.IsNullOrEmpty(Configuration))
            {
                properties[nameof(Configuration)] = Configuration;
            }

            if (!string.IsNullOrEmpty(Platform))
            {
                properties[nameof(Platform)] = Platform;
            }

            _msBuildHelper.Parameters = new InvokeMSBuildParameters
            {
                Project          = project,
                Verbosity        = Verbosity,
                ToolsVersion     = ToolsVersion,
                Target           = Target,
                MaxCpuCount      = MaxCpuCount,
                NodeReuse        = NodeReuse ?? Environment.GetEnvironmentVariable("MSBUILDDISABLENODEREUSE") != "1",
                Properties       = properties,
                DetailedSummary  = DetailedSummary || Verbosity == LoggerVerbosity.Diagnostic,
                WarningsAsErrors = WarningsAsErrors == null
                    ? null
                    : new HashSet <string>(WarningsAsErrors, StringComparer.InvariantCultureIgnoreCase),
                WarningsAsMessages = WarningsAsMessages == null
                    ? null
                    : new HashSet <string>(WarningsAsMessages, StringComparer.InvariantCultureIgnoreCase)
            };

            var     loggers = new List <ILogger>();
            ILogger consoleLogger;

            if (Logger != null)
            {
                loggers.AddRange(Logger);
            }

            var consoleLoggerType = GetConsoleLoggerType();

            switch (consoleLoggerType)
            {
            case ConsoleLoggerType.Streams:
                consoleLogger = Factory.PowerShellInstance.CreateConsoleLogger(Verbosity, ConsoleLoggerParameters, false);
                break;

            case ConsoleLoggerType.PSHost:
                consoleLogger = Factory.PowerShellInstance.CreateConsoleLogger(Verbosity, ConsoleLoggerParameters, true);
                break;

            case ConsoleLoggerType.None:
                consoleLogger = null;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }

            if (consoleLogger != null)
            {
                loggers.Add(consoleLogger);
            }

            var eventSink = new PSEventSink(this);

            foreach (var psLogger in loggers.OfType <IPSLogger>())
            {
                psLogger.Initialize(eventSink);
            }

            var crossDomainLoggers = (
                from unknownLogger in loggers
                group unknownLogger by unknownLogger is MarshalByRefObject
                into marshalByRefLogger
                from logger in MakeLoggersCrossDomain(marshalByRefLogger.Key, marshalByRefLogger)
                select logger).ToArray();

            _msBuildHelper.Loggers = crossDomainLoggers;

            try
            {
                var asyncResults = ProcessRecordAsync(eventSink);
                eventSink.ConsumeEvents();
                var results = asyncResults.Result;
                WriteObject(results, true);
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "ProcessRecordError", ErrorCategory.NotSpecified, null));
            }
        }
Ejemplo n.º 4
0
        protected override void ProcessRecord()
        {
            WriteDebug("Process record");

            var properties = Property?.Cast <DictionaryEntry>().ToDictionary(x => x.Key.ToString(), x => x.Value.ToString());

            properties = properties ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            var projects = string.IsNullOrEmpty(Project)
                ? new[] { SessionState.Path.CurrentFileSystemLocation.Path }
                : new[] { Project };
            var project = MSBuildApp.ProcessProjectSwitch(projects, IgnoreProjectExtensions, Directory.GetFiles);

            if (!string.IsNullOrEmpty(Configuration))
            {
                properties[nameof(Configuration)] = Configuration;
            }

            if (!string.IsNullOrEmpty(Platform))
            {
                properties[nameof(Platform)] = Platform;
            }

            _msBuildHelper.Parameters = new InvokeMSBuildParameters
            {
                Project          = project,
                Verbosity        = Verbosity,
                ToolsVersion     = ToolsVersion,
                Target           = Target,
                MaxCpuCount      = MaxCpuCount,
                NodeReuse        = NodeReuse ?? Environment.GetEnvironmentVariable("MSBUILDDISABLENODEREUSE") != "1",
                Properties       = properties,
                DetailedSummary  = DetailedSummary || Verbosity == LoggerVerbosity.Diagnostic,
                WarningsAsErrors = WarningsAsErrors == null
                    ? null
                    : new HashSet <string>(WarningsAsErrors, StringComparer.InvariantCultureIgnoreCase),
                WarningsAsMessages = WarningsAsMessages == null
                    ? null
                    : new HashSet <string>(WarningsAsMessages, StringComparer.InvariantCultureIgnoreCase)
            };

            var loggers = new List <LoggerDescription>();
            LoggerDescription consoleLogger;

            if (Logger != null)
            {
                loggers.AddRange(Logger);
            }

            var consoleLoggerType = GetConsoleLoggerType();

            switch (consoleLoggerType)
            {
            case ConsoleLoggerType.PSStreams:
                consoleLogger = new LoggerDescription
                {
                    Assembly   = NewConsoleLogger.Assembly,
                    ClassName  = NewConsoleLogger.PSStreamsLoggerClassName,
                    Parameters = ConsoleLoggerParameters,
                    Verbosity  = Verbosity
                };
                break;

            case ConsoleLoggerType.PSHost:
                consoleLogger = new LoggerDescription
                {
                    Assembly   = NewConsoleLogger.Assembly,
                    ClassName  = NewConsoleLogger.PSHostLoggerClassName,
                    Parameters = ConsoleLoggerParameters,
                    Verbosity  = Verbosity
                };
                break;

            case ConsoleLoggerType.None:
                consoleLogger = null;
                break;

            default:
                throw new InvalidEnumArgumentException();
            }

            if (consoleLogger != null)
            {
                loggers.Add(consoleLogger);
            }

            var eventSink = _msBuildHelper.PSEventSink = new PSEventSink(this);

            _msBuildHelper.Loggers = loggers;

            try
            {
                var asyncResults = ProcessRecordAsync(eventSink);
                eventSink.ConsumeEvents();
                var results = asyncResults.Result;
                WriteObject(results, true);
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "ProcessRecordError", ErrorCategory.NotSpecified, null));
            }
        }