예제 #1
0
        protected override void AddToContext(string fullPath, IImmutableDictionary <string, string> metadata, bool isActiveContext, IProjectDiagnosticOutputService logger)
        {
            string[]? folderNames = FileItemServices.GetLogicalFolderNames(Path.GetDirectoryName(_project.FullPath), fullPath, metadata);

            logger.WriteLine("Adding source file '{0}'", fullPath);
            Context.AddSourceFile(fullPath, isInCurrentContext: isActiveContext, folderNames: folderNames);
        }
예제 #2
0
 public void Dispose()
 {
     if (_builder != null)
     {
         _outputService.WriteLine(_builder.ToString());
     }
 }
        public void Handle(IComparable version, IProjectChangeDescription projectChange, ContextState state, IProjectDiagnosticOutputService logger)
        {
            Requires.NotNull(version, nameof(version));
            Requires.NotNull(projectChange, nameof(projectChange));
            Requires.NotNull(logger, nameof(logger));

            VerifyInitialized();

            foreach (string name in projectChange.Difference.ChangedProperties)
            {
                string value = projectChange.After.Properties[name];

                // Is it a property we're specifically aware of?
                if (TryHandleSpecificProperties(name, value, logger))
                {
                    continue;
                }

                // Otherwise, just pass it through
                logger.WriteLine("{0}: {1}", name, value);
                Context.SetProperty(name, value);
            }

            // NOTE: Roslyn treats "unset" as true, so always set it.
            Context.IsPrimary = state.IsActiveConfiguration;
        }
        /// <summary>
        ///     If <see cref="IProjectDiagnosticOutputService.IsEnabled"/> is <see langword="true"/>,
        ///     writes the text representation of the specified objects, followed
        ///     by the current line terminator, to the log using the specified
        ///     format information.
        /// </summary>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="logger"/> is <see langword="null"/>
        ///     <para>
        ///         -or-
        ///     </para>
        ///     <paramref name="format"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="FormatException">
        ///     The format specification in <paramref name="format"/> is invalid.
        /// </exception>
        public static void WriteLine(this IProjectDiagnosticOutputService logger, string format, object?argument1, object?argument2, object?argument3)
        {
            Requires.NotNull(logger, nameof(logger));

            if (logger.IsEnabled)
            {
                logger.WriteLine(string.Format(format, argument1, argument2, argument3));
            }
        }
예제 #5
0
 protected override void UpdateInContext(string fullPath, IImmutableDictionary <string, string> previousMetadata, IImmutableDictionary <string, string> currentMetadata, bool isActiveContext, IProjectDiagnosticOutputService logger)
 {
     if (LinkMetadataChanged(previousMetadata, currentMetadata))
     {
         logger.WriteLine("Removing and then re-adding source file '{0}' to <Link> metadata changes", fullPath);
         RemoveFromContext(fullPath, logger);
         AddToContext(fullPath, currentMetadata, isActiveContext, logger);
     }
 }
예제 #6
0
        public void Handle(IComparable version, IProjectChangeDescription projectChange, ContextState state, IProjectDiagnosticOutputService logger)
        {
            Requires.NotNull(version, nameof(version));
            Requires.NotNull(projectChange, nameof(projectChange));
            Requires.NotNull(logger, nameof(logger));

            VerifyInitialized();

            if (projectChange.Difference.ChangedProperties.Contains(ConfigurationGeneral.MSBuildProjectFullPathProperty))
            {
                string projectFilePath = projectChange.After.Properties[ConfigurationGeneral.MSBuildProjectFullPathProperty];
                string displayName     = GetDisplayName(projectFilePath);

                logger.WriteLine("DisplayName: {0}", displayName);
                logger.WriteLine("ProjectFilePath: {0}", projectFilePath);

                Context.ProjectFilePath = projectFilePath;
                Context.DisplayName     = displayName;
            }
        }
예제 #7
0
        private void ProcessProjectBuildFailure(IProjectRuleSnapshot snapshot)
        {
            Assumes.NotNull(_context);

            // If 'CompileDesignTime' didn't run due to a preceding failed target, or a failure in itself, IsEvaluationSucceeded returns false.
            //
            // We still forward those 'removes' of references, sources, etc onto Roslyn to avoid duplicate/incorrect results when the next
            // successful build occurs, because it will be diff between it and this failed build.

            bool succeeded = snapshot.IsEvaluationSucceeded();

            if (_context.LastDesignTimeBuildSucceeded != succeeded)
            {
                _logger.WriteLine(succeeded ? "Last design-time build succeeded, turning semantic errors back on." : "Last design-time build failed, turning semantic errors off.");
                _context.LastDesignTimeBuildSucceeded = succeeded;
            }
        }
        private bool TryHandleSpecificProperties(string name, string value, IProjectDiagnosticOutputService logger)
        {
            // The language service wants both the intermediate (bin\obj) and output (bin\debug)) paths
            // so that it can automatically hook up project-to-project references. It does this by matching the
            // bin output path with the another project's /reference argument, if they match, then it automatically
            // introduces a project reference between the two. We pass the intermediate path via the /out
            // command-line argument and set via one of the other handlers, where as the latter is calculated via
            // the TargetPath property and explicitly set on the context.

            if (StringComparers.PropertyNames.Equals(name, LanguageService.TargetPathProperty))
            {
                if (!string.IsNullOrEmpty(value))
                {
                    logger.WriteLine("BinOutputPath: {0}", value);
                    Context.BinOutputPath = value;
                }

                return(true);
            }

            return(false);
        }
예제 #9
0
 protected override void RemoveFromContext(string fullPath, IProjectDiagnosticOutputService logger)
 {
     logger.WriteLine("Removing source file '{0}'", fullPath);
     Context.RemoveSourceFile(fullPath);
 }