public async Task SaveProjectWithImportedWildcardsBuildActionChangedBackAgain()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesDotNetProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                string projFile = Util.GetSampleProject("console-project-with-wildcards", "ConsoleProject-import.csproj");
                string originalProjectFileText = File.ReadAllText(projFile);

                var p = await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                Assert.IsInstanceOf <Project> (p);
                var mp = (Project)p;
                mp.UseAdvancedGlobSupport = true;

                var f = mp.Files.FirstOrDefault(pf => pf.FilePath.FileName == "text1-1.txt");
                var originalBuildAction = f.BuildAction;
                f.BuildAction = BuildAction.EmbeddedResource;
                await p.SaveAsync(Util.GetMonitor());

                f.BuildAction = originalBuildAction;
                await p.SaveAsync(Util.GetMonitor());

                Assert.AreEqual(Util.ToSystemEndings(originalProjectFileText), File.ReadAllText(p.FileName));

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
Exemple #2
0
        public async Task FilesImportedAreMarkedAsImported()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                FilePath projFile     = Util.GetSampleProject("msbuild-glob-tests", "glob-import-test2.csproj");
                var      textFilePath = projFile.ParentDirectory.Combine("test.txt");
                File.WriteAllText(textFilePath, "test");
                var p = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                Assert.AreEqual(4, p.Files.Count);

                var c2File   = p.Files.First(fi => fi.FilePath.FileName == "c2.cs");
                var textFile = p.Files.First(fi => fi.FilePath.FileName == "test.txt");

                Assert.IsFalse(textFile.IsImported);
                Assert.IsTrue(c2File.IsImported);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
Exemple #3
0
        public async Task RemoveAllFilesFromProject_NoFilesDeleted_RemoveItemAddedForFiles()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                string projFile = Util.GetSampleProject("msbuild-glob-tests", "glob-import-test.csproj");
                var    p        = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                Assert.AreEqual(3, p.Files.Count);

                p.Files.Clear();

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

                string projectXml = File.ReadAllText(p.FileName);
                Assert.AreEqual(File.ReadAllText(p.FileName.ChangeName("glob-remove-saved3")), projectXml);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
        public async Task CSharpFileBuildActionChangedToNoneBackToCompileBackToNoneAgain()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesDotNetProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                string projFile = Util.GetSampleProject("console-project-with-wildcards", "ConsoleProject-imported-none-wildcard.csproj");

                var p = await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                Assert.IsInstanceOf <Project> (p);
                var mp = (Project)p;
                mp.UseAdvancedGlobSupport = true;

                var f = mp.Files.FirstOrDefault(pf => pf.FilePath.FileName == "Program.cs");
                f.BuildAction = BuildAction.None;
                await p.SaveAsync(Util.GetMonitor());

                f             = mp.Files.FirstOrDefault(pf => pf.FilePath.FileName == "Program.cs");
                f.BuildAction = BuildAction.Compile;
                await p.SaveAsync(Util.GetMonitor());

                f             = mp.Files.FirstOrDefault(pf => pf.FilePath.FileName == "Program.cs");
                f.BuildAction = BuildAction.None;
                await p.SaveAsync(Util.GetMonitor());

                Assert.AreEqual(Util.ReadAllWithWindowsEndings(p.FileName + ".saved1"), Util.ReadAllWithWindowsEndings(p.FileName));

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
        public async Task SaveProjectWithImportedWildcardsBuildActionChangedThenCopyToOutputChanged()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesDotNetProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                string projFile = Util.GetSampleProject("console-project-with-wildcards", "ConsoleProject-import.csproj");

                var p = await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                Assert.IsInstanceOf <Project> (p);
                var mp = (Project)p;
                mp.UseAdvancedGlobSupport = true;

                var f = mp.Files.FirstOrDefault(pf => pf.FilePath.FileName == "text1-1.txt");
                f.BuildAction = BuildAction.EmbeddedResource;
                await p.SaveAsync(Util.GetMonitor());

                f.CopyToOutputDirectory = FileCopyMode.PreserveNewest;
                await p.SaveAsync(Util.GetMonitor());

                Assert.AreEqual(Util.ReadAllWithWindowsEndings(p.FileName + ".saved1"), Util.ReadAllWithWindowsEndings(p.FileName));

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
Exemple #6
0
        public void TagsInItemExtension()
        {
            var p = new TestTagProvider();

            StringParserService.RegisterStringTagProvider(p);

            var node = new CustomItemNode <StringTagTestExtension> ();

            WorkspaceObject.RegisterCustomExtension(node);

            try {
                var project = Services.ProjectService.CreateDotNetProject("C#");

                var modeld = project.GetStringTagModelDescription(ConfigurationSelector.Default);
                Assert.IsTrue(modeld.GetTags().Any(t => t.Name == "foo"));

                var model = project.GetStringTagModel(ConfigurationSelector.Default);
                Assert.AreEqual("bar", model.GetValue("foo"));

                project.Dispose();
            }
            finally {
                StringParserService.UnregisterStringTagProvider(p);
                WorkspaceObject.UnregisterCustomExtension(node);
            }
        }
        public async Task FlavorLoadSaveExtendedPropertiesWithUnknownProperty()
        {
            // Unknown data should be kept in the file

            string projFile    = Util.GetSampleProject("extended-project-properties", "test-unknown-data.myproj");
            string projectXml1 = File.ReadAllText(projFile);

            var tn = new MyEmptyProjectTypeNode();
            var fn = new CustomItemNode <FlavorWithData> ();

            MSBuildProjectService.RegisterCustomItemType(tn);
            WorkspaceObject.RegisterCustomExtension(fn);
            try {
                var p = await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                Assert.IsInstanceOf <MyEmptyProject> (p);
                var mp = (MyEmptyProject)p;

                var f = mp.GetFlavor <FlavorWithData> ();
                Assert.NotNull(f.Data);
                Assert.AreEqual(f.Data.Foo, "bar");
                Assert.AreEqual(f.SimpleData, "Test");

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

                string projectXml2 = File.ReadAllText(projFile);
                Assert.AreEqual(projectXml1, projectXml2);

                p.Dispose();
            } finally {
                MSBuildProjectService.UnregisterCustomItemType(tn);
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
        public async Task DependentUponUsingFileNameMetadataProperty()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                FilePath projFile           = Util.GetSampleProject("msbuild-glob-tests", "glob-import-metadata-prop.csproj");
                string   expectedProjectXml = File.ReadAllText(projFile);

                var xamlCSharpFileName = projFile.ParentDirectory.Combine("test.xaml.cs");
                File.WriteAllText(xamlCSharpFileName, "csharp");
                var xamlFileName = projFile.ParentDirectory.Combine("test.xaml");
                File.WriteAllText(xamlFileName, "xaml");
                var p = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                var xamlCSharpFile = p.Files.Single(fi => fi.FilePath.FileName == "test.xaml.cs");
                var xamlFile       = p.Files.Single(fi => fi.FilePath.FileName == "test.xaml");

                Assert.AreEqual(xamlFileName.ToString(), xamlCSharpFile.DependsOn);
                Assert.AreEqual(xamlCSharpFile.DependsOnFile, xamlFile);

                // Ensure the expanded %(FileName) does not get added to the main project on saving.
                await p.SaveAsync(Util.GetMonitor());

                string projectXml = File.ReadAllText(p.FileName);
                Assert.AreEqual(expectedProjectXml, projectXml);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
Exemple #9
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);
            }
        }
        public async Task FlavorLoadExtendedProperties_InitialEmptyGroup()
        {
            // Check that data load works when it is not defined in the main group
            // Test for BXC 41774.
            string projFile = Util.GetSampleProject("extended-project-properties", "test-data-empty-group.myproj");

            var tn = new MyEmptyProjectTypeNode();
            var fn = new CustomItemNode <FlavorWithData> ();

            MSBuildProjectService.RegisterCustomItemType(tn);
            WorkspaceObject.RegisterCustomExtension(fn);
            try {
                var p = await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                Assert.IsInstanceOf <MyEmptyProject> (p);
                var mp = (MyEmptyProject)p;

                var f = mp.GetFlavor <FlavorWithData> ();
                Assert.NotNull(f.Data);
                Assert.AreEqual(f.Data.Foo, "bar");
                Assert.AreEqual(f.SimpleData, "Test");
                p.Dispose();
            } finally {
                MSBuildProjectService.UnregisterCustomItemType(tn);
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
Exemple #11
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);
            }
        }
Exemple #12
0
        public async Task OnConfigureTargetEvaluationContext()
        {
            var node = new CustomItemNode <EvalContextCreationTestExtension> ();

            WorkspaceObject.RegisterCustomExtension(node);
            EvalContextCreationTestExtension.ControlValue = "First";

            try {
                string   solFile = Util.GetSampleProject("fast-build-test", "FastBuildTest.sln");
                Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

                var app = (DotNetProject)sol.Items [0];

                var cs = new SolutionConfigurationSelector("Debug");

                Assert.IsTrue(app.FastCheckNeedsBuild(cs));

                var res = await sol.Build(Util.GetMonitor(), cs);

                Assert.IsFalse(res.HasErrors);
                Assert.IsFalse(app.FastCheckNeedsBuild(cs));

                EvalContextCreationTestExtension.ControlValue = "Changed";
                Assert.IsTrue(app.FastCheckNeedsBuild(cs));

                res = await sol.Build(Util.GetMonitor(), cs);

                Assert.IsFalse(res.HasErrors);
                Assert.IsFalse(app.FastCheckNeedsBuild(cs));

                sol.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(node);
            }
        }
        public async Task FileUpdateChangeThenRemoveMetadata2()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                string projFile         = Util.GetSampleProject("msbuild-glob-tests", "glob-import-test.csproj");
                string originalProjFile = new FilePath(projFile).ChangeName("glob-import-test-original.csproj");
                File.Copy(projFile, originalProjFile);
                var p = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                Assert.AreEqual(3, p.Files.Count);

                var f = p.Files.First(fi => fi.FilePath.FileName == "c2.cs");
                f.Metadata.SetValue("foo", "bar");

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

                string projectXml = File.ReadAllText(p.FileName);
                Assert.AreEqual(File.ReadAllText(p.FileName.ChangeName("glob-import-update1-test")), projectXml);

                f.Metadata.RemoveProperty("foo");

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

                projectXml = File.ReadAllText(p.FileName);
                Assert.AreEqual(File.ReadAllText(originalProjFile), projectXml);
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
        public async Task RemoveFileLink()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                FilePath projFile = Util.GetSampleProject("msbuild-glob-tests", "glob-file-link-test.csproj");

                string linkedFile = Path.Combine(projFile.ParentDirectory, "..", "test.txt");
                File.WriteAllText(linkedFile, "test");

                var p = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                Assert.AreEqual(4, p.Files.Count);

                var f = p.Files.First(fi => fi.FilePath.FileName == "test.txt");
                Assert.IsTrue(f.IsLink);
                p.Files.Remove(f);

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

                string expectedProjectXml = File.ReadAllText(p.FileName.ChangeName("glob-file-link-test-saved1"));
                string projectXml         = File.ReadAllText(p.FileName);
                Assert.AreEqual(expectedProjectXml, projectXml);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
        public async Task ProjectExtensionOnModifiedCalledWhenProjectModified()
        {
            var fn = new CustomItemNode <TestModifiedProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

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

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

                TestModifiedProjectExtension.ModifiedEventArgs.Clear();

                p.NotifyModified("Files");

                var args      = TestModifiedProjectExtension.ModifiedEventArgs.Single();
                var eventInfo = args.Single();
                Assert.AreEqual("Files", eventInfo.Hint);
                Assert.AreEqual(p, eventInfo.SolutionItem);
                Assert.AreEqual(sol, eventInfo.Solution);
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
        public void Teardown()
        {
            WorkspaceObject.UnregisterCustomExtension(capaNode);

            // Unregister test addin.
            File.Delete(testAddinAssemblyPath);
            AddinManager.Registry.Update(null);
        }
        public void Teardown()
        {
            WorkspaceObject.UnregisterCustomExtension(capaNode);

            // Ensure MonoDevelop.Core.Tests addin is not registered in local-config after tests are run.
            string localConfigFile = Path.Combine(Util.TestsRootDir, "..", "..", "local-config", "MonoDevelop.Core.Tests.Addin.addins");

            File.Delete(localConfigFile);
        }
Exemple #18
0
        public async Task Reevaluate_AfterReferenceRemovedFromProject_BeforeProjectSaved2()
        {
            FilePath oldProjectFile = Util.GetSampleProject("console-project", "ConsoleProject", "ConsoleProject.csproj.reference-added");
            FilePath projectFile    = oldProjectFile.ParentDirectory.Combine("ConsoleProject-reference-added.csproj");

            File.Move(oldProjectFile, projectFile);

            var p = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projectFile);

            var systemXmlLinqRef = p.References.Single(r => r.Include == "System.Xml.Linq");
            var systemNetRef     = p.References.Single(r => r.Include == "System.Net");

            Assert.AreEqual(5, p.References.Count);

            var fn = new CustomItemNode <RemoveReferenceOnReevaluateProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                int  itemAdded           = 0;
                int  itemRemoved         = 0;
                int  configAdded         = 0;
                int  configRemoved       = 0;
                bool configsChanged      = false;
                bool runConfigsChanged   = false;
                bool capabilitiesChanged = false;
                p.ProjectItemAdded           += (sender, e) => itemAdded += e.Count;
                p.ProjectItemRemoved         += (sender, e) => itemRemoved += e.Count;
                p.ConfigurationAdded         += (sender, e) => configAdded++;
                p.ConfigurationRemoved       += (sender, e) => configRemoved++;
                p.ConfigurationsChanged      += (sender, e) => configsChanged = true;
                p.RunConfigurationsChanged   += (sender, e) => runConfigsChanged = true;
                p.ProjectCapabilitiesChanged += (sender, e) => capabilitiesChanged = true;

                await p.ReevaluateProject(Util.GetMonitor());

                Assert.IsFalse(p.References.Any(r => r.Include == "System.Xml.Linq"));
                Assert.IsFalse(p.References.Any(r => r.Include == "System.Net"));
                Assert.AreEqual(3, p.References.Count);

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

                Assert.AreEqual(Util.ToSystemEndings(File.ReadAllText(p.FileName)), File.ReadAllText(p.FileName.ParentDirectory.Combine("ConsoleProject.csproj")));

                Assert.AreEqual(0, itemAdded);
                Assert.AreEqual(2, itemRemoved);
                Assert.AreEqual(0, configAdded);
                Assert.AreEqual(0, configRemoved);
                Assert.IsFalse(configsChanged);
                Assert.IsFalse(runConfigsChanged);
                Assert.IsFalse(capabilitiesChanged);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
Exemple #19
0
        public async Task Reevaluate_AfterReferenceAddedToProject_BeforeProjectSaved2()
        {
            string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");

            Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

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

            Assert.AreEqual(3, p.References.Count);

            var fn = new CustomItemNode <AddReferenceOnReevaluateProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                int  itemAdded           = 0;
                int  itemRemoved         = 0;
                int  configAdded         = 0;
                int  configRemoved       = 0;
                bool configsChanged      = false;
                bool runConfigsChanged   = false;
                bool capabilitiesChanged = false;
                p.ProjectItemAdded           += (sender, e) => itemAdded += e.Count;
                p.ProjectItemRemoved         += (sender, e) => itemRemoved += e.Count;
                p.ConfigurationAdded         += (sender, e) => configAdded++;
                p.ConfigurationRemoved       += (sender, e) => configRemoved++;
                p.ConfigurationsChanged      += (sender, e) => configsChanged = true;
                p.RunConfigurationsChanged   += (sender, e) => runConfigsChanged = true;
                p.ProjectCapabilitiesChanged += (sender, e) => capabilitiesChanged = true;

                await p.ReevaluateProject(Util.GetMonitor());

                Assert.AreEqual(1, p.References.Count(r => r.Include == "System.Xml.Linq"));
                Assert.AreEqual(1, p.References.Count(r => r.Include == "System.Net"));
                Assert.AreEqual(5, p.References.Count);

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

                Assert.AreEqual(File.ReadAllText(p.FileName), Util.ToSystemEndings(File.ReadAllText(p.FileName + ".reference-added")));

                Assert.AreEqual(2, itemAdded);
                Assert.AreEqual(0, itemRemoved);
                Assert.AreEqual(0, configAdded);
                Assert.AreEqual(0, configRemoved);
                Assert.IsFalse(configsChanged);
                Assert.IsFalse(runConfigsChanged);
                Assert.IsFalse(capabilitiesChanged);

                sol.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
        public async Task Remove_WildCardHasMetadataProperties()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                FilePath projFile           = Util.GetSampleProject("msbuild-glob-tests", "glob-import-metadata-prop.csproj");
                string   expectedProjectXml = File.ReadAllText(projFile);

                var p = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                var xamlFileName1 = projFile.ParentDirectory.Combine("MyView1.xaml");
                File.WriteAllText(xamlFileName1, "xaml1");
                var xamlCSharpFileName = projFile.ParentDirectory.Combine("MyView1.xaml.cs");
                File.WriteAllText(xamlCSharpFileName, "csharpxaml");

                var xamlFile1 = new ProjectFile(xamlFileName1, BuildAction.EmbeddedResource);
                xamlFile1.Generator   = "MSBuild:UpdateDesignTimeXaml";
                xamlFile1.ContentType = "Designer";
                p.Files.Add(xamlFile1);

                var xamlCSharpFile = p.AddFile(xamlCSharpFileName);
                xamlCSharpFile.DependsOn = "MyView1.xaml";

                // Ensure no items are added to the project on saving.
                await p.SaveAsync(Util.GetMonitor());

                string projectXml = File.ReadAllText(p.FileName);
                Assert.AreEqual(expectedProjectXml, projectXml);

                // Remove .xaml.cs file but do not delete it.
                p.Files.Remove(xamlCSharpFile);
                await p.SaveAsync(Util.GetMonitor());

                // Remove item should be added for .xaml.cs file.
                projectXml         = File.ReadAllText(p.FileName);
                expectedProjectXml = File.ReadAllText(p.FileName.ChangeName("glob-import-metadata-prop-saved1"));
                Assert.AreEqual(expectedProjectXml, projectXml);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
        public async Task SolutionStartupItemChangedAfterReevaluation()
        {
            var node = new TestCapabilityNode();

            WorkspaceObject.RegisterCustomExtension(node);

            try {
                string solFile  = Util.GetSampleProject("project-capability-tests", "Library", "Library.sln");
                var    solution = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

                var item = solution.GetAllProjects().Single();

                string projectExtension = "TestCapabilityExtension";
                Func <ProjectExtension, bool> isMatch = f => f.GetType().Name == projectExtension;
                var ext = item.GetFlavors().FirstOrDefault(isMatch);
                Assert.IsNull(ext);

                // Library project is the only project in the solution so the startup item
                // should be null.
                Assert.IsNull(solution.StartupItem);

                // Now activate "TestCapability" capability which enables the project to
                // support execution.
                var import = item.MSBuildProject.AddNewImport("testcapability.targets");
                await item.ReevaluateProject(Util.GetMonitor());

                ext = item.GetFlavors().FirstOrDefault(isMatch);
                Assert.IsNotNull(ext);

                // Startup item is not set for the solution.
                Assert.AreEqual(item, solution.StartupItem);

                item.MSBuildProject.RemoveImport(import);
                await item.ReevaluateProject(Util.GetMonitor());

                ext = item.GetFlavors().FirstOrDefault(isMatch);
                Assert.IsNull(ext);

                // Startup item is now set to null since no project can be executed.
                Assert.IsNull(solution.StartupItem);

                item.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(node);
            }
        }
Exemple #22
0
        public async Task AddFile_WildCardHasMetadataProperties()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                FilePath projFile           = Util.GetSampleProject("msbuild-glob-tests", "glob-import-metadata-prop.csproj");
                string   expectedProjectXml = File.ReadAllText(projFile);

                var p = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                var xamlFileName1 = projFile.ParentDirectory.Combine("MyView1.xaml");
                File.WriteAllText(xamlFileName1, "xaml1");
                var xamlCSharpFileName = projFile.ParentDirectory.Combine("MyView1.xaml.cs");
                File.WriteAllText(xamlCSharpFileName, "csharpxaml");

                // Xaml file with Generator and Subtype set to match that defined in the glob.
                var xamlFile1 = new ProjectFile(xamlFileName1, BuildAction.EmbeddedResource);
                xamlFile1.Generator   = "MSBuild:UpdateDesignTimeXaml";
                xamlFile1.ContentType = "Designer";
                p.Files.Add(xamlFile1);

                var xamlCSharpFile = p.AddFile(xamlCSharpFileName);
                xamlCSharpFile.DependsOn = "MyView1.xaml";

                // Ensure no items are added to the project on saving.
                await p.SaveAsync(Util.GetMonitor());

                string projectXml = File.ReadAllText(p.FileName);
                Assert.AreEqual(expectedProjectXml, projectXml);

                // Save again. A second save was adding an include for the .xaml file whilst
                // the first save was not.
                await p.SaveAsync(Util.GetMonitor());

                projectXml = File.ReadAllText(p.FileName);
                Assert.AreEqual(expectedProjectXml, projectXml);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
Exemple #23
0
        public async Task RemoveAllFilesFromProject_ProjectHasOneFileWithUpdateItem_RemoveItemAddedAndUpdateItemRemoved()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                string projFile = Util.GetSampleProject("msbuild-glob-tests", "glob-remove-test2.csproj");
                var    p        = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                Assert.AreEqual(3, p.Files.Count);

                var f2 = p.Files.First(fi => fi.FilePath.FileName == "c2.cs");
                var f3 = p.Files.First(fi => fi.FilePath.FileName == "c3.cs");
                File.Delete(f2.FilePath);
                File.Delete(f3.FilePath);

                p.Files.Remove(f2);
                p.Files.Remove(f3);

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

                // Single c1.cs Update item in project. No other .cs files found by the file glob.
                // With two or more files the bug does not happen. Also need to reload the project
                // otherwise the bug does not happen.
                p = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                Assert.AreEqual(1, p.Files.Count);

                // Remove c1.cs file but do not delete it.
                p.Files.Clear();

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

                string projectXml = File.ReadAllText(p.FileName);
                Assert.AreEqual(File.ReadAllText(p.FileName.ChangeName("glob-remove-saved2")), projectXml);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
Exemple #24
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);
            }
        }
Exemple #25
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);
            }
        }
Exemple #26
0
        public async Task SerializedWrite()
        {
            var node = new CustomItemNode <SerializedSaveTestExtension> ();

            WorkspaceObject.RegisterCustomExtension(node);

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

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

                var   op1 = p.SaveAsync(Util.GetMonitor());
                var   op2 = p.SaveAsync(Util.GetMonitor());
                await op1;
                await op2;
                Assert.AreEqual(2, SerializedSaveTestExtension.SaveCount);
            } finally {
                WorkspaceObject.UnregisterCustomExtension(node);
            }
        }
Exemple #27
0
        public async Task DeleteAllFilesFromProject_ProjectHasOneFileWithUpdateItem_UpdateItemRemoved()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                FilePath projFile           = Util.GetSampleProject("msbuild-glob-tests", "glob-import-test.csproj");
                string   expectedProjectXml = File.ReadAllText(projFile);

                // Leave only the c1.cs file.
                var c2File = projFile.ParentDirectory.Combine("c2.cs");
                var c3File = projFile.ParentDirectory.Combine("c3.cs");
                File.Delete(c2File);
                File.Delete(c3File);

                var p = (DotNetProject)await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                p.UseAdvancedGlobSupport = true;

                Assert.AreEqual(1, p.Files.Count);

                var c1File = p.Files.First(fi => fi.FilePath.FileName == "c1.cs");
                c1File.CopyToOutputDirectory = FileCopyMode.Always;

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

                File.Delete(c1File.FilePath);
                p.Files.Clear();

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

                string projectXml = File.ReadAllText(p.FileName);
                Assert.AreEqual(expectedProjectXml, projectXml);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
        public async Task DeleteFileAndThenAddNewFileToProjectWithSingleFileAndImportedCSharpFilesWildcard()
        {
            var fn = new CustomItemNode <SupportImportedProjectFilesDotNetProjectExtension> ();

            WorkspaceObject.RegisterCustomExtension(fn);

            try {
                string projFile = Util.GetSampleProject("console-project-imported-wildcard", "ConsoleProject-imported-wildcard.csproj");
                string originalProjectFileText = File.ReadAllText(projFile);

                var p = await Services.ProjectService.ReadSolutionItem(Util.GetMonitor(), projFile);

                Assert.IsInstanceOf <Project> (p);
                var mp = (Project)p;
                mp.UseAdvancedGlobSupport = true;

                var f = mp.Files.Single();
                Assert.AreEqual("Program.cs", f.FilePath.FileName);
                string fileToDelete = f.FilePath;
                File.Delete(fileToDelete);
                mp.Files.Remove(f);
                await mp.SaveAsync(Util.GetMonitor());

                string newFile = Path.Combine(p.BaseDirectory, "Test.cs");
                File.WriteAllText(newFile, "class Test { }");
                mp.AddFile(newFile);
                await mp.SaveAsync(Util.GetMonitor());

                // Second save was triggering a null reference.
                await mp.SaveAsync(Util.GetMonitor());

                var savedProjFileText = File.ReadAllText(projFile);
                Assert.AreEqual(originalProjectFileText, savedProjFileText);

                p.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(fn);
            }
        }
Exemple #29
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);
            }
        }
 public void Teardown()
 {
     WorkspaceObject.UnregisterCustomExtension(capaNode);
 }