Пример #1
0
        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);
        }
        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);
        }
        public void ProblematicPredictorsAreHandled()
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            // We don't bother creating content for the entry point project. The predictor is going to fail anyway.
            string entryPoint = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());

            using (var reporter = new GraphBuilderReporter(Guid.NewGuid().ToString()))
            {
                var arguments = new MSBuildGraphBuilderArguments(
                    TestOutputDirectory,
                    entryPoint,
                    outputFile,
                    globalProperties: null,
                    mSBuildSearchLocations: new[] { TestDeploymentDir },
                    entryPointTargets: new string[0]);

                MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(
                    MsBuildAssemblyLoader.Instance,
                    reporter,
                    arguments,
                    new IProjectStaticPredictor[] { new ThrowOnPredictionPredictor() });
            }

            var result = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            // The result should gracefully fail, with some error message.
            Assert.False(result.Succeeded);
            Assert.True(result.Failure.Message != null);
        }
Пример #4
0
        public void ProblematicPredictorsAreHandled()
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            // We don't bother creating content for the entry point project. The predictor is going to fail anyway.
            string entryPoint = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());

            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,
                    new IProjectPredictor[] { new ThrowOnPredictionPredictor() });
            }

            var result = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            // The result should gracefully fail, with some error message.
            Assert.False(result.Succeeded);
            Assert.True(result.Failure.Message != null);
        }
Пример #5
0
        private ProjectGraphWithPredictionsResult <string> BuildGraphAndDeserialize(MSBuildGraphBuilderArguments arguments)
        {
            MsBuildGraphBuilder.BuildGraphAndSerialize(arguments);

            // The serialized graph should exist
            Assert.True(File.Exists(arguments.OutputPath));

            var projectGraphWithPredictionsResult = SimpleDeserializer.Instance.DeserializeGraph(arguments.OutputPath);

            return(projectGraphWithPredictionsResult);
        }
Пример #6
0
        private ProjectGraphWithPredictionsResult <string> BuildGraphAndDeserialize(IReadOnlyCollection <string> projectEntryPoints)
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());

            MsBuildGraphBuilder.BuildGraphAndSerialize(
                new MSBuildGraphBuilderArguments(
                    TestOutputDirectory,
                    projectEntryPoints,
                    outputFile,
                    globalProperties: null,
                    mSBuildSearchLocations: new[] { TestDeploymentDir },
                    entryPointTargets: new string[0]));

            // The serialized graph should exist
            Assert.True(File.Exists(outputFile));

            var projectGraphWithPredictionsResult = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            return(projectGraphWithPredictionsResult);
        }
Пример #7
0
        private bool BuildAndReport(GraphBuilderReporter reporter, out string failure)
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            var    arguments  = GetStandardBuilderArguments(
                new[] { m_entryPoint },
                outputFile,
                globalProperties: GlobalProperties.Empty,
                entryPointTargets: new string[0],
                requestedQualifiers: new GlobalProperties[] { GlobalProperties.Empty },
                allowProjectsWithoutTargetProtocol: false);

            MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(AssemblyLoader, reporter, arguments);
            var result = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            failure = string.Empty;
            if (!result.Succeeded)
            {
                failure = result.Failure.Message;
            }

            return(result.Succeeded);
        }
Пример #8
0
        private bool BuildAndReport(GraphBuilderReporter reporter, out string failure)
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            var    arguments  = new MSBuildGraphBuilderArguments(
                TestOutputDirectory,
                new[] { m_entryPoint },
                outputFile,
                globalProperties: null,
                mSBuildSearchLocations: new[] { TestDeploymentDir },
                entryPointTargets: new string[0]);

            MsBuildGraphBuilder.BuildGraphAndSerializeForTesting(MsBuildAssemblyLoader.Instance, reporter, arguments);
            var result = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            failure = string.Empty;
            if (!result.Succeeded)
            {
                failure = result.Failure.Message;
            }

            return(result.Succeeded);
        }
        public void StaticPredictionsAreSerialized()
        {
            string outputFile = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());
            string entryPoint = Path.Combine(TemporaryDirectory, Guid.NewGuid().ToString());

            // Here we create a project that we know standard predictors are able to predict: a compile item and an 'OutDir' property, that the CSharp and OutDir predictors should catch
            File.WriteAllText(entryPoint,
                              @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
    <PropertyGroup>
        <OutDir>bin</OutDir>
    </PropertyGroup>
    <ItemGroup>
        <Compile Include=""Program.cs"" />
    </ItemGroup >
</Project>
");

            MsBuildGraphBuilder.BuildGraphAndSerialize(
                new MSBuildGraphBuilderArguments(
                    TestOutputDirectory,
                    new[] { entryPoint },
                    outputFile,
                    globalProperties: GlobalProperties.Empty,
                    mSBuildSearchLocations: new[] { TestDeploymentDir },
                    entryPointTargets: new string[0],
                    requestedQualifiers: new GlobalProperties[] { GlobalProperties.Empty },
                    allowProjectsWithoutTargetProtocol: false));

            var result = SimpleDeserializer.Instance.DeserializeGraph(outputFile);

            Assert.True(result.Succeeded);

            // There is a single project in this graph, which should have non-empty predictions
            ProjectWithPredictions <string> project = result.Result.ProjectNodes.Single();

            Assert.True(project.PredictedInputFiles.Count > 0, "Expected a non-empty collection of predicted input files");
            Assert.True(project.PredictedOutputFolders.Count > 0, "Expected a non-empty collection of predicted output folders");
        }