Example #1
0
        public async Task RemoveCustomData()
        {
            var en = new CustomSolutionItemNode <TestSolutionExtension> ();

            WorkspaceObject.RegisterCustomExtension(en);
            try {
                FilePath solFile = Util.GetSampleProject("solution-custom-data", "custom-data.sln");
                var      sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

                var ext = sol.GetService <TestSolutionExtension> ();
                ext.Prop1 = "xx";
                ext.Prop2 = "";
                ext.Extra = null;

                var refFile = solFile.ParentDirectory.Combine("no-custom-data.sln");

                await sol.SaveAsync(Util.GetMonitor());

                Assert.AreEqual(File.ReadAllText(refFile), File.ReadAllText(sol.FileName));

                sol.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(en);
            }
        }
Example #2
0
        public async Task WriteCustomData()
        {
            var en = new CustomSolutionItemNode <TestSolutionExtension> ();

            WorkspaceObject.RegisterCustomExtension(en);
            try {
                string solFile = Util.GetSampleProject("solution-custom-data", "custom-data.sln");

                var sol = new Solution();
                var ext = sol.GetService <TestSolutionExtension> ();
                Assert.NotNull(ext);
                ext.Prop1 = "one";
                ext.Prop2 = "two";
                ext.Extra = new ComplexSolutionData {
                    Prop3 = "three",
                    Prop4 = "four"
                };
                var savedFile = solFile + ".saved.sln";
                await sol.SaveAsync(savedFile, Util.GetMonitor());

                Assert.AreEqual(File.ReadAllText(solFile), File.ReadAllText(savedFile));
                sol.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(en);
            }
        }
Example #3
0
        public async Task SolutionDisposed_ActiveProjectTasks_MSBuildEngineManagerNotDisposedUntilProjectTasksCompleted()
        {
            var en = new CustomSolutionItemNode <TestProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(en);
            try {
                string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");
                var    sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

                var p = (DotNetProject)sol.Items [0];
                var msbuildProject = p.MSBuildProject;

                var ext  = p.GetFlavor <TestProjectExtension> ();
                var task = ext.RunTestTask();
                sol.Dispose();

                // Should not throw. Evaluating requires the MSBuildEngineManager to not be disposed.
                msbuildProject.Evaluate();

                try {
                    // Ensure that BindTask cannot be used after Solution has been disposed but
                    // project has not yet been disposed.
                    await p.BindTask(ct => Task.CompletedTask);

                    Assert.Fail("Should not reach here.");
                } catch (TaskCanceledException) {
                    // Expected
                }

                try {
                    // Ensure that BindTask<T> cannot be used after Solution has been disposed but
                    // project has not yet been disposed.
                    await p.BindTask(ct => Task.FromResult(true));

                    Assert.Fail("Should not reach here.");
                } catch (TaskCanceledException) {
                    // Expected
                }

                ext.TaskCompletionSource.TrySetResult(true);

                await task;
            } finally {
                WorkspaceObject.UnregisterCustomExtension(en);
            }
        }
Example #4
0
        public async Task ReadCustomData()
        {
            var en = new CustomSolutionItemNode <TestSolutionExtension> ();

            WorkspaceObject.RegisterCustomExtension(en);
            try {
                string solFile = Util.GetSampleProject("solution-custom-data", "custom-data.sln");
                var    sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

                var ext = sol.GetService <TestSolutionExtension> ();
                Assert.NotNull(ext);
                Assert.AreEqual("one", ext.Prop1);
                Assert.AreEqual("two", ext.Prop2);
                Assert.NotNull(ext.Extra);
                Assert.AreEqual("three", ext.Extra.Prop3);
                Assert.AreEqual("four", ext.Extra.Prop4);
            } finally {
                WorkspaceObject.UnregisterCustomExtension(en);
            }
        }
Example #5
0
        public async Task KeepUnknownCustomData()
        {
            var en = new CustomSolutionItemNode <TestSolutionExtension> ();

            WorkspaceObject.RegisterCustomExtension(en);
            try {
                FilePath solFile = Util.GetSampleProject("solution-custom-data", "custom-data-keep-unknown.sln");
                var      sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

                var ext = sol.GetService <TestSolutionExtension> ();
                ext.Prop1       = "one-mod";
                ext.Prop2       = "";
                ext.Extra.Prop3 = "three-mod";
                ext.Extra.Prop4 = "";

                var refFile = solFile.ParentDirectory.Combine("custom-data-keep-unknown.sln.saved");

                await sol.SaveAsync(Util.GetMonitor());

                Assert.AreEqual(File.ReadAllText(refFile), File.ReadAllText(sol.FileName));
            } finally {
                WorkspaceObject.UnregisterCustomExtension(en);
            }
        }
Example #6
0
        public async Task BuildSessionBeginEnd()
        {
            var en  = new CustomSolutionItemNode <TestBuildSolutionExtension> ();
            var en2 = new CustomSolutionItemNode <TestBuildSolutionItemExtension> ();

            WorkspaceObject.RegisterCustomExtension(en);
            WorkspaceObject.RegisterCustomExtension(en2);

            int beginCount = 0, endCount = 0, projectBuildCount = 0, msbuildBeginCount = 0, msbuildEndCount = 0;

            TestBuildSolutionExtension.BeginBuildCalled = delegate {
                beginCount++;
            };

            TestBuildSolutionExtension.EndBuildCalled = delegate {
                endCount++;
            };

            TestBuildSolutionItemExtension.BuildCalled = delegate {
                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(0, endCount);
                projectBuildCount++;
            };

            // This logger is used to verify that the BuildStarted event is raised only once per
            // build, which means only one build session is started.

            var customLogger = new MSBuildLogger();

            customLogger.EnabledEvents = MSBuildEvent.BuildStarted | MSBuildEvent.BuildFinished;
            customLogger.EventRaised  += (sender, e) => {
                if (e.Event == MSBuildEvent.BuildStarted)
                {
                    msbuildBeginCount++;
                }
                else if (e.Event == MSBuildEvent.BuildFinished)
                {
                    msbuildEndCount++;
                }
            };

            var oldPrefParallelBuild  = Runtime.Preferences.ParallelBuild.Value;
            var oldPrefSkipUnmodified = Runtime.Preferences.SkipBuildingUnmodifiedProjects.Value;

            try {
                Runtime.Preferences.ParallelBuild.Set(false);
                Runtime.Preferences.SkipBuildingUnmodifiedProjects.Set(false);
                FilePath solFile = Util.GetSampleProject("build-session", "build-session.sln");
                var      sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

                Assert.AreEqual(0, beginCount);
                Assert.AreEqual(0, endCount);
                Assert.AreEqual(0, projectBuildCount);
                Assert.AreEqual(0, msbuildBeginCount);
                Assert.AreEqual(0, msbuildEndCount);

                // Test building the whole solution

                var context = new TargetEvaluationContext();
                context.Loggers.Add(customLogger);
                var res = await sol.Build(Util.GetMonitor(), "Debug", context);

                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(1, endCount);
                Assert.AreEqual(3, projectBuildCount);
                Assert.AreEqual(1, msbuildBeginCount);
                Assert.AreEqual(1, msbuildEndCount);

                // Test building a solution folder

                beginCount = endCount = projectBuildCount = msbuildBeginCount = msbuildEndCount = 0;

                var folder = (SolutionFolder)sol.RootFolder.Items.FirstOrDefault(i => i.Name == "libraries");

                context = new TargetEvaluationContext();
                context.Loggers.Add(customLogger);
                res = await folder.Build(Util.GetMonitor(), sol.Configurations["Debug|x86"].Selector, operationContext : context);

                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(1, endCount);
                Assert.AreEqual(2, projectBuildCount);
                Assert.AreEqual(1, msbuildBeginCount);
                Assert.AreEqual(1, msbuildEndCount);

                // Test building a specific item and dependencies

                beginCount = endCount = projectBuildCount = msbuildBeginCount = msbuildEndCount = 0;

                var item = (SolutionItem)sol.RootFolder.Items.FirstOrDefault(i => i.Name == "build-session");

                context = new TargetEvaluationContext();
                context.Loggers.Add(customLogger);
                res = await item.Build(Util.GetMonitor(), sol.Configurations ["Debug|x86"].Selector, true, context);

                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(1, endCount);
                Assert.AreEqual(3, projectBuildCount);
                Assert.AreEqual(1, msbuildBeginCount);
                Assert.AreEqual(1, msbuildEndCount);

                // Test building a specific item but not its dependencies

                beginCount = endCount = projectBuildCount = msbuildBeginCount = msbuildEndCount = 0;

                context = new TargetEvaluationContext();
                context.Loggers.Add(customLogger);
                res = await item.Build(Util.GetMonitor(), sol.Configurations ["Debug|x86"].Selector, false, context);

                Assert.AreEqual(1, beginCount);
                Assert.AreEqual(1, endCount);
                Assert.AreEqual(1, projectBuildCount);
                Assert.AreEqual(1, msbuildBeginCount);
                Assert.AreEqual(1, msbuildEndCount);

                sol.Dispose();
            } finally {
                TestBuildSolutionExtension.BeginBuildCalled = null;
                TestBuildSolutionExtension.EndBuildCalled   = null;
                TestBuildSolutionItemExtension.BuildCalled  = null;

                WorkspaceObject.UnregisterCustomExtension(en);
                WorkspaceObject.UnregisterCustomExtension(en2);

                Runtime.Preferences.ParallelBuild.Set(oldPrefParallelBuild);
                Runtime.Preferences.SkipBuildingUnmodifiedProjects.Set(oldPrefSkipUnmodified);
            }
        }