/// <summary> /// Gets the markdown content of the aggregated results and saves it to disk /// </summary> private void GenerateProfilerReport() { try { var profilerFile = FileToLog; Console.WriteLine(ResourceUtilities.FormatResourceString("WritingProfilerReport", profilerFile)); var content = ProfilerResultPrettyPrinter.GetMarkdownContent(GetAggregatedResult()); File.WriteAllText(profilerFile, content); Console.WriteLine(ResourceUtilities.GetResourceString("WritingProfilerReportDone")); } catch (DirectoryNotFoundException ex) { Console.WriteLine(ResourceUtilities.FormatResourceString("ErrorWritingProfilerReport", ex.Message)); } catch (IOException ex) { Console.WriteLine(ResourceUtilities.FormatResourceString("ErrorWritingProfilerReport", ex.Message)); } catch (UnauthorizedAccessException ex) { Console.WriteLine(ResourceUtilities.FormatResourceString("ErrorWritingProfilerReport", ex.Message)); } catch (SecurityException ex) { Console.WriteLine(ResourceUtilities.FormatResourceString("ErrorWritingProfilerReport", ex.Message)); } }
/// <summary> /// Pretty prints the aggregated results and saves it to disk /// </summary> /// <remarks> /// If the extension of the file to log is 'md', markdown content is generated. Otherwise, it falls /// back to a tab separated format /// </remarks> private void GenerateProfilerReport() { try { Console.WriteLine(ResourceUtilities.FormatResourceString("WritingProfilerReport", FileToLog)); // If the extension of the file is 'md', markdown content is produced. For any other case, // a tab separated format is generated var content = System.IO.Path.GetExtension(FileToLog) == ".md" ? ProfilerResultPrettyPrinter.GetMarkdownContent(GetAggregatedResult()) : ProfilerResultPrettyPrinter.GetTsvContent(GetAggregatedResult()); File.WriteAllText(FileToLog, content); Console.WriteLine(ResourceUtilities.GetResourceString("WritingProfilerReportDone")); } catch (DirectoryNotFoundException ex) { Console.WriteLine(ResourceUtilities.FormatResourceString("ErrorWritingProfilerReport", ex.Message)); } catch (IOException ex) { Console.WriteLine(ResourceUtilities.FormatResourceString("ErrorWritingProfilerReport", ex.Message)); } catch (UnauthorizedAccessException ex) { Console.WriteLine(ResourceUtilities.FormatResourceString("ErrorWritingProfilerReport", ex.Message)); } catch (SecurityException ex) { Console.WriteLine(ResourceUtilities.FormatResourceString("ErrorWritingProfilerReport", ex.Message)); } }
public void RoundtripProjectEvaluationFinishedEventArgsWithProfileData() { var projectFile = @"C:\foo\bar.proj"; var args = new ProjectEvaluationFinishedEventArgs( ResourceUtilities.GetResourceString("EvaluationFinished"), projectFile) { BuildEventContext = BuildEventContext.Invalid, ProjectFile = @"C:\foo\bar.proj", ProfilerResult = new ProfilerResult(new Dictionary <EvaluationLocation, ProfiledLocation> { { new EvaluationLocation(1, 0, EvaluationPass.InitialProperties, "desc1", "file1", 7, "element1", "description", EvaluationLocationKind.Condition), new ProfiledLocation(TimeSpan.FromSeconds(1), TimeSpan.FromHours(2), 1) }, { new EvaluationLocation(0, null, EvaluationPass.LazyItems, "desc2", "file1", null, "element2", "description2", EvaluationLocationKind.Glob), new ProfiledLocation(TimeSpan.FromSeconds(1), TimeSpan.FromHours(2), 2) }, { new EvaluationLocation(2, 0, EvaluationPass.Properties, "desc2", "file1", null, "element2", "description2", EvaluationLocationKind.Element), new ProfiledLocation(TimeSpan.FromSeconds(1), TimeSpan.FromHours(2), 2) } }) }; Roundtrip(args, e => e.Message, e => e.ProjectFile, e => ToString(e.ProfilerResult.Value.ProfiledLocations)); }
public void TestDetailedSummary() { string contents = ObjectModelHelpers.CleanupFileContents(@" <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'> <Target Name='test'> <Message Text='[success]'/> </Target> </Project> "); _parameters.DetailedSummary = true; #if FEATURE_XMLTEXTREADER Project project = new Project(new XmlTextReader(new StringReader(contents))); #else Project project = new Project(XmlReader.Create(new StringReader(contents))); #endif BuildRequestData data = new BuildRequestData(project.CreateProjectInstance(), new string[] { "test" }); BuildResult result = _buildManager.Build(_parameters, data); Assert.Equal(BuildResultCode.Success, result.OverallResult); _logger.AssertLogContains("[success]"); // Verify the existence of the first line of the header. StringReader reader = new StringReader(ResourceUtilities.GetResourceString("BuildHierarchyHeader")); _logger.AssertLogContains(reader.ReadLine()); }
private ProjectGraphNode CreateNewNode( ConfigurationMetadata configurationMetadata, ProjectCollection projectCollection, ProjectInstanceFactoryFunc projectInstanceFactory) { // TODO: ProjectInstance just converts the dictionary back to a PropertyDictionary, so find a way to directly provide it. var globalProperties = configurationMetadata.GlobalProperties.ToDictionary(); var projectInstance = projectInstanceFactory( configurationMetadata.ProjectFullPath, globalProperties, projectCollection); if (projectInstance == null) { throw new InvalidOperationException(ResourceUtilities.GetResourceString("NullReferenceFromProjectInstanceFactory")); } var graphNode = new ProjectGraphNode( projectInstance, globalProperties); _allParsedProjects[configurationMetadata] = graphNode; return(graphNode); }
private static void MergeIntoPropertyDictionary( PropertyDictionary <ProjectPropertyInstance> properties, string propertyNameAndValuesString, string syntaxName) { if (!string.IsNullOrEmpty(propertyNameAndValuesString)) { if (PropertyParser.GetTableWithEscaping( null, null, null, propertyNameAndValuesString.Split(PropertySeparator, StringSplitOptions.RemoveEmptyEntries), out Dictionary <string, string> propertiesTable)) { foreach (KeyValuePair <string, string> pair in propertiesTable) { properties[pair.Key] = ProjectPropertyInstance.Create(pair.Key, pair.Value); } } else { throw new InvalidProjectFileException(string.Format( CultureInfo.InvariantCulture, ResourceUtilities.GetResourceString("General.InvalidPropertyError"), syntaxName, propertyNameAndValuesString)); } } }
public void RoundtripProjectEvaluationFinishedEventArgs() { var projectFile = @"C:\foo\bar.proj"; var args = new ProjectEvaluationFinishedEventArgs( ResourceUtilities.GetResourceString("EvaluationFinished"), projectFile) { BuildEventContext = BuildEventContext.Invalid, ProjectFile = @"C:\foo\bar.proj", GlobalProperties = new Dictionary <string, string>() { { "GlobalKey", "GlobalValue" } }, Properties = new List <DictionaryEntry>() { new DictionaryEntry("Key", "Value") }, Items = new List <DictionaryEntry>() { new DictionaryEntry("Key", new MyTaskItem() { ItemSpec = "TestItemSpec" }) } }; Roundtrip(args, e => e.Message, e => e.ProjectFile, e => TranslationHelpers.GetPropertiesString(e.GlobalProperties), e => TranslationHelpers.GetPropertiesString(e.Properties), e => TranslationHelpers.GetMultiItemsString(e.Items)); }
/// <summary> /// Logs that a project evaluation has finished /// </summary> /// <param name="projectEvaluationEventContext">Event context for the project.</param> /// <param name="projectFile">Project file being built</param> /// <param name="globalProperties">Global properties used for the evaluation.</param> /// <param name="properties">Properties produced by the evaluation.</param> /// <param name="items">Items produced by the evaluation.</param> /// <param name="profilerResult">Profiler results if evaluation profiling was enabled.</param> /// <exception cref="InternalErrorException">BuildEventContext is null</exception> public void LogProjectEvaluationFinished( BuildEventContext projectEvaluationEventContext, string projectFile, IEnumerable globalProperties, IEnumerable properties, IEnumerable items, ProfilerResult?profilerResult) { lock (_lockObject) { ErrorUtilities.VerifyThrow(projectEvaluationEventContext != null, "projectBuildEventContext"); ProjectEvaluationFinishedEventArgs buildEvent = new ProjectEvaluationFinishedEventArgs(ResourceUtilities.GetResourceString("EvaluationFinished"), projectFile) { BuildEventContext = projectEvaluationEventContext, ProjectFile = projectFile, ProfilerResult = profilerResult, GlobalProperties = globalProperties, Properties = properties, Items = items }; ProcessLoggingEvent(buildEvent); } }
public void LogComment(BuildEventContext buildEventContext, MessageImportance importance, string messageResourceName, params object[] messageArgs) { if (!OnlyLogCriticalEvents) { ErrorUtilities.VerifyThrow(!string.IsNullOrEmpty(messageResourceName), "Need resource string for comment message."); LogCommentFromText(buildEventContext, importance, ResourceUtilities.GetResourceString(messageResourceName), messageArgs); } }
public IEnumerable <ReferenceInfo> GetReferences(ProjectInstance requesterInstance) { IEnumerable <ProjectItemInstance> projectReferenceItems; IEnumerable <GlobalPropertiesModifier> globalPropertiesModifiers = null; switch (GetProjectType(requesterInstance)) { case ProjectType.OuterBuild: projectReferenceItems = ConstructInnerBuildReferences(requesterInstance); break; case ProjectType.InnerBuild: globalPropertiesModifiers = ModifierForNonMultitargetingNodes.Add((parts, reference) => parts.AddPropertyToUndefine(GetInnerBuildPropertyName(requesterInstance))); projectReferenceItems = requesterInstance.GetItems(ItemTypeNames.ProjectReference); break; case ProjectType.NonMultitargeting: globalPropertiesModifiers = ModifierForNonMultitargetingNodes; projectReferenceItems = requesterInstance.GetItems(ItemTypeNames.ProjectReference); break; default: throw new ArgumentOutOfRangeException(); } foreach (var projectReferenceItem in projectReferenceItems) { if (!String.IsNullOrEmpty(projectReferenceItem.GetMetadataValue(ToolsVersionMetadataName))) { throw new InvalidOperationException( String.Format( CultureInfo.InvariantCulture, ResourceUtilities.GetResourceString( "ProjectGraphDoesNotSupportProjectReferenceWithToolset"), projectReferenceItem.EvaluatedInclude, requesterInstance.FullPath)); } var projectReferenceFullPath = projectReferenceItem.GetMetadataValue(FullPathMetadataName); var referenceGlobalProperties = GetGlobalPropertiesForItem(projectReferenceItem, requesterInstance.GlobalPropertiesDictionary, globalPropertiesModifiers); var requesterPlatform = ""; var requesterPlatformLookupTable = ""; if (ConversionUtilities.ValidBooleanTrue(requesterInstance.GetPropertyValue("EnableDynamicPlatformResolution"))) { requesterPlatform = requesterInstance.GetPropertyValue("Platform"); requesterPlatformLookupTable = requesterInstance.GetPropertyValue("PlatformLookupTable"); } var referenceConfig = new ConfigurationMetadata(projectReferenceFullPath, referenceGlobalProperties, requesterPlatform, requesterPlatformLookupTable, projectReferenceItem.HasMetadata("SetPlatform")); yield return(new ReferenceInfo(referenceConfig, projectReferenceItem)); } }
private static IRarController GetController(string pipeName, Handshake handshake) { Type rarControllerType = Type.GetType(RarControllerName); Func <string, int?, int?, int, bool, NamedPipeServerStream> streamFactory = NamedPipeUtil.CreateNamedPipeServer; Func <Handshake, NamedPipeServerStream, int, bool> validateCallback = NamedPipeUtil.ValidateHandshake; IRarController controller = Activator.CreateInstance(rarControllerType, pipeName, handshake, streamFactory, validateCallback, null) as IRarController; ErrorUtilities.VerifyThrow(controller != null, ResourceUtilities.GetResourceString("RarControllerReflectionError"), RarControllerName); return(controller); }
public void LogProjectEvaluationStarted(BuildEventContext projectEvaluationEventContext, string projectFile) { ProjectEvaluationStartedEventArgs evaluationEvent = new ProjectEvaluationStartedEventArgs(ResourceUtilities.GetResourceString("EvaluationStarted"), projectFile) { BuildEventContext = projectEvaluationEventContext, ProjectFile = projectFile }; ProcessLoggingEvent(evaluationEvent); }
private static ProjectEvaluationStartedEventArgs CreateProjectEvaluationStarted() { string projectFile = "test.csproj"; var result = new ProjectEvaluationStartedEventArgs( ResourceUtilities.GetResourceString("EvaluationStarted"), projectFile) { ProjectFile = projectFile }; result.BuildEventContext = CreateBuildEventContext(); return(result); }
/// <summary> /// Helper method for retrieving the function description structure for the given function index. /// This method needs to also return the native pointer to be released when we're done with our FUNCDESC. /// It's not really possible to copy everything to a managed struct and then release the ptr immediately /// here, since FUNCDESCs contain other native pointers we may need to access. /// </summary> internal static void GetFuncDescForDescIndex(ITypeInfo typeInfo, int funcIndex, out FUNCDESC funcDesc, out IntPtr funcDescHandle) { typeInfo.GetFuncDesc(funcIndex, out IntPtr pFuncDesc); // GetFuncDesc should never return null, this is just to be safe if (pFuncDesc == IntPtr.Zero) { throw new COMException( ResourceUtilities.GetResourceString("ResolveComReference.CannotRetrieveTypeInformation")); } funcDesc = (FUNCDESC)Marshal.PtrToStructure(pFuncDesc, typeof(FUNCDESC)); funcDescHandle = pFuncDesc; }
/// <summary> /// Helper method for retrieving type attributes for a given type info /// This method needs to also return the native pointer to be released when we're done with our VARDESC. /// It's not really possible to copy everything to a managed struct and then release the ptr immediately /// here, since VARDESCs contain other native pointers we may need to access. /// </summary> internal static void GetVarDescForVarIndex(ITypeInfo typeInfo, int varIndex, out VARDESC varDesc, out IntPtr varDescHandle) { typeInfo.GetVarDesc(varIndex, out IntPtr pVarDesc); // GetVarDesc should never return null, this is just to be safe if (pVarDesc == IntPtr.Zero) { throw new COMException( ResourceUtilities.GetResourceString("ResolveComReference.CannotRetrieveTypeInformation")); } varDesc = (VARDESC)Marshal.PtrToStructure(pVarDesc, typeof(VARDESC)); varDescHandle = pVarDesc; }
public void RoundtripProjectEvaluationStartedEventArgs() { var projectFile = @"C:\foo\bar.proj"; var args = new ProjectEvaluationStartedEventArgs( ResourceUtilities.GetResourceString("EvaluationStarted"), projectFile) { BuildEventContext = BuildEventContext.Invalid, ProjectFile = projectFile, }; Roundtrip(args, e => e.Message, e => e.ProjectFile); }
private ParsedProject ParseProject(ConfigurationMetadata configurationMetadata) { // TODO: ProjectInstance just converts the dictionary back to a PropertyDictionary, so find a way to directly provide it. var globalProperties = configurationMetadata.GlobalProperties.ToDictionary(); ProjectGraphNode graphNode; ProjectInstance projectInstance; var negotiatePlatform = PlatformNegotiationEnabled && !configurationMetadata.IsSetPlatformHardCoded; projectInstance = _projectInstanceFactory( configurationMetadata.ProjectFullPath, negotiatePlatform ? null : globalProperties, // Platform negotiation requires an evaluation with no global properties first _projectCollection); if (ConversionUtilities.ValidBooleanTrue(projectInstance.GetPropertyValue(EnableDynamicPlatformResolutionMetadataName))) { PlatformNegotiationEnabled = true; } if (projectInstance == null) { throw new InvalidOperationException(ResourceUtilities.GetResourceString("NullReferenceFromProjectInstanceFactory")); } if (negotiatePlatform) { var selectedPlatform = PlatformNegotiation.GetNearestPlatform(projectInstance.GetPropertyValue(PlatformMetadataName), projectInstance.GetPropertyValue(PlatformsMetadataName), projectInstance.GetPropertyValue(PlatformLookupTableMetadataName), configurationMetadata.PreviousPlatformLookupTable, projectInstance.FullPath, configurationMetadata.PreviousPlatform); if (selectedPlatform.Equals(String.Empty)) { globalProperties.Remove(PlatformMetadataName); } else { globalProperties[PlatformMetadataName] = selectedPlatform; } projectInstance = _projectInstanceFactory( configurationMetadata.ProjectFullPath, globalProperties, _projectCollection); } graphNode = new ProjectGraphNode(projectInstance); var referenceInfos = ParseReferences(graphNode); return(new ParsedProject(configurationMetadata, graphNode, referenceInfos)); }