private static ProjectGraphWithPredictionsResult BuildGraph( IMsBuildAssemblyLoader assemblyLoader, GraphBuilderReporter reporter, MSBuildGraphBuilderArguments arguments, IReadOnlyCollection <IProjectPredictor> projectPredictorsForTesting) { reporter.ReportMessage("Looking for MSBuild toolset..."); if (!assemblyLoader.TryLoadMsBuildAssemblies(arguments.MSBuildSearchLocations, reporter, out string failure, out IReadOnlyDictionary <string, string> locatedAssemblyPaths, out string locatedMsBuildPath)) { return(ProjectGraphWithPredictionsResult.CreateFailure( GraphConstructionError.CreateFailureWithoutLocation(failure), locatedAssemblyPaths, locatedMsBuildPath)); } reporter.ReportMessage("Done looking for MSBuild toolset."); return(BuildGraphInternal( reporter, locatedAssemblyPaths, locatedMsBuildPath, arguments, projectPredictorsForTesting)); }
private ProjectGraphWithPredictionsResult <string> BuildGraphAndDeserialize(IMsBuildAssemblyLoader assemblyLoader, string projectEntryPointContent = null) { string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString()); string entryPoint = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString()); if (projectEntryPointContent != null) { File.WriteAllText(entryPoint, projectEntryPointContent); } using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString())) { var arguments = new MSBuildGraphBuilderArguments( TemporaryDirectory, entryPoint, outputFile, globalProperties: null, mSBuildSearchLocations: new string[] { TestDeploymentDir }, entryPointTargets: new string[0]); MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(assemblyLoader, reporter, arguments); } // The serialized graph should exist Assert.True(File.Exists(outputFile)); var projectGraphWithPredictionsResult = SimpleDeserializer.Instance.DeserializeGraph(outputFile); return(projectGraphWithPredictionsResult); }
private ProjectGraphWithPredictionsResult <string> BuildGraphAndDeserialize(IMsBuildAssemblyLoader assemblyLoader, string projectEntryPointContent = null) { string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString()); string entryPoint = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString()); if (projectEntryPointContent != null) { File.WriteAllText(entryPoint, projectEntryPointContent); } using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString())) { var arguments = GetStandardBuilderArguments( new[] { entryPoint }, outputFile, globalProperties: GlobalProperties.Empty, entryPointTargets: new string[0], requestedQualifiers: new GlobalProperties[] { GlobalProperties.Empty }, allowProjectsWithoutTargetProtocol: false); MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(assemblyLoader, reporter, arguments); } // The serialized graph should exist Assert.True(File.Exists(outputFile)); var projectGraphWithPredictionsResult = SimpleDeserializer.Instance.DeserializeGraph(outputFile); return(projectGraphWithPredictionsResult); }
/// <summary> /// For tests only. Similar to <see cref="BuildGraphAndSerialize(MSBuildGraphBuilderArguments)"/>, but the assembly loader and reporter can be passed explicitly /// </summary> internal static void BuildGraphAndSerializeForTesting( IMsBuildAssemblyLoader assemblyLoader, GraphBuilderReporter reporter, MSBuildGraphBuilderArguments arguments, IReadOnlyCollection <IProjectPredictor> projectPredictorsForTesting = null) { DoBuildGraphAndSerialize( assemblyLoader, reporter, arguments, projectPredictorsForTesting); }
private static void DoBuildGraphAndSerialize( IMsBuildAssemblyLoader assemblyLoader, GraphBuilderReporter reporter, MSBuildGraphBuilderArguments arguments, IReadOnlyCollection <IProjectPredictor> projectPredictorsForTesting = null) { reporter.ReportMessage("Starting MSBuild graph construction process..."); var stopwatch = Stopwatch.StartNew(); ProjectGraphWithPredictionsResult graphResult = BuildGraph(assemblyLoader, reporter, arguments, projectPredictorsForTesting); SerializeGraph(graphResult, arguments.OutputPath, reporter); reporter.ReportMessage($"Done constructing build graph in {stopwatch.ElapsedMilliseconds}ms."); }