Beispiel #1
0
        public async Task LoadKnownUnsupportedProjects()
        {
            string solFile = Util.GetSampleProject("unsupported-project", "console-with-libs.sln");

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

            var app  = sol.GetAllItems <SolutionItem> ().FirstOrDefault(it => it.FileName.FileName == "console-with-libs.csproj");
            var lib1 = sol.GetAllItems <SolutionItem> ().FirstOrDefault(it => it.FileName.FileName == "library1.csproj");
            var lib2 = sol.GetAllItems <SolutionItem> ().FirstOrDefault(it => it.FileName.FileName == "library2.csproj");

            Assert.IsInstanceOf <DotNetProject> (app);
            Assert.IsTrue(lib1.IsUnsupportedProject);
            Assert.IsTrue(lib2.IsUnsupportedProject);

            Assert.IsInstanceOf <Project> (lib2);

            var p = (Project)lib2;

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

            p.AddFile(p.BaseDirectory.Combine("Test.cs"), BuildAction.Compile);

            var solText = File.ReadAllLines(solFile);

            await sol.SaveAsync(new ProgressMonitor());

            Assert.AreEqual(Util.GetXmlFileInfoset(p.FileName + ".saved"), Util.GetXmlFileInfoset(p.FileName));
            Assert.AreEqual(solText, File.ReadAllLines(solFile));

            sol.Dispose();
        }
Beispiel #2
0
        public async Task UnloadProject()
        {
            string solFile = Util.GetSampleProject("console-with-libs", "console-with-libs.sln");

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

            SolutionItem p    = sol.FindProjectByName("console-with-libs");
            SolutionItem lib1 = sol.FindProjectByName("library1");
            SolutionItem lib2 = sol.FindProjectByName("library2");

            Assert.IsTrue(p.Enabled);
            Assert.IsTrue(lib1.Enabled);
            Assert.IsTrue(lib2.Enabled);
            Assert.IsTrue(sol.Configurations [0].BuildEnabledForItem(p));

            p.Enabled = false;
            await p.ParentFolder.ReloadItem(Util.GetMonitor(), p);

            p = sol.GetAllItems <SolutionItem> ().FirstOrDefault(it => it.Name == "console-with-libs");
            Assert.IsNotNull(p);
            Assert.IsFalse(p.Enabled);
            Assert.IsTrue(lib1.Enabled);
            Assert.IsTrue(lib2.Enabled);

            p.Enabled = true;
            await p.ParentFolder.ReloadItem(Util.GetMonitor(), p);

            p = sol.FindProjectByName("console-with-libs");
            Assert.IsNotNull(p);
            Assert.IsTrue(sol.Configurations [0].BuildEnabledForItem(p));

            // Reload the solution

            Assert.IsTrue(sol.Configurations [0].BuildEnabledForItem(lib1));
            lib1.Enabled = false;
            await sol.SaveAsync(Util.GetMonitor());

            sol.Dispose();

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

            lib1 = sol.GetAllItems <SolutionItem> ().FirstOrDefault(it => it.Name == "library1");
            Assert.IsNotNull(lib1);
            lib1.Enabled = true;
            await lib1.ParentFolder.ReloadItem(Util.GetMonitor(), lib1);

            lib1 = sol.FindProjectByName("library1");
            Assert.IsNotNull(lib1);
            Assert.IsTrue(sol.Configurations [0].BuildEnabledForItem(lib1));

            sol.Dispose();
        }
Beispiel #3
0
        public async Task SolutionUnboundWhenUnloadingProject()
        {
            var sol = new Solution();

            var item = new SomeItem();

            item.Name = "SomeItem";
            Assert.AreEqual(0, item.BoundEvents);
            Assert.AreEqual(0, item.UnboundEvents);

            sol.RootFolder.AddItem(item);
            Assert.AreEqual(1, item.BoundEvents);
            Assert.AreEqual(0, item.UnboundEvents);
            Assert.AreEqual(1, item.InternalItem.BoundEvents);
            Assert.AreEqual(0, item.InternalItem.UnboundEvents);

            Assert.IsTrue(item.Enabled);

            item.Reset();

            item.Enabled = false;
            await item.ParentFolder.ReloadItem(Util.GetMonitor(), item);

            SolutionItem reloadedItem = sol.GetAllItems <SolutionItem> ().FirstOrDefault(it => it.Name == "SomeItem");

            Assert.IsNotNull(reloadedItem);
            Assert.IsFalse(reloadedItem.Enabled);
            Assert.IsInstanceOf <UnloadedSolutionItem> (reloadedItem);
            Assert.AreEqual(0, item.BoundEvents);
            Assert.AreEqual(1, item.UnboundEvents);
            Assert.AreEqual(0, item.InternalItem.BoundEvents);
            Assert.AreEqual(1, item.InternalItem.UnboundEvents);

            sol.Dispose();
        }
Beispiel #4
0
        public async Task BuildSolutionWithUnsupportedProjects()
        {
            string solFile = Util.GetSampleProject("unsupported-project", "console-with-libs.sln");

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

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

            // The solution has a console app that references an unsupported library. The build of the solution should fail.
            Assert.AreEqual(1, res.ErrorCount);

            var app = sol.GetAllItems <DotNetProject> ().FirstOrDefault(it => it.FileName.FileName == "console-with-libs.csproj");

            // The console app references an unsupported library. The build of the project should fail.
            res = await app.Build(Util.GetMonitor(), ConfigurationSelector.Default, true);

            Assert.IsTrue(res.ErrorCount == 1);

            // A solution build should succeed if it has unbuildable projects but those projects are not referenced by buildable projects
            app.References.Clear();
            await sol.SaveAsync(Util.GetMonitor());

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

            Assert.IsTrue(res.ErrorCount == 0);

            // Regular project not referencing anything else. Should build.
            res = await app.Build(Util.GetMonitor(), ConfigurationSelector.Default, true);

            Assert.IsTrue(res.ErrorCount == 0);

            sol.Dispose();
        }
Beispiel #5
0
        async Task <SolutionItem> LoadProject(CustomProjectLoadProgressMonitor m)
        {
            string   solFile = Util.GetSampleProject("flavor-migration", "ConsoleProject.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(m, solFile);

            return(sol.GetAllItems <SolutionItem>().FirstOrDefault());
        }
        public async Task RemoveRefreshedReferenceSaveProjectAndAddReferenceBackAgain()
        {
            string solFile = Util.GetSampleProject("reference-refresh", "ConsoleProject.sln");

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

            DotNetProject project = sol.GetAllItems <DotNetProject> ().FirstOrDefault();

            File.Move(project.BaseDirectory.Combine("test.dll"), project.BaseDirectory.Combine("test.dll.tmp"));

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

            project = sol.GetAllItems <DotNetProject> ().FirstOrDefault();

            ProjectReference r = project.References.FirstOrDefault(re => re.Reference == "test");

            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsFalse(r.IsValid);

            File.Move(project.BaseDirectory.Combine("test.dll.tmp"), project.BaseDirectory.Combine("test.dll"));

            ProjectReference refreshedReference = r.GetRefreshedReference();

            Assert.IsNotNull(refreshedReference);

            project.References.Remove(r);
            await project.SaveAsync(Util.GetMonitor());

            project.References.Add(refreshedReference);
            await project.SaveAsync(Util.GetMonitor());

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

            project = sol.GetAllItems <DotNetProject> ().FirstOrDefault();

            r = project.References.FirstOrDefault(re => re.Reference == "test");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Assembly);
            Assert.AreEqual(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single(), project.BaseDirectory.Combine("test.dll").FullPath.ToString());
            Assert.IsTrue(r.IsValid);

            sol.Dispose();
        }
Beispiel #7
0
        void ExcludeEntries(IWorkspaceFileObject obj, string[] includedChildIds)
        {
            Solution sol = obj as Solution;

            if (sol != null && includedChildIds != null)
            {
                // Remove items not to be exported.

                Dictionary <string, string> childIds = new Dictionary <string, string> ();
                foreach (string it in includedChildIds)
                {
                    childIds [it] = it;
                }

                foreach (SolutionFolderItem item in sol.GetAllItems <SolutionFolderItem> ())
                {
                    if (!childIds.ContainsKey(item.ItemId) && item.ParentFolder != null)
                    {
                        item.ParentFolder.Items.Remove(item);
                    }
                }
            }
        }
Beispiel #8
0
        public async Task RefreshReferences()
        {
            string solFile = Util.GetSampleProject("reference-refresh", "ConsoleProject.sln");

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

            DotNetProject project = sol.GetAllItems <DotNetProject> ().FirstOrDefault();

            Assert.AreEqual(4, project.References.Count);

            ProjectReference r;

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System.Xml,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference == "test");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Assembly);
            Assert.AreEqual(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single(), project.BaseDirectory.Combine("test.dll").FullPath.ToString());
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference == "gtk-sharp");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Assembly);
            Assert.AreEqual(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single(), project.BaseDirectory.Combine("gtk-sharp.dll").FullPath.ToString());
            Assert.IsTrue(r.IsValid);

            // Refresh without any change

            project.RefreshReferenceStatus();

            Assert.AreEqual(4, project.References.Count);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System.Xml,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference == "test");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Assembly);
            Assert.AreEqual(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single(), project.BaseDirectory.Combine("test.dll").FullPath.ToString());
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference == "gtk-sharp");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Assembly);
            Assert.AreEqual(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single(), project.BaseDirectory.Combine("gtk-sharp.dll").FullPath.ToString());
            Assert.IsTrue(r.IsValid);

            // Refresh after deleting test.dll

            File.Move(project.BaseDirectory.Combine("test.dll"), project.BaseDirectory.Combine("test.dll.tmp"));
            project.RefreshReferenceStatus();

            Assert.AreEqual(4, project.References.Count);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System.Xml,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference == "test");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsFalse(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference == "gtk-sharp");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Assembly);
            Assert.AreEqual(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single(), project.BaseDirectory.Combine("gtk-sharp.dll").FullPath.ToString());
            Assert.IsTrue(r.IsValid);

            // Refresh after deleting gtk-sharp.dll

            File.Move(project.BaseDirectory.Combine("gtk-sharp.dll"), project.BaseDirectory.Combine("gtk-sharp.dll.tmp"));
            project.RefreshReferenceStatus();

            Assert.AreEqual(4, project.References.Count);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System.Xml,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference == "test");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsFalse(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("gtk-sharp,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.AreEqual("gtk-sharp.dll", Path.GetFileName(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single()));
            Assert.IsTrue(r.IsValid);

            // Refresh after restoring gtk-sharp.dll and test.dll

            File.Move(project.BaseDirectory.Combine("test.dll.tmp"), project.BaseDirectory.Combine("test.dll"));
            File.Move(project.BaseDirectory.Combine("gtk-sharp.dll.tmp"), project.BaseDirectory.Combine("gtk-sharp.dll"));
            project.RefreshReferenceStatus();

            Assert.AreEqual(4, project.References.Count);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("System.Xml,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Package);
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference == "test");
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Assembly);
            Assert.AreEqual(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single(), project.BaseDirectory.Combine("test.dll").FullPath.ToString());
            Assert.IsTrue(r.IsValid);

            r = project.References.FirstOrDefault(re => re.Reference.StartsWith("gtk-sharp,"));
            Assert.IsNotNull(r);
            Assert.AreEqual(r.ReferenceType, ReferenceType.Assembly);
            Assert.AreEqual(r.GetReferencedFileNames(project.DefaultConfiguration.Selector).Single(), project.BaseDirectory.Combine("gtk-sharp.dll").FullPath.ToString());
            Assert.IsTrue(r.IsValid);
        }