/// <summary>
 /// This method is used to flag errors in the project file being processed. Do NOT use this method in place of
 /// ErrorUtilities.VerifyThrow(), because ErrorUtilities.VerifyThrow() is used to flag internal/programming errors.
 /// 
 /// PERF WARNING: calling a method that takes a variable number of arguments is expensive, because memory is allocated for
 /// the array of arguments -- do not call this method repeatedly in performance-critical scenarios
 /// </summary>
 /// <param name="projectFile">The invalid project file.</param>
 /// <param name="resourceName">The resource string for the error message.</param>
 /// <param name="args">Extra arguments for formatting the error message.</param>
 internal static void ThrowInvalidProjectFile
 (
     BuildEventFileInfo projectFile,
     string resourceName,
     params object[] args
 )
 {
     VerifyThrowInvalidProjectFile(false, null, projectFile, resourceName, args);
 }
 /// <summary>
 /// This method is used to flag errors in the project file being processed. Do NOT use this method in place of
 /// ErrorUtilities.VerifyThrow(), because ErrorUtilities.VerifyThrow() is used to flag internal/programming errors.
 /// 
 /// PERF WARNING: calling a method that takes a variable number of arguments is expensive, because memory is allocated for
 /// the array of arguments -- do not call this method repeatedly in performance-critical scenarios
 /// </summary>
 /// <param name="condition">The condition to check.</param>
 /// <param name="projectFile">The invalid project file.</param>
 /// <param name="resourceName">The resource string for the error message.</param>
 /// <param name="args">Extra arguments for formatting the error message.</param>
 internal static void VerifyThrowInvalidProjectFile
 (
     bool condition,
     BuildEventFileInfo projectFile,
     string resourceName,
     params object[] args
 )
 {
     VerifyThrowInvalidProjectFile(condition, null, projectFile, resourceName, args);
 }
 /// <summary>
 /// Logs a warning
 /// </summary>
 /// <param name="buildEventContext">The event context</param>
 /// <param name="subcategoryResourceName">The subcategory resource</param>
 /// <param name="file">The file</param>
 /// <param name="messageResourceName">The message resource</param>
 /// <param name="messageArgs">The message args</param>
 public void LogWarning(BuildEventContext buildEventContext, string subcategoryResourceName, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs)
 {
 }
 /// <summary>
 /// Logs a generic fatal error
 /// </summary>
 /// <param name="buildEventContext">The build context</param>
 /// <param name="exception">The exception</param>
 /// <param name="file">The file</param>
 /// <param name="messageResourceName">The message resource</param>
 /// <param name="messageArgs">The message args</param>
 public void LogFatalError(BuildEventContext buildEventContext, Exception exception, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs)
 {
 }
 /// <summary>
 /// Logs a fatal build error
 /// </summary>
 /// <param name="buildEventContext">The event context</param>
 /// <param name="exception">The exception</param>
 /// <param name="file">The file</param>
 public void LogFatalBuildError(BuildEventContext buildEventContext, Exception exception, BuildEventFileInfo file)
 {
 }
        /// <summary>
        /// Logs a warning using the specified resource string.
        /// </summary>
        /// <param name="buildEventContext">Event context information which describes who is logging the event</param>
        /// <param name="subcategoryResourceName">Can be null.</param>
        /// <param name="file">File information which describes where the warning happened</param>
        /// <param name="messageResourceName">String name for the resource string to be used</param>
        /// <param name="messageArgs">Arguments for messageResourceName</param>
        public void LogWarning(BuildEventContext buildEventContext, string subcategoryResourceName, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs)
        {
            lock (_lockObject)
            {
                ErrorUtilities.VerifyThrow(!string.IsNullOrEmpty(messageResourceName), "Need resource string for warning message.");

                string warningCode;
                string helpKeyword;
                string message = ResourceUtilities.FormatResourceString(out warningCode, out helpKeyword, messageResourceName, messageArgs);
                LogWarningFromText(buildEventContext, subcategoryResourceName, warningCode, helpKeyword, file, message);
            }
        }
        /// <summary>
        /// Logs an error regarding an unexpected failure using the specified resource string.
        /// This will include a stack dump.
        /// </summary>
        /// <param name="buildEventContext">BuildEventContext of the error</param>
        /// <param name="exception">Exception which will be used to generate the error message</param>
        /// <param name="file">File information which describes where the error happened</param>
        /// <param name="messageResourceName">String name for the resource string to be used</param>
        /// <param name="messageArgs">Arguments for messageResourceName</param>
        /// <exception cref="InternalErrorException">MessageResourceName is null</exception>
        public void LogFatalError(BuildEventContext buildEventContext, Exception exception, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs)
        {
            lock (_lockObject)
            {
                ErrorUtilities.VerifyThrow(!string.IsNullOrEmpty(messageResourceName), "Need resource string for error message.");

                string errorCode;
                string helpKeyword;
                string message = ResourceUtilities.FormatResourceString(out errorCode, out helpKeyword, messageResourceName, messageArgs);
#if DEBUG
                message += Environment.NewLine + "This is an unhandled exception from a task -- PLEASE OPEN A BUG AGAINST THE TASK OWNER.";
#endif
                if (exception != null)
                {
                    message += Environment.NewLine + exception.ToString();
                }

                LogErrorFromText(buildEventContext, null, errorCode, helpKeyword, file, message);
            }
        }
 /// <summary>
 /// Logs an error regarding an unexpected build failure
 /// This will include a stack dump.
 /// </summary>
 /// <param name="buildEventContext">BuildEventContext of the error</param>
 /// <param name="exception">Exception wihch caused the build error</param>
 /// <param name="file">Provides file information about where the build error happened</param>
 public void LogFatalBuildError(BuildEventContext buildEventContext, Exception exception, BuildEventFileInfo file)
 {
     lock (_lockObject)
     {
         LogFatalError(buildEventContext, exception, file, "FatalBuildError");
     }
 }
        public void LogFatalBuildErrorGoodInput()
        {
            BuildEventFileInfo fileInfo = new BuildEventFileInfo("foo.cs", 1, 2, 3, 4);
            Exception exception = new Exception("SuperException");
            string resourceName = "FatalBuildError";
            string errorCode;
            string helpKeyword;
            string message;
            GenerateMessageFromExceptionAndResource(exception, resourceName, out errorCode, out helpKeyword, out message);

            ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
            service.LogFatalBuildError(s_buildEventContext, exception, fileInfo);
            VerifyBuildErrorEventArgs(fileInfo, errorCode, helpKeyword, message, service, null);
        }
        public void LogFatalErrorNullException()
        {
            BuildEventFileInfo fileInfo = new BuildEventFileInfo("foo.cs", 1, 2, 3, 4);
            string errorCode;
            string helpKeyword;
            string resourceName = "FatalTaskError";
            string parameters = "TaskName";
            string message = null;

            GenerateMessageFromExceptionAndResource(null, resourceName, out errorCode, out helpKeyword, out message, parameters);
            ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
            service.LogFatalError(s_buildEventContext, null, fileInfo, resourceName, parameters);
            VerifyBuildErrorEventArgs(fileInfo, errorCode, helpKeyword, message, service, null);
        }
        public void LogInvalidProjectFileError()
        {
            ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
            InvalidProjectFileException exception = new InvalidProjectFileException("ProjectFile", 1, 2, 3, 4, "Message", "errorSubCategory", "ErrorCode", "HelpKeyword");

            // Log the exception for the first time
            Assert.IsFalse(exception.HasBeenLogged);
            service.LogInvalidProjectFileError(s_buildEventContext, exception);
            Assert.IsTrue(exception.HasBeenLogged);
            BuildEventFileInfo fileInfo = new BuildEventFileInfo(exception.ProjectFile, exception.LineNumber, exception.ColumnNumber, exception.EndLineNumber, exception.EndColumnNumber);
            VerifyBuildErrorEventArgs(fileInfo, exception.ErrorCode, exception.HelpKeyword, exception.BaseMessage, service, exception.ErrorSubcategory);

            // Verify when the exception is logged again that it does not actually get logged due to it already being logged
            service.ResetProcessedBuildEvent();
            service.LogInvalidProjectFileError(s_buildEventContext, exception);
            Assert.IsNull(service.ProcessedBuildEvent);

            // Reset the HasLogged field and verify OnlyLogCriticalEvents does not effect the logging of the message
            service.ResetProcessedBuildEvent();
            service.OnlyLogCriticalEvents = true;
            exception.HasBeenLogged = false;
            service.LogInvalidProjectFileError(s_buildEventContext, exception);
            VerifyBuildErrorEventArgs(fileInfo, exception.ErrorCode, exception.HelpKeyword, exception.BaseMessage, service, exception.ErrorSubcategory);
        }
 /// <summary>
 /// Create a buildError event to compare to the one which was passed into the ProcessedBuildEvent method.
 /// </summary>
 /// <param name="fileInfo">FileInfo to create the comparison event with</param>
 /// <param name="errorCode">Errorcode to create the comparison event with c</param>
 /// <param name="helpKeyword">helpKeyword to create the comparison event with</param>
 /// <param name="message">message to create the comparison event with</param>
 /// <param name="service">LoggingService mock object which overrides ProcessBuildEvent and can provide a ProcessedBuildEvent (the event which would have been sent to the loggers)</param>
 /// <param name="subcategory">Subcategory to create the comparison event with</param>
 private void VerifyBuildErrorEventArgs(BuildEventFileInfo fileInfo, string errorCode, string helpKeyword, string message, ProcessBuildEventHelper service, string subcategory)
 {
     BuildErrorEventArgs buildEvent = new BuildErrorEventArgs
         (
             subcategory,
             errorCode,
             fileInfo.File,
             fileInfo.Line,
             fileInfo.Column,
             fileInfo.EndLine,
             fileInfo.EndColumn,
             message,
             helpKeyword,
             "MSBuild",
             service.ProcessedBuildEvent.Timestamp
         );
     buildEvent.BuildEventContext = s_buildEventContext;
     Assert.IsTrue(buildEvent.IsEquivalent((BuildErrorEventArgs)service.ProcessedBuildEvent));
 }
        public void LogErrorGoodParameters()
        {
            BuildEventFileInfo fileInfo = new BuildEventFileInfo("foo.cs", 1, 2, 3, 4);
            string errorCode;
            string helpKeyword;
            string taskName = "TaskName";
            string subcategoryKey = "SubCategoryForSolutionParsingErrors";
            string message = ResourceUtilities.FormatResourceString(out errorCode, out helpKeyword, "FatalTaskError", taskName);
            string subcategory = AssemblyResources.GetString(subcategoryKey);

            ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);

            service.LogError(s_buildEventContext, subcategoryKey, fileInfo, "FatalTaskError", taskName);
            VerifyBuildErrorEventArgs(fileInfo, errorCode, helpKeyword, message, service, subcategory);
        }
        /// <summary>
        /// Test LogWarning
        /// </summary>
        /// <param name="taskName">TaskName to test</param>
        /// <param name="subCategoryKey">SubCategoryKey to test</param>
        private void TestLogWarning(string taskName, string subCategoryKey)
        {
            string subcategory = AssemblyResources.GetString(subCategoryKey);
            BuildEventFileInfo fileInfo = new BuildEventFileInfo("foo.cs", 1, 2, 3, 4);
            string warningCode;
            string helpKeyword;
            string message = ResourceUtilities.FormatResourceString(out warningCode, out helpKeyword, "FatalTaskError", taskName);
            ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);

            service.LogWarning(s_buildEventContext, subCategoryKey, fileInfo, "FatalTaskError", taskName);
            VerifyBuildWarningEventArgs(fileInfo, warningCode, helpKeyword, message, service, subcategory);
        }
        /// <summary>
        /// Verify LogWarningFromText
        /// </summary>
        /// <param name="warningCode">WarningCode to test</param>
        /// <param name="helpKeyword">HelpKeyword to test</param>
        /// <param name="subcategoryKey">SubCategory which will be used to get the Subcategory</param>
        /// <param name="message">Message to test</param>
        private void TestLogWarningFromText(string warningCode, string helpKeyword, string subcategoryKey, string message)
        {
            BuildEventFileInfo fileInfo = new BuildEventFileInfo("foo.cs", 1, 2, 3, 4);
            string subcategory = null;
            if (subcategoryKey != null)
            {
                subcategory = AssemblyResources.GetString(subcategoryKey);
            }

            ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
            service.LogWarningFromText(s_buildEventContext, subcategoryKey, warningCode, helpKeyword, fileInfo, message);
            VerifyBuildWarningEventArgs(fileInfo, warningCode, helpKeyword, message, service, subcategory);
        }
 /// <summary>
 /// Logs a warning
 /// </summary>
 /// <param name="buildEventContext">The event context</param>
 /// <param name="subcategoryResourceName">The subcategory resource</param>
 /// <param name="file">The file</param>
 /// <param name="messageResourceName">The message resource</param>
 /// <param name="messageArgs">The message args</param>
 public void LogWarning(BuildEventContext buildEventContext, string subcategoryResourceName, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs)
 {
     Console.WriteLine(messageResourceName);
     foreach (object o in messageArgs)
     {
         Console.WriteLine((string)o);
     }
 }
        /**************************************************************************************************************************
         * WARNING: Do not add overloads that allow raising events without specifying a file. In general ALL events should have a
         * file associated with them. We've received a LOT of feedback from dogfooders about the lack of information in our
         * events. If an event TRULY does not have an associated file, then String.Empty can be passed in for the file. However,
         * that burden should lie on the caller -- these wrapper methods should NOT make it easy to skip the filename.
         *************************************************************************************************************************/

        /// <summary>
        /// Logs an error with all registered loggers using the specified resource string.
        /// </summary>
        /// <param name="location">Event context information which describes who is logging the event</param>
        /// <param name="file">File information where the error happened</param>
        /// <param name="messageResourceName">String key to find the correct string resource</param>
        /// <param name="messageArgs">Arguments for the string resource</param>
        public void LogError(BuildEventContext location, BuildEventFileInfo file, string messageResourceName, params object[] messageArgs)
        {
            lock (_lockObject)
            {
                LogError(location, null, file, messageResourceName, messageArgs);
            }
        }
 public void LogFatalTaskErrorNullTaskNameName()
 {
     BuildEventFileInfo fileInfo = new BuildEventFileInfo("foo.cs", 1, 2, 3, 4);
     ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
     service.LogFatalTaskError(s_buildEventContext, new Exception("SuperException"), fileInfo, null);
 }
        /// <summary>
        /// Logs an error regarding an unexpected task failure.
        /// This will include a stack dump.
        /// </summary>
        /// <param name="buildEventContext">BuildEventContext of the error</param>
        /// <param name="exception">Exceptionm which caused the error</param>
        /// <param name="file">File information which indicates which file the error is happening in</param>
        /// <param name="taskName">Task which the error is happening in</param>
        /// <exception cref="InternalErrorException">TaskName is null</exception>
        public void LogFatalTaskError(BuildEventContext buildEventContext, Exception exception, BuildEventFileInfo file, string taskName)
        {
            lock (_lockObject)
            {
                ErrorUtilities.VerifyThrow(taskName != null, "Must specify the name of the task that failed.");

                LogFatalError(buildEventContext, exception, file, "FatalTaskError", taskName);
            }
        }
        public void LogFatalTaskError()
        {
            BuildEventFileInfo fileInfo = new BuildEventFileInfo("foo.cs", 1, 2, 3, 4);
            Exception exception = new Exception("SuperException");
            string errorCode;
            string helpKeyword;
            string resourceName = "FatalTaskError";
            string parameters = "TaskName";
            string message = null;

            GenerateMessageFromExceptionAndResource(exception, resourceName, out errorCode, out helpKeyword, out message, parameters);
            ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
            service.LogFatalTaskError(s_buildEventContext, exception, fileInfo, parameters);
            VerifyBuildErrorEventArgs(fileInfo, errorCode, helpKeyword, message, service, null);

            // Test when the task name is empty
            GenerateMessageFromExceptionAndResource(exception, resourceName, out errorCode, out helpKeyword, out message, String.Empty);
            service.ResetProcessedBuildEvent();
            service.LogFatalTaskError(s_buildEventContext, exception, fileInfo, string.Empty);
            VerifyBuildErrorEventArgs(fileInfo, errorCode, helpKeyword, message, service, null);
        }
        /**************************************************************************************************************************
         * WARNING: Do not add overloads that allow raising events without specifying a file. In general ALL events should have a
         * file associated with them. We've received a LOT of feedback from dogfooders about the lack of information in our
         * events. If an event TRULY does not have an associated file, then String.Empty can be passed in for the file. However,
         * that burden should lie on the caller -- these wrapper methods should NOT make it easy to skip the filename.
         *************************************************************************************************************************/

        /// <summary>
        /// Logs an warning regarding an unexpected task failure
        /// This will include a stack dump.
        /// </summary>
        /// <param name="buildEventContext">Event context information which describes who is logging the event</param>
        /// <param name="exception">The exception to be used to create the warning text</param>
        /// <param name="file">The file information which indicates where the warning happened</param>
        /// <param name="taskName">Name of the task which the warning is being raised from</param>
        public void LogTaskWarningFromException(BuildEventContext buildEventContext, Exception exception, BuildEventFileInfo file, string taskName)
        {
            lock (_lockObject)
            {
                ErrorUtilities.VerifyThrow(!String.IsNullOrEmpty(taskName), "Must specify the name of the task that failed.");

                string warningCode;
                string helpKeyword;
                string message = ResourceUtilities.FormatResourceString(out warningCode, out helpKeyword, "FatalTaskError", taskName);
#if DEBUG
                message += Environment.NewLine + "This is an unhandled exception from a task -- PLEASE OPEN A BUG AGAINST THE TASK OWNER.";
#endif

                if (exception != null)
                {
                    message += Environment.NewLine + exception.ToString();
                }

                LogWarningFromText(buildEventContext, null, warningCode, helpKeyword, file, message);
            }
        }
 public void LogTaskWarningFromExceptionEmptyTaskName()
 {
     BuildEventFileInfo fileInfo = new BuildEventFileInfo("foo.cs", 1, 2, 3, 4);
     ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);
     service.LogTaskWarningFromException(s_buildEventContext, null, fileInfo, null);
 }
        /// <summary>
        /// Logs a warning
        /// </summary>
        /// <param name="buildEventContext">Event context information which describes who is logging the event</param>
        /// <param name="subcategoryResourceName">Subcategory resource Name. Can be null.</param>
        /// <param name="warningCode">The warning code of the message. Can be null.</param>
        /// <param name="helpKeyword">Help keyword for the message. Can be null.</param>
        /// <param name="file">The file information which will describe where the warning happened</param>
        /// <param name="message">Warning message to log</param>
        public void LogWarningFromText(BuildEventContext buildEventContext, string subcategoryResourceName, string warningCode, string helpKeyword, BuildEventFileInfo file, string message)
        {
            lock (_lockObject)
            {
                ErrorUtilities.VerifyThrow(file != null, "Must specify the associated file.");
                ErrorUtilities.VerifyThrow(message != null, "Need warning message.");
                ErrorUtilities.VerifyThrow(buildEventContext != null, "Need a BuildEventContext");

                string subcategory = null;

                if (subcategoryResourceName != null)
                {
                    subcategory = AssemblyResources.GetString(subcategoryResourceName);
                }

                BuildWarningEventArgs buildEvent = new BuildWarningEventArgs
                    (
                        subcategory,
                        warningCode,
                        file.File,
                        file.Line,
                        file.Column,
                        file.EndLine,
                        file.EndColumn,
                        message,
                        helpKeyword,
                        "MSBuild"
                    );

                buildEvent.BuildEventContext = buildEventContext;
                if (buildEvent.ProjectFile == null && buildEventContext.ProjectContextId != BuildEventContext.InvalidProjectContextId)
                {
                    string projectFile;
                    _projectFileMap.TryGetValue(buildEventContext.ProjectContextId, out projectFile);
                    ErrorUtilities.VerifyThrow(projectFile != null, "ContextID {0} should have been in the ID-to-project file mapping but wasn't!", buildEventContext.ProjectContextId);
                    buildEvent.ProjectFile = projectFile;
                }

                ProcessLoggingEvent(buildEvent);
            }
        }
        public void LogTaskWarningFromException()
        {
            BuildEventFileInfo fileInfo = new BuildEventFileInfo("foo.cs", 1, 2, 3, 4);
            string resourceName = "FatalTaskError";
            string parameters = "TaskName";
            string warningCode;
            string helpKeyword;
            string message;
            ProcessBuildEventHelper service = (ProcessBuildEventHelper)ProcessBuildEventHelper.CreateLoggingService(LoggerMode.Synchronous, 1);

            // Check with a null exception
            GenerateMessageFromExceptionAndResource(null, resourceName, out warningCode, out helpKeyword, out message, parameters);
            service.LogTaskWarningFromException(s_buildEventContext, null, fileInfo, parameters);
            VerifyBuildWarningEventArgs(fileInfo, warningCode, helpKeyword, message, service, null);

            // Check when the exception is not null
            service.ResetProcessedBuildEvent();
            Exception exception = new Exception("SuperException");
            GenerateMessageFromExceptionAndResource(exception, resourceName, out warningCode, out helpKeyword, out message, parameters);
            service.LogTaskWarningFromException(s_buildEventContext, exception, fileInfo, parameters);
            VerifyBuildWarningEventArgs(fileInfo, warningCode, helpKeyword, message, service, null);
        }
 /// <summary>
 /// Logs a fatal task error
 /// </summary>
 /// <param name="buildEventContext">The event context</param>
 /// <param name="exception">The exception</param>
 /// <param name="file">The file</param>
 /// <param name="taskName">The name of the task</param>
 public void LogFatalTaskError(BuildEventContext buildEventContext, Exception exception, BuildEventFileInfo file, string taskName)
 {
 }
        /// <summary>
        /// Constructor helper to load an XmlDocumentWithLocation from a path.
        /// Assumes path is already normalized.
        /// May throw InvalidProjectFileException.
        /// Never returns null.
        /// Does NOT add to the ProjectRootElementCache. Caller should add after verifying subsequent MSBuild parsing succeeds.
        /// </summary>
        /// <param name="fullPath">The full path to the document to load.</param>
        private XmlDocumentWithLocation LoadDocument(string fullPath)
        {
            ErrorUtilities.VerifyThrowInternalRooted(fullPath);

            XmlDocumentWithLocation document = new XmlDocumentWithLocation();
#if (!STANDALONEBUILD)
            using (new CodeMarkerStartEnd(CodeMarkerEvent.perfMSBuildProjectLoadFromFileBegin, CodeMarkerEvent.perfMSBuildProjectLoadFromFileEnd))
#endif
            {
                try
                {
#if MSBUILDENABLEVSPROFILING 
                    string beginProjectLoad = String.Format(CultureInfo.CurrentCulture, "Load Project {0} From File - Start", fullPath);
                    DataCollection.CommentMarkProfile(8806, beginProjectLoad);
#endif
                    using (XmlTextReader xtr = new XmlTextReader(fullPath))
                    {
                        // Start the reader so it has an idea of what the encoding is.
                        xtr.DtdProcessing = DtdProcessing.Ignore;
                        xtr.Read();
                        _encoding = xtr.Encoding;
                        document.Load(xtr);
                    }

                    document.FullPath = fullPath;
                    _projectFileLocation = ElementLocation.Create(fullPath);
                    _directory = Path.GetDirectoryName(fullPath);

                    if (XmlDocument != null)
                    {
                        XmlDocument.FullPath = fullPath;
                    }

                    _lastWriteTimeWhenRead = FileUtilities.GetFileInfoNoThrow(fullPath).LastWriteTime;
                }
                catch (Exception ex)
                {
                    if (ExceptionHandling.NotExpectedIoOrXmlException(ex))
                    {
                        throw;
                    }

                    XmlException xmlException = ex as XmlException;

                    BuildEventFileInfo fileInfo;

                    if (xmlException != null)
                    {
                        fileInfo = new BuildEventFileInfo(xmlException);
                    }
                    else
                    {
                        fileInfo = new BuildEventFileInfo(fullPath);
                    }

                    ProjectFileErrorUtilities.ThrowInvalidProjectFile(fileInfo, ex, "InvalidProjectFile", ex.Message);
                }
#if MSBUILDENABLEVSPROFILING 
                finally
                {
                    string endProjectLoad = String.Format(CultureInfo.CurrentCulture, "Load Project {0} From File - End", fullPath);
                    DataCollection.CommentMarkProfile(8807, endProjectLoad);
                }
#endif
            }

            return document;
        }
 /// <summary>
 /// Logs a task warning
 /// </summary>
 /// <param name="buildEventContext">The build context</param>
 /// <param name="exception">The exception</param>
 /// <param name="file">The file</param>
 /// <param name="taskName">The name of the task</param>
 public void LogTaskWarningFromException(BuildEventContext buildEventContext, Exception exception, BuildEventFileInfo file, string taskName)
 {
 }
        /// <summary>
        /// Constructor helper to load an XmlDocumentWithLocation from an XmlReader.
        /// May throw InvalidProjectFileException.
        /// Never returns null.
        /// </summary>
        private XmlDocumentWithLocation LoadDocument(XmlReader reader)
        {
            XmlDocumentWithLocation document = new XmlDocumentWithLocation();

            try
            {
                document.Load(reader);
            }
            catch (XmlException ex)
            {
                BuildEventFileInfo fileInfo = new BuildEventFileInfo(ex);

                ProjectFileErrorUtilities.ThrowInvalidProjectFile(fileInfo, "InvalidProjectFile", ex.Message);
            }

            return document;
        }
 /// <summary>
 /// Logs a text warning
 /// </summary>
 /// <param name="buildEventContext">The build context</param>
 /// <param name="subcategoryResourceName">The subcategory resource</param>
 /// <param name="warningCode">The warning code</param>
 /// <param name="helpKeyword">A help keyword</param>
 /// <param name="file">The file</param>
 /// <param name="message">The message</param>
 public void LogWarningFromText(BuildEventContext buildEventContext, string subcategoryResourceName, string warningCode, string helpKeyword, BuildEventFileInfo file, string message)
 {
 }
 /// <summary>
 /// Logs a text error
 /// </summary>
 /// <param name="buildEventContext">The event context</param>
 /// <param name="subcategoryResourceName">The subcategory resource</param>
 /// <param name="errorCode">The error code</param>
 /// <param name="helpKeyword">A help keyword</param>
 /// <param name="file">The file</param>
 /// <param name="message">The message</param>
 public void LogErrorFromText(BuildEventContext buildEventContext, string subcategoryResourceName, string errorCode, string helpKeyword, BuildEventFileInfo file, string message)
 {
     Console.WriteLine(message);
 }