Example #1
0
        //------------------------------------------------------
        //
        //  Internal Helper Methods
        //
        //------------------------------------------------------

        #region Internal Methods

        // <summary>
        // Output the Logo information to the logger for a given task
        // (Console or registered Loggers).
        // </summary>
        internal static void DisplayLogo(TaskLoggingHelper log, string taskName)
        {
            string acPath = Assembly.GetExecutingAssembly().Location;
            FileVersionInfo acFileVersionInfo = FileVersionInfo.GetVersionInfo(acPath);

            string avalonFileVersion = acFileVersionInfo.FileVersion;

            log.LogMessage(MessageImportance.Low,Environment.NewLine);
            log.LogMessageFromResources(MessageImportance.Low, SRID.TaskLogo, taskName, avalonFileVersion);
            log.LogMessageFromResources(MessageImportance.Low, SRID.TaskRight);
            log.LogMessage(MessageImportance.Low, Environment.NewLine);
        }
 internal static StateFileBase DeserializeCache(string stateFile, TaskLoggingHelper log, Type requiredReturnType)
 {
     StateFileBase o = null;
     try
     {
         if (((stateFile == null) || (stateFile.Length <= 0)) || !File.Exists(stateFile))
         {
             return o;
         }
         using (FileStream stream = new FileStream(stateFile, FileMode.Open))
         {
             object obj2 = new BinaryFormatter().Deserialize(stream);
             o = obj2 as StateFileBase;
             if ((o == null) && (obj2 != null))
             {
                 log.LogMessageFromResources("General.CouldNotReadStateFileMessage", new object[] { stateFile, log.FormatResourceString("General.IncompatibleStateFileType", new object[0]) });
             }
             if ((o != null) && !requiredReturnType.IsInstanceOfType(o))
             {
                 log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", new object[] { stateFile, log.FormatResourceString("General.IncompatibleStateFileType", new object[0]) });
                 o = null;
             }
         }
     }
     catch (Exception exception)
     {
         log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", new object[] { stateFile, exception.Message });
     }
     return o;
 }
        public static bool FindFxCop(out ITaskItem toolPath, TaskLoggingHelper log)
        {
            bool toolFound = false;
            toolPath = new TaskItem();

            string toolName = "Microsoft FxCop";
            string fxCop132Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), toolName + " 1.32");
            string fxCop135Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), toolName + " 1.35");
            string fxCop136Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), toolName + " 1.36");

            if (Directory.Exists(fxCop136Path))
            {
                toolPath.ItemSpec = fxCop136Path;
            }
            else if (Directory.Exists(fxCop135Path))
            {
                toolPath.ItemSpec = fxCop135Path;
            }
            else if (Directory.Exists(fxCop132Path))
            {
                toolPath.ItemSpec = fxCop132Path;
            }
            else
            {
                toolPath.ItemSpec = String.Empty;
            }

            toolFound = (toolPath.ItemSpec.Length != 0);
            if (log != null)
            {
                if (toolFound)
                {
                    log.LogMessageFromResources("ToolFound", toolName, toolPath);
                }
                else
                {
                    log.LogMessageFromResources("ToolNotFound", toolName);
                }
            }

            return toolFound;
        }
        public static bool IsUpToDate(TaskLoggingHelper Log, UpToDateCheckType upToDateCheckType, FlatTrackingData inputs, FlatTrackingData outputs)
        {
            bool            flag          = false;
            ResourceManager taskResources = Log.TaskResources;

            Log.TaskResources = AssemblyResources.PrimaryResources;
            inputs.UpdateFileEntryDetails();
            outputs.UpdateFileEntryDetails();
            if ((!inputs.TlogsAvailable || !outputs.TlogsAvailable) || (inputs.DependencyTable.Count == 0))
            {
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_LogFilesNotAvailable", new object[0]);
            }
            else if ((inputs.MissingFiles.Count > 0) || (outputs.MissingFiles.Count > 0))
            {
                if (inputs.MissingFiles.Count > 0)
                {
                    Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingInputs", new object[0]);
                }
                if (inputs.MissingFiles.Count > 100)
                {
                    FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_InputsNotShown", new object[] { inputs.MissingFiles.Count });
                }
                else
                {
                    foreach (string str in inputs.MissingFiles)
                    {
                        FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + str, new object[0]);
                    }
                }
                if (outputs.MissingFiles.Count > 0)
                {
                    Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingOutputs", new object[0]);
                }
                if (outputs.MissingFiles.Count > 100)
                {
                    FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_OutputsNotShown", new object[] { outputs.MissingFiles.Count });
                }
                else
                {
                    foreach (string str2 in outputs.MissingFiles)
                    {
                        FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + str2, new object[0]);
                    }
                }
            }
            else if ((upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking) && (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
            {
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
            }
            else if ((upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking) && (outputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
            {
                Log.LogMessage(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { outputs.NewestFileName, outputs.NewestFileTimeUtc });
            }
            else if ((upToDateCheckType == UpToDateCheckType.InputNewerThanOutput) && (inputs.NewestFileTimeUtc > outputs.NewestFileTimeUtc))
            {
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
            }
            else if ((upToDateCheckType == UpToDateCheckType.InputNewerThanTracking) && (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
            {
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
            }
            else if ((upToDateCheckType == UpToDateCheckType.InputNewerThanTracking) && (inputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
            {
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
            }
            else
            {
                flag = true;
                Log.LogMessageFromResources(MessageImportance.Normal, "Tracking_UpToDate", new object[0]);
            }
            Log.TaskResources = taskResources;
            return(flag);
        }
		public void TestLogMessageFromResourcesNullMessage2 ()
		{
			tlh = new TaskLoggingHelper (task);
			tlh.LogMessageFromResources (MessageImportance.Low, null);
		}
		public void TestLogMessageFromResourcesNullMessage ()
		{
			tlh = new TaskLoggingHelper (task);
			tlh.LogMessageFromResources (null);
		}
Example #7
0
        /// <summary>
        /// Reads the specified file from disk into a StateFileBase derived object.
        /// </summary>
        /// <param name="stateFile"></param>
        /// <returns></returns>
        static internal StateFileBase DeserializeCache(string stateFile, TaskLoggingHelper log, Type requiredReturnType)
        {
            StateFileBase retVal = null;

            // First, we read the cache from disk if one exists, or if one does not exist
            // then we create one.  
            try
            {
                if (!string.IsNullOrEmpty(stateFile) && File.Exists(stateFile))
                {
                    using (FileStream s = new FileStream(stateFile, FileMode.Open))
                    {
                        BinaryFormatter formatter = new BinaryFormatter();
                        object deserializedObject = formatter.Deserialize(s);
                        retVal = deserializedObject as StateFileBase;

                        // If the deserialized object is null then there would be no cast error but retVal would still be null
                        // only log the message if there would have been a cast error
                        if (retVal == null && deserializedObject != null)
                        {
                            // When upgrading to Visual Studio 2008 and running the build for the first time the resource cache files are replaced which causes a cast error due
                            // to a new version number on the tasks class. "Unable to cast object of type 'Microsoft.Build.Tasks.SystemState' to type 'Microsoft.Build.Tasks.StateFileBase”.
                            // If there is an invalid cast, a message rather than a warning should be emitted.
                            log.LogMessageFromResources("General.CouldNotReadStateFileMessage", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
                        }

                        if ((retVal != null) && (!requiredReturnType.IsInstanceOfType(retVal)))
                        {
                            log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", stateFile,
                                log.FormatResourceString("General.IncompatibleStateFileType"));
                            retVal = null;
                        }

                        // If we get back a valid object and internals were changed, things are likely to be null. Check the version before we use it.
                        if (retVal != null && retVal._serializedVersion != CurrentSerializationVersion)
                        {
                            log.LogMessageFromResources("General.CouldNotReadStateFileMessage", stateFile, log.FormatResourceString("General.IncompatibleStateFileType"));
                            retVal = null;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (ExceptionHandling.IsCriticalException(e))
                {
                    throw;
                }

                // The deserialization process seems like it can throw just about 
                // any exception imaginable.  Catch them all here.
                // Not being able to deserialize the cache is not an error, but we let the user know anyway.
                // Don't want to hold up processing just because we couldn't read the file.
                log.LogWarningWithCodeFromResources("General.CouldNotReadStateFile", stateFile, e.Message);
            }

            return retVal;
        }
Example #8
0
        public static bool IsUpToDate(TaskLoggingHelper Log, UpToDateCheckType upToDateCheckType, FlatTrackingData inputs, FlatTrackingData outputs)
        {
            bool isUpToDate = false;
            // Keep a record of the task resources that was in use before
            ResourceManager taskResources = Log.TaskResources;

            Log.TaskResources = AssemblyResources.PrimaryResources;

            inputs.UpdateFileEntryDetails();
            outputs.UpdateFileEntryDetails();

            if (!inputs.TlogsAvailable || !outputs.TlogsAvailable || inputs.DependencyTable.Count == 0)
            {
                // 1) The TLogs are somehow missing, which means we need to build
                // 2) Because we are flat tracking, there are no roots which means that all the input file information
                //    comes from the input Tlogs, if they are empty then we must build.
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_LogFilesNotAvailable");
            }
            else if (inputs.MissingFiles.Count > 0 || outputs.MissingFiles.Count > 0)
            {
                // Files are missing from either inputs or outputs, that means we need to build

                // Files are missing from inputs, that means we need to build
                if (inputs.MissingFiles.Count > 0)
                {
                    Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingInputs");
                }
                // Too much logging leads to poor performance
                if (inputs.MissingFiles.Count > MaxLogCount)
                {
                    FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_InputsNotShown", inputs.MissingFiles.Count);
                }
                else
                {
                    // We have our set of inputs, log the details
                    foreach (string input in inputs.MissingFiles)
                    {
                        FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + input);
                    }
                }

                // Files are missing from outputs, that means we need to build
                if (outputs.MissingFiles.Count > 0)
                {
                    Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingOutputs");
                }
                // Too much logging leads to poor performance
                if (outputs.MissingFiles.Count > MaxLogCount)
                {
                    FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_OutputsNotShown", outputs.MissingFiles.Count);
                }
                else
                {
                    // We have our set of inputs, log the details
                    foreach (string output in outputs.MissingFiles)
                    {
                        FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + output);
                    }
                }
            }
            else if (upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking &&
                     (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
            {
                // One of the inputs is newer than the input tlog
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", inputs.NewestFileName, inputs.NewestFileTimeUtc, inputs.NewestTLogFileName, inputs.NewestTLogTimeUtc);
            }
            else if (upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking &&
                     (outputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
            {
                // one of the outputs is newer than the output tlog
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", outputs.NewestFileName, outputs.NewestFileTimeUtc, outputs.NewestTLogFileName, outputs.NewestTLogTimeUtc);
            }
            else if (upToDateCheckType == UpToDateCheckType.InputNewerThanOutput &&
                     (inputs.NewestFileTimeUtc > outputs.NewestFileTimeUtc))
            {
                // One of the inputs is newer than the outputs
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", inputs.NewestFileName, inputs.NewestFileTimeUtc, outputs.NewestFileName, outputs.NewestFileTimeUtc);
            }
            else if (upToDateCheckType == UpToDateCheckType.InputNewerThanTracking &&
                     (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
            {
                // One of the inputs is newer than the one of the TLogs
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", inputs.NewestFileName, inputs.NewestFileTimeUtc, inputs.NewestTLogFileName, inputs.NewestTLogTimeUtc);
            }
            else if (upToDateCheckType == UpToDateCheckType.InputNewerThanTracking &&
                     (inputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
            {
                // One of the inputs is newer than the one of the TLogs
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", inputs.NewestFileName, inputs.NewestFileTimeUtc, outputs.NewestTLogFileName, outputs.NewestTLogTimeUtc);
            }
            else
            {
                // Nothing appears to have changed..
                isUpToDate = true;
                Log.LogMessageFromResources(MessageImportance.Normal, "Tracking_UpToDate");
            }

            // Set the task resources back now that we're done with it
            Log.TaskResources = taskResources;

            return(isUpToDate);
        }
Example #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns>True if the operation was successful</returns>
        internal static bool ExecuteTargets
            (
            ITaskItem[] projects,
            Hashtable propertiesTable,
            string[] undefineProperties,
            ArrayList targetLists,
            bool stopOnFirstFailure,
            bool rebaseOutputs,
            IBuildEngine3 buildEngine,
            TaskLoggingHelper log,
            ArrayList targetOutputs,
            bool useResultsCache,
            bool unloadProjectsOnCompletion,
            string toolsVersion
            )
        {
            bool success = true;

            // We don't log a message about the project and targets we're going to
            // build, because it'll all be in the immediately subsequent ProjectStarted event.

            string[] projectDirectory = new string[projects.Length];
            string[] projectNames = new string[projects.Length];
            string[] toolsVersions = new string[projects.Length];
            IList<IDictionary<string, ITaskItem[]>> targetOutputsPerProject = null;
            IDictionary[] projectProperties = new IDictionary[projects.Length];
            List<string>[] undefinePropertiesPerProject = new List<string>[projects.Length];

            for (int i = 0; i < projectNames.Length; i++)
            {
                projectNames[i] = null;
                projectProperties[i] = propertiesTable;

                if (projects[i] != null)
                {
                    // Retrieve projectDirectory only the first time.  It never changes anyway.
                    string projectPath = FileUtilities.AttemptToShortenPath(projects[i].ItemSpec);
                    projectDirectory[i] = Path.GetDirectoryName(projectPath);
                    projectNames[i] = projects[i].ItemSpec;
                    toolsVersions[i] = toolsVersion;


                    // If the user specified a different set of global properties for this project, then
                    // parse the string containing the properties
                    if (!String.IsNullOrEmpty(projects[i].GetMetadata("Properties")))
                    {
                        Hashtable preProjectPropertiesTable;
                        if (!PropertyParser.GetTableWithEscaping
                             (log, ResourceUtilities.FormatResourceString("General.OverridingProperties", projectNames[i]), "Properties", projects[i].GetMetadata("Properties").Split(';'),
                              out preProjectPropertiesTable)
                           )
                        {
                            return false;
                        }
                        projectProperties[i] = preProjectPropertiesTable;
                    }

                    if (undefineProperties != null)
                    {
                        undefinePropertiesPerProject[i] = new List<string>(undefineProperties);
                    }

                    // If the user wanted to undefine specific global properties for this project, parse
                    // that string and remove them now.
                    string projectUndefineProperties = projects[i].GetMetadata("UndefineProperties");
                    if (!String.IsNullOrEmpty(projectUndefineProperties))
                    {
                        string[] propertiesToUndefine = projectUndefineProperties.Split(new char[] { ';' });
                        if (undefinePropertiesPerProject[i] == null)
                        {
                            undefinePropertiesPerProject[i] = new List<string>(propertiesToUndefine.Length);
                        }

                        if (log != null && propertiesToUndefine.Length > 0)
                        {
                            log.LogMessageFromResources(MessageImportance.Low, "General.ProjectUndefineProperties", projectNames[i]);
                            foreach (string property in propertiesToUndefine)
                            {
                                undefinePropertiesPerProject[i].Add(property);
                                log.LogMessageFromText(String.Format(CultureInfo.InvariantCulture, "  {0}", property), MessageImportance.Low);
                            }
                        }
                    }

                    // If the user specified a different set of global properties for this project, then
                    // parse the string containing the properties
                    if (!String.IsNullOrEmpty(projects[i].GetMetadata("AdditionalProperties")))
                    {
                        Hashtable additionalProjectPropertiesTable;
                        if (!PropertyParser.GetTableWithEscaping
                             (log, ResourceUtilities.FormatResourceString("General.AdditionalProperties", projectNames[i]), "AdditionalProperties", projects[i].GetMetadata("AdditionalProperties").Split(';'),
                              out additionalProjectPropertiesTable)
                           )
                        {
                            return false;
                        }
                        Hashtable combinedTable = new Hashtable(StringComparer.OrdinalIgnoreCase);
                        // First copy in the properties from the global table that not in the additional properties table
                        if (projectProperties[i] != null)
                        {
                            foreach (DictionaryEntry entry in projectProperties[i])
                            {
                                if (!additionalProjectPropertiesTable.Contains(entry.Key))
                                {
                                    combinedTable.Add(entry.Key, entry.Value);
                                }
                            }
                        }
                        // Add all the additional properties
                        foreach (DictionaryEntry entry in additionalProjectPropertiesTable)
                        {
                            combinedTable.Add(entry.Key, entry.Value);
                        }
                        projectProperties[i] = combinedTable;
                    }

                    // If the user specified a different toolsVersion for this project - then override the setting
                    if (!String.IsNullOrEmpty(projects[i].GetMetadata("ToolsVersion")))
                    {
                        toolsVersions[i] = projects[i].GetMetadata("ToolsVersion");
                    }
                }
            }

            foreach (string[] targetList in targetLists)
            {
                if (stopOnFirstFailure && !success)
                {
                    // Inform the user that we skipped the remaining targets StopOnFirstFailure=true.
                    log.LogMessageFromResources(MessageImportance.Low, "MSBuild.SkippingRemainingTargets");

                    // We have encountered a failure.  Caller has requested that we not 
                    // continue with remaining targets.
                    break;
                }

                // Send the project off to the build engine.  By passing in null to the 
                // first param, we are indicating that the project to build is the same
                // as the *calling* project file.
                bool currentTargetResult = true;

                BuildEngineResult result =
                    buildEngine.BuildProjectFilesInParallel(projectNames, targetList, projectProperties, undefinePropertiesPerProject, toolsVersions, true /* ask that target outputs are returned in the buildengineresult */);

                currentTargetResult = result.Result;
                targetOutputsPerProject = result.TargetOutputsPerProject;
                success = success && currentTargetResult;

                // If the engine was able to satisfy the build request
                if (currentTargetResult)
                {
                    for (int i = 0; i < projects.Length; i++)
                    {
                        IEnumerable nonNullTargetList = (targetList != null) ? targetList : targetOutputsPerProject[i].Keys;

                        foreach (string targetName in nonNullTargetList)
                        {
                            if (targetOutputsPerProject[i].ContainsKey(targetName))
                            {
                                ITaskItem[] outputItemsFromTarget = (ITaskItem[])targetOutputsPerProject[i][targetName];

                                foreach (ITaskItem outputItemFromTarget in outputItemsFromTarget)
                                {
                                    // No need to rebase if the calling project is the same as the callee project 
                                    // (project == null).  Also no point in trying to copy item metadata either,
                                    // because no items were passed into the Projects parameter!
                                    if (projects[i] != null)
                                    {
                                        // Rebase the output item paths if necessary.  No need to rebase if the calling
                                        // project is the same as the callee project (project == null).
                                        if (rebaseOutputs)
                                        {
                                            try
                                            {
                                                outputItemFromTarget.ItemSpec = Path.Combine(projectDirectory[i], outputItemFromTarget.ItemSpec);
                                            }
                                            catch (ArgumentException e)
                                            {
                                                log.LogWarningWithCodeFromResources(null, projects[i].ItemSpec, 0, 0, 0, 0, "MSBuild.CannotRebaseOutputItemPath", outputItemFromTarget.ItemSpec, e.Message);
                                            }
                                        }

                                        // Copy the custom item metadata from the "Projects" items to these
                                        // output items.
                                        projects[i].CopyMetadataTo(outputItemFromTarget);

                                        // Set a metadata on the output items called "MSBuildProjectFile" which tells you which project file produced this item.
                                        if (String.IsNullOrEmpty(outputItemFromTarget.GetMetadata(ItemMetadataNames.msbuildSourceProjectFile)))
                                        {
                                            outputItemFromTarget.SetMetadata(ItemMetadataNames.msbuildSourceProjectFile, projects[i].GetMetadata(FileUtilities.ItemSpecModifiers.FullPath));
                                        }
                                    }

                                    // Set a metadata on the output items called "MSBuildTargetName" which tells you which target produced this item.
                                    if (String.IsNullOrEmpty(outputItemFromTarget.GetMetadata(ItemMetadataNames.msbuildSourceTargetName)))
                                    {
                                        outputItemFromTarget.SetMetadata(ItemMetadataNames.msbuildSourceTargetName, targetName);
                                    }
                                }

                                targetOutputs.AddRange(outputItemsFromTarget);
                            }
                        }
                    }
                }
            }

            return success;
        }
Example #10
0
        public static bool FindSandcastleHelpFileBuilder(out ITaskItem toolPath, TaskLoggingHelper log)
        {
            bool toolFound = false;
            toolPath = new TaskItem();

            string toolName = "Sandcastle Help File Builder";
            string sandcastlePath = PathHelpers.CombinePaths(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "EWSoftware", toolName);

            if (Directory.Exists(sandcastlePath))
            {
                toolPath.ItemSpec = sandcastlePath;
            }

            toolFound = (toolPath.ItemSpec.Length != 0);
            if (log != null)
            {
                if (toolFound)
                {
                    log.LogMessageFromResources("ToolFound", toolName, toolPath);
                }
                else
                {
                    log.LogMessageFromResources("ToolNotFound", toolName);
                }
            }

            return toolFound;
        }
 internal static string GeneratePathToTool(Microsoft.Build.Shared.FileExists fileExists, string currentArchitecture, string sdkToolsPath, string toolName, TaskLoggingHelper log, bool logErrorsAndWarnings)
 {
     string path = null;
     if (!string.IsNullOrEmpty(sdkToolsPath))
     {
         string str2 = string.Empty;
         try
         {
             string str4 = currentArchitecture;
             if (str4 == null)
             {
                 goto Label_0061;
             }
             if (!(str4 == "AMD64"))
             {
                 if (str4 == "IA64")
                 {
                     goto Label_0053;
                 }
                 if (str4 == "x86")
                 {
                 }
                 goto Label_0061;
             }
             str2 = Path.Combine(sdkToolsPath, "x64");
             goto Label_0063;
         Label_0053:
             str2 = Path.Combine(sdkToolsPath, "ia64");
             goto Label_0063;
         Label_0061:
             str2 = sdkToolsPath;
         Label_0063:
             path = Path.Combine(str2, toolName);
             if (!fileExists(path))
             {
                 if (currentArchitecture != "x86")
                 {
                     path = Path.Combine(sdkToolsPath, toolName);
                 }
             }
             else
             {
                 return path;
             }
         }
         catch (ArgumentException exception)
         {
             log.LogErrorWithCodeFromResources("General.SdkToolsPathError", new object[] { toolName, exception.Message });
             return null;
         }
         if (fileExists(path))
         {
             return path;
         }
         if (logErrorsAndWarnings)
         {
             log.LogWarningWithCodeFromResources("General.PlatformSDKFileNotFoundSdkToolsPath", new object[] { toolName, str2, sdkToolsPath });
         }
     }
     else if (logErrorsAndWarnings)
     {
         log.LogMessageFromResources(MessageImportance.Low, "General.SdkToolsPathNotSpecifiedOrToolDoesNotExist", new object[] { toolName, sdkToolsPath });
     }
     if ((path == null) || !fileExists(path))
     {
         path = FindSDKToolUsingToolsLocationHelper(toolName);
         if ((path == null) && logErrorsAndWarnings)
         {
             log.LogErrorWithCodeFromResources("General.SdkToolsPathToolDoesNotExist", new object[] { toolName, sdkToolsPath, ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.Version40) });
         }
     }
     return path;
 }
Example #12
0
        /// <summary>
        /// This method will take a sdkToolsPath and a toolName and return the path to the tool if it is found and exists.
        /// 
        /// First the method will try and find the tool under the sdkToolsPath taking into account the current processor architecture
        /// If the tool could not be found the method will try and find the tool under the sdkToolsPath (which should point to the x86 sdk directory).
        /// 
        /// Finally if the method has not found the tool yet it will fallback and use the toolslocation helper method to try and find the tool.
        /// </summary>
        /// <returns>Path including the toolName of the tool if found, null if it is not found</returns>
        internal static string GeneratePathToTool(FileExists fileExists, string currentArchitecture, string sdkToolsPath, string toolName, TaskLoggingHelper log, bool logErrorsAndWarnings)
        {
            // Null until we combine the toolname with the path.
            string pathToTool = null;
            if (!String.IsNullOrEmpty(sdkToolsPath))
            {
                string processorSpecificToolDirectory = String.Empty;
                try
                {
                    switch (currentArchitecture)
                    {
                        // There may not be an arm directory so we will fall back to the x86 tool location
                        // but if there is then we should try and use it.
                        case ProcessorArchitecture.ARM:
                            processorSpecificToolDirectory = Path.Combine(sdkToolsPath, "arm");
                            break;
                        case ProcessorArchitecture.AMD64:
                            processorSpecificToolDirectory = Path.Combine(sdkToolsPath, "x64");
                            break;
                        case ProcessorArchitecture.IA64:
                            processorSpecificToolDirectory = Path.Combine(sdkToolsPath, "ia64");
                            break;
                        case ProcessorArchitecture.X86:
                        default:
                            processorSpecificToolDirectory = sdkToolsPath;
                            break;
                    }

                    pathToTool = Path.Combine(processorSpecificToolDirectory, toolName);

                    if (!fileExists(pathToTool))
                    {
                        // Try falling back to the x86 location
                        if (currentArchitecture != ProcessorArchitecture.X86)
                        {
                            pathToTool = Path.Combine(sdkToolsPath, toolName);
                        }
                    }
                    else
                    {
                        return pathToTool;
                    }
                }
                catch (ArgumentException e)
                {
                    // Catch exceptions from path.combine
                    log.LogErrorWithCodeFromResources("General.SdkToolsPathError", toolName, e.Message);
                    return null;
                }

                if (fileExists(pathToTool))
                {
                    return pathToTool;
                }
                else
                {
                    if (logErrorsAndWarnings)
                    {
                        // Log an error indicating we could not find it in the processor specific architecture or x86 locations.
                        // We could not find the tool at all, lot a error.
                        log.LogWarningWithCodeFromResources("General.PlatformSDKFileNotFoundSdkToolsPath", toolName, processorSpecificToolDirectory, sdkToolsPath);
                    }
                }
            }
            else
            {
                if (logErrorsAndWarnings)
                {
                    log.LogMessageFromResources(MessageImportance.Low, "General.SdkToolsPathNotSpecifiedOrToolDoesNotExist", toolName, sdkToolsPath);
                }
            }

            // Fall back and see if we can find it with the toolsLocation helper methods. This is not optimal because 
            // the location they are looking at is based on when the Microsoft.Build.Utilities.dll was compiled
            // but it is better than nothing.
            if (null == pathToTool || !fileExists(pathToTool))
            {
                pathToTool = FindSDKToolUsingToolsLocationHelper(toolName);

                if (pathToTool == null && logErrorsAndWarnings)
                {
                    log.LogErrorWithCodeFromResources("General.SdkToolsPathToolDoesNotExist", toolName, sdkToolsPath, ToolLocationHelper.GetDotNetFrameworkSdkRootRegistryKey(TargetDotNetFrameworkVersion.VersionLatest, VisualStudioVersion.VersionLatest));
                }
            }

            return pathToTool;
        }
Example #13
0
        public static bool FindVisualStudioTool(string toolName, out ITaskItem toolPath, TaskLoggingHelper log)
        {
            bool toolFound = false;
            toolPath = new TaskItem();

            bool vs2003Found;
            ITaskItem vs2003toolPath;
            bool vs2005Found;
            ITaskItem vs2005toolPath;
            bool vs2008Found;
            ITaskItem vs2008toolPath;

            vs2003Found = FindVisualStudio2003(out vs2003toolPath, log);
            vs2005Found = FindVisualStudio2005(out vs2005toolPath, log);
            vs2008Found = FindVisualStudio2008(out vs2008toolPath, log);

            if (vs2003Found)
            {
                if (File.Exists(Path.Combine(vs2003toolPath.ItemSpec, toolName)))
                {
                    toolPath = vs2003toolPath;
                }
            }
            if (vs2005Found)
            {
                if (File.Exists(Path.Combine(vs2005toolPath.ItemSpec, toolName)))
                {
                    toolPath = vs2005toolPath;
                }
            }
            if (vs2008Found)
            {
                if (File.Exists(Path.Combine(vs2008toolPath.ItemSpec, toolName)))
                {
                    toolPath = vs2008toolPath;
                }
            }

            toolFound = (toolPath.ItemSpec.Length != 0);
            if (log != null)
            {
                if (toolFound)
                {
                    log.LogMessageFromResources("ToolFound", toolName, toolPath);
                }
                else
                {
                    log.LogMessageFromResources("ToolNotFound", toolName);
                }
            }

            return toolFound;
        }
Example #14
0
        public static bool FindVisualStudio2008(out ITaskItem toolPath, TaskLoggingHelper log)
        {
            bool toolFound = false;
            toolPath = new TaskItem();
            string toolName = "Microsoft Visual Studio 2008";

            using (Microsoft.Win32.RegistryKey regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\9.0"))
            {
                if (regkey != null)
                {
                    toolPath.ItemSpec = (string)regkey.GetValue("toolPath", "");
                }
            }
            toolFound = (toolPath.ItemSpec.Length != 0);
            if (log != null)
            {
                if (toolFound)
                {
                    log.LogMessageFromResources("ToolFound", toolName, toolPath);
                }
                else
                {
                    log.LogMessageFromResources("ToolNotFound", toolName);
                }
            }

            return toolFound;
        }
Example #15
0
        public static bool IsUpToDate(TaskLoggingHelper Log, UpToDateCheckType upToDateCheckType, FlatTrackingData inputs, FlatTrackingData outputs)
        {
            bool isUpToDate = false;
            // Keep a record of the task resources that was in use before
            ResourceManager taskResources = Log.TaskResources;

            Log.TaskResources = AssemblyResources.PrimaryResources;

            inputs.UpdateFileEntryDetails();
            outputs.UpdateFileEntryDetails();

            if (!inputs.TlogsAvailable || !outputs.TlogsAvailable || inputs.DependencyTable.Count == 0)
            {
                // 1) The TLogs are somehow missing, which means we need to build
                // 2) Because we are flat tracking, there are no roots which means that all the input file information 
                //    comes from the input Tlogs, if they are empty then we must build.
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_LogFilesNotAvailable");
            }
            else if (inputs.MissingFiles.Count > 0 || outputs.MissingFiles.Count > 0)
            {
                // Files are missing from either inputs or outputs, that means we need to build

                // Files are missing from inputs, that means we need to build
                if (inputs.MissingFiles.Count > 0)
                {
                    Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingInputs");
                }
                // Too much logging leads to poor performance
                if (inputs.MissingFiles.Count > MaxLogCount)
                {
                    FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_InputsNotShown", inputs.MissingFiles.Count);
                }
                else
                {
                    // We have our set of inputs, log the details
                    foreach (string input in inputs.MissingFiles)
                    {
                        FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + input);
                    }
                }

                // Files are missing from outputs, that means we need to build
                if (outputs.MissingFiles.Count > 0)
                {
                    Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingOutputs");
                }
                // Too much logging leads to poor performance
                if (outputs.MissingFiles.Count > MaxLogCount)
                {
                    FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_OutputsNotShown", outputs.MissingFiles.Count);
                }
                else
                {
                    // We have our set of inputs, log the details
                    foreach (string output in outputs.MissingFiles)
                    {
                        FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + output);
                    }
                }
            }
            else if (upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking &&
                    (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
            {
                // One of the inputs is newer than the input tlog
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", inputs.NewestFileName, inputs.NewestFileTimeUtc, inputs.NewestTLogFileName, inputs.NewestTLogTimeUtc);
            }
            else if (upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking &&
                    (outputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
            {
                // one of the outputs is newer than the output tlog
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", outputs.NewestFileName, outputs.NewestFileTimeUtc, outputs.NewestTLogFileName, outputs.NewestTLogTimeUtc);
            }
            else if (upToDateCheckType == UpToDateCheckType.InputNewerThanOutput &&
                    (inputs.NewestFileTimeUtc > outputs.NewestFileTimeUtc))
            {
                // One of the inputs is newer than the outputs
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", inputs.NewestFileName, inputs.NewestFileTimeUtc, outputs.NewestFileName, outputs.NewestFileTimeUtc);
            }
            else if (upToDateCheckType == UpToDateCheckType.InputNewerThanTracking &&
                    (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
            {
                // One of the inputs is newer than the one of the TLogs
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", inputs.NewestFileName, inputs.NewestFileTimeUtc, inputs.NewestTLogFileName, inputs.NewestTLogTimeUtc);
            }
            else if (upToDateCheckType == UpToDateCheckType.InputNewerThanTracking &&
                    (inputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
            {
                // One of the inputs is newer than the one of the TLogs
                Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", inputs.NewestFileName, inputs.NewestFileTimeUtc, outputs.NewestTLogFileName, outputs.NewestTLogTimeUtc);
            }
            else
            {
                // Nothing appears to have changed..
                isUpToDate = true;
                Log.LogMessageFromResources(MessageImportance.Normal, "Tracking_UpToDate");
            }

            // Set the task resources back now that we're done with it
            Log.TaskResources = taskResources;

            return isUpToDate;
        }
 public static bool IsUpToDate(TaskLoggingHelper Log, UpToDateCheckType upToDateCheckType, FlatTrackingData inputs, FlatTrackingData outputs)
 {
     bool flag = false;
     ResourceManager taskResources = Log.TaskResources;
     Log.TaskResources = AssemblyResources.PrimaryResources;
     inputs.UpdateFileEntryDetails();
     outputs.UpdateFileEntryDetails();
     if ((!inputs.TlogsAvailable || !outputs.TlogsAvailable) || (inputs.DependencyTable.Count == 0))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_LogFilesNotAvailable", new object[0]);
     }
     else if ((inputs.MissingFiles.Count > 0) || (outputs.MissingFiles.Count > 0))
     {
         if (inputs.MissingFiles.Count > 0)
         {
             Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingInputs", new object[0]);
         }
         if (inputs.MissingFiles.Count > 100)
         {
             FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_InputsNotShown", new object[] { inputs.MissingFiles.Count });
         }
         else
         {
             foreach (string str in inputs.MissingFiles)
             {
                 FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + str, new object[0]);
             }
         }
         if (outputs.MissingFiles.Count > 0)
         {
             Log.LogMessageFromResources(MessageImportance.Low, "Tracking_MissingOutputs", new object[0]);
         }
         if (outputs.MissingFiles.Count > 100)
         {
             FileTracker.LogMessageFromResources(Log, MessageImportance.Low, "Tracking_OutputsNotShown", new object[] { outputs.MissingFiles.Count });
         }
         else
         {
             foreach (string str2 in outputs.MissingFiles)
             {
                 FileTracker.LogMessage(Log, MessageImportance.Low, "\t" + str2, new object[0]);
             }
         }
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking) && (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputOrOutputNewerThanTracking) && (outputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
     {
         Log.LogMessage(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { outputs.NewestFileName, outputs.NewestFileTimeUtc });
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputNewerThanOutput) && (inputs.NewestFileTimeUtc > outputs.NewestFileTimeUtc))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputNewerThanTracking) && (inputs.NewestFileTimeUtc > inputs.NewestTLogTimeUtc))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
     }
     else if ((upToDateCheckType == UpToDateCheckType.InputNewerThanTracking) && (inputs.NewestFileTimeUtc > outputs.NewestTLogTimeUtc))
     {
         Log.LogMessageFromResources(MessageImportance.Low, "Tracking_DependencyWasModifiedAt", new object[] { inputs.NewestFileName, inputs.NewestFileTimeUtc });
     }
     else
     {
         flag = true;
         Log.LogMessageFromResources(MessageImportance.Normal, "Tracking_UpToDate", new object[0]);
     }
     Log.TaskResources = taskResources;
     return flag;
 }
Example #17
0
        public static bool FindNUnit(out ITaskItem toolPath, TaskLoggingHelper log)
        {
            bool toolFound = false;
            toolPath = new TaskItem();

            string toolName = "NUnit 2.2";
            string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), toolName);

            if (Directory.Exists(path))
            {
                toolPath.ItemSpec = path;
            }

            toolFound = (toolPath.ItemSpec.Length != 0);
            if (log != null)
            {
                if (toolFound)
                {
                    log.LogMessageFromResources("ToolFound", toolName, toolPath);
                }
                else
                {
                    log.LogMessageFromResources("ToolNotFound", toolName);
                }
            }

            return toolFound;
        }