public static async Task TestLoadSaveResources(MSBuildFileFormat fileFormat)
        {
            string   solFile = Util.GetSampleProject("resources-tester", "ResourcesTester.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            sol.ConvertToFormat(fileFormat);
            ProjectTests.CheckResourcesSolution(sol);

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

            solFile = sol.FileName;

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

            ProjectTests.CheckResourcesSolution(sol);

            DotNetProject p  = (DotNetProject)sol.Items [0];
            string        f  = Path.Combine(p.BaseDirectory, "Bitmap1.bmp");
            ProjectFile   pf = p.Files.GetFile(f);

            pf.ResourceId = "SomeBitmap.bmp";
            await sol.SaveAsync(Util.GetMonitor());

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

            p  = (DotNetProject)sol.Items [0];
            f  = Path.Combine(p.BaseDirectory, "Bitmap1.bmp");
            pf = p.Files.GetFile(f);
            Assert.AreEqual("SomeBitmap.bmp", pf.ResourceId);
        }
Exemple #2
0
        public async Task Reloading()
        {
            Solution sol = TestProjectsChecks.CreateConsoleSolution("reloading");
            await sol.SaveAsync(Util.GetMonitor());

            Assert.IsFalse(sol.NeedsReload);

            Project p = sol.Items [0] as Project;

            Assert.IsFalse(p.NeedsReload);

            // Changing format must reset the reload flag (it's like we just created a new solution in memory)
            sol.ConvertToFormat(MSBuildFileFormat.VS2010);
            Assert.IsFalse(sol.NeedsReload);
            Assert.IsFalse(p.NeedsReload);
            sol.ConvertToFormat(MSBuildFileFormat.VS2012);
            Assert.IsFalse(sol.NeedsReload);
            Assert.IsFalse(p.NeedsReload);

            sol.RootFolder.Items.Remove(p);
            Assert.IsFalse(p.NeedsReload);
            p.FileFormat = MSBuildFileFormat.VS2012;
            Assert.IsFalse(p.NeedsReload);
            sol.RootFolder.Items.Add(p);
            Assert.IsFalse(p.NeedsReload);
            sol.RootFolder.Items.Remove(p);
            Assert.IsFalse(p.NeedsReload);
            p.FileFormat = MSBuildFileFormat.VS2005;
            Assert.IsFalse(p.NeedsReload);
            sol.RootFolder.Items.Add(p);
            Assert.IsFalse(p.NeedsReload);

            string   solFile2 = Util.GetSampleProject("csharp-console", "csharp-console.sln");
            Solution sol2     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile2);

            Project p2 = sol2.Items [0] as Project;

            Assert.IsFalse(sol2.NeedsReload);
            Assert.IsFalse(p2.NeedsReload);

            // Check reloading flag in another solution

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

            Assert.IsFalse(sol3.NeedsReload);

            Project p3 = sol3.Items [0] as Project;

            Assert.IsFalse(p3.NeedsReload);

            System.Threading.Thread.Sleep(1000);
            sol.Description = "Foo";             // Small change to force the solution file save
            await sol.SaveAsync(Util.GetMonitor());

            Assert.IsTrue(sol3.NeedsReload);

            sol.Dispose();
        }
Exemple #3
0
        public async Task CSharpFormattingPolicyIndentSwitchCaseSectionChangedMultipleTimes()
        {
            string dir  = Util.CreateTmpDir("IndentSwitchCaseSectionChangedMultipleTimes");
            var    pset = PolicyService.GetPolicySet("Mono");
            var    monoFormattingPolicy = pset.Get <CSharpFormattingPolicy> ("text/x-csharp");
            var    formattingPolicy     = monoFormattingPolicy.Clone();
            var    solution             = new Solution();

            solution.Policies.Set(formattingPolicy);

            bool   expectedSetting = !formattingPolicy.IndentSwitchCaseSection;
            string fileName        = Path.Combine(dir, "IndentSwitchCaseSectionChangedMultipleTimes.sln");

            for (int i = 0; i < 3; ++i)
            {
                formattingPolicy.IndentSwitchCaseSection = expectedSetting;

                await solution.SaveAsync(fileName, Util.GetMonitor());

                var savedSolution = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), fileName);

                var savedFormattingPolicy = savedSolution.Policies.Get <CSharpFormattingPolicy> ();
                Assert.AreEqual(expectedSetting, savedFormattingPolicy.IndentSwitchCaseSection);

                expectedSetting = !expectedSetting;
            }

            solution.Dispose();
        }
Exemple #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();
        }
Exemple #5
0
        public async Task SaveSolutionAfterChangingCSharpFormattingPolicyForTheFirstTime()
        {
            string dir = Util.CreateTmpDir("FormattingPolicyChangedOnce");
            var    formattingPolicy = new CSharpFormattingPolicy();
            var    solution         = new Solution();

            solution.Policies.Set(formattingPolicy);

            bool expectedSetting = !formattingPolicy.IndentSwitchCaseSection;

            formattingPolicy.IndentSwitchCaseSection = expectedSetting;
            string fileName = Path.Combine(dir, "FormattingPolicyChangedOnce.sln");

            await solution.SaveAsync(fileName, Util.GetMonitor());

            var file = new SlnFile();

            file.Read(fileName);
            var s           = file.Sections.GetSection("MonoDevelopProperties", SlnSectionType.PreProcess);
            var missingItem = default(KeyValuePair <string, string>);

            Assert.AreEqual(expectedSetting.ToString(), s.Properties.SingleOrDefault(p => p.Key.Contains("IndentSwitchCaseSection")).Value);
            Assert.AreEqual(missingItem, s.Properties.SingleOrDefault(p => p.Key.Contains("IndentSwitchSection")));
            Assert.AreEqual(missingItem, s.Properties.SingleOrDefault(p => p.Key.Contains("IndentBlock")));
            Assert.AreEqual(missingItem, s.Properties.SingleOrDefault(p => p.Key.Contains("SpaceBeforeDot")));
            Assert.AreEqual(missingItem, s.Properties.SingleOrDefault(p => p.Key.Contains("NewLineForElse")));

            solution.Dispose();
        }
Exemple #6
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 SaveRunConfigurationsToUserProject()
        {
            string   solFile = Util.GetSampleProject("run-configurations", "ConsoleProject.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

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

            var es = new ProjectRunConfiguration("Test1");

            es.StoreInUserFile = false;
            es.Properties.SetValue("SomeValue", "Foo");
            p.RunConfigurations.Add(es);

            es = new ProjectRunConfiguration("Test2");
            es.Properties.SetValue("SomeValue", "Bar");
            p.RunConfigurations.Add(es);

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

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

            string projectXml    = File.ReadAllText(p.FileName);
            string newProjectXml = File.ReadAllText(p.FileName.ChangeName("ConsoleProject.configs-user-added"));

            Assert.AreEqual(newProjectXml, projectXml);

            Assert.IsTrue(File.Exists(p.FileName + ".user"));

            projectXml    = File.ReadAllText(p.FileName + ".user");
            newProjectXml = File.ReadAllText(p.FileName.ChangeName("ConsoleProject.configs-user-added") + ".user");
            Assert.AreEqual(newProjectXml, projectXml);

            sol.Dispose();
        }
        public static async Task CheckGenericItemProject(MSBuildFileFormat format)
        {
            Solution sol = new Solution();

            sol.ConvertToFormat(format);
            string dir = Util.CreateTmpDir("generic-item-" + format.Name);

            sol.FileName = Path.Combine(dir, "TestGenericItem");
            sol.Name     = "TheItem";

            MonoDevelop.Projects.MSBuild.MSBuildProjectService.RegisterGenericProjectType("GenericItem", typeof(GenericItem));

            GenericItem it = new GenericItem();

            it.SomeValue = "hi";

            sol.RootFolder.Items.Add(it);
            it.FileName = Path.Combine(dir, "TheItem");
            it.Name     = "TheItem";

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

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

            Assert.AreEqual(1, sol2.Items.Count);
            Assert.IsInstanceOf <GenericItem> (sol2.Items [0]);

            it = (GenericItem)sol2.Items [0];
            Assert.AreEqual("hi", it.SomeValue);
        }
Exemple #9
0
        public async Task ReloadingKeepsBuildConfigurationAndStartupProject()
        {
            string solFile = Util.GetSampleProject("console-with-libs", "console-with-libs.sln");

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

            DotNetProject p    = (DotNetProject)sol.FindProjectByName("console-with-libs");
            DotNetProject lib2 = (DotNetProject)sol.FindProjectByName("library2");

            Assert.AreSame(sol.StartupItem, p);

            var be = sol.Configurations ["Debug"].GetEntryForItem(lib2);

            be.Build             = false;
            be.ItemConfiguration = "FooConfig";
            await sol.SaveAsync(Util.GetMonitor());

            // Test that build configuration info is not lost when reloading a project

            lib2 = (DotNetProject)await lib2.ParentFolder.ReloadItem(Util.GetMonitor(), lib2);

            be = sol.Configurations ["Debug"].GetEntryForItem(lib2);
            Assert.IsFalse(be.Build);
            Assert.AreEqual("FooConfig", be.ItemConfiguration);

            // Test that startup project is the reloaded project

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

            Assert.AreSame(sol.StartupItem, p);

            sol.Dispose();
        }
        public async Task ConfigurationsInNewProject()
        {
            string dir = Util.CreateTmpDir("ConfigurationsInNewProject");

            var sol = new Solution();

            sol.FileName = Path.Combine(dir, "TestSolution.sln");
            sol.AddConfiguration("Debug", true);

            var p = Services.ProjectService.CreateDotNetProject("C#");

            p.ItemId   = "{3A83F683-760F-486C-8844-B0F079B30B25}";
            p.FileName = Path.Combine(dir, "TestProject.csproj");
            sol.RootFolder.Items.Add(p);

            Assert.AreEqual(1, p.RunConfigurations.Count);
            var es = p.RunConfigurations [0];

            Assert.AreEqual("Default", es.Name);

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

            Assert.IsFalse(File.Exists(p.FileName + ".user"));

            string projectXml    = File.ReadAllText(p.FileName);
            string projFile      = Util.GetSampleProject("run-configurations", "ConsoleProject", "ConsoleProject.new-project.csproj");
            string newProjectXml = File.ReadAllText(projFile);

            Assert.AreEqual(Util.ToWindowsEndings(newProjectXml), projectXml);

            sol.Dispose();
        }
Exemple #11
0
        //TODO: find solution that contains the project if possible
        public async Task <Solution> GetWrapperSolution(ProgressMonitor monitor, string filename)
        {
            // First of all, check if a solution with the same name already exists

            string solFileName = Path.ChangeExtension(filename, ".sln");

            if (File.Exists(solFileName))
            {
                return((Solution)await Services.ProjectService.ReadWorkspaceItem(monitor, solFileName));
            }
            else
            {
                // Create a temporary solution and add the project to the solution
                SolutionItem sitem = await Services.ProjectService.ReadSolutionItem(monitor, filename);

                Solution tempSolution = new Solution();
                tempSolution.FileName = solFileName;
                tempSolution.ConvertToFormat(sitem.FileFormat);
                tempSolution.RootFolder.Items.Add(sitem);
                tempSolution.CreateDefaultConfigurations();
                await tempSolution.SaveAsync(monitor);

                return(tempSolution);
            }
        }
Exemple #12
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();
        }
Exemple #13
0
        public async Task FormatConversions()
        {
            Solution sol = TestProjectsChecks.CreateConsoleSolution("reloading");
            Project  p   = (Project)sol.Items [0];

            Assert.AreEqual(MSBuildFileFormat.DefaultFormat.Id, sol.FileFormat.Id);
            Assert.AreEqual(MSBuildFileFormat.DefaultFormat.Id, p.FileFormat.Id);
            Assert.AreEqual("4.0", p.ToolsVersion);

            // Change solution format of unsaved solution

            sol.ConvertToFormat(MSBuildFileFormat.VS2008);

            Assert.AreEqual("MSBuild08", sol.FileFormat.Id);
            Assert.AreEqual("MSBuild08", p.FileFormat.Id);
            Assert.AreEqual("3.5", p.ToolsVersion);

            sol.ConvertToFormat(MSBuildFileFormat.VS2010);

            Assert.AreEqual("MSBuild10", sol.FileFormat.Id);
            Assert.AreEqual("MSBuild10", p.FileFormat.Id);
            Assert.AreEqual("4.0", p.ToolsVersion);

            // Change solution format of saved solution

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

            sol.ConvertToFormat(MSBuildFileFormat.VS2005);

            Assert.AreEqual("MSBuild05", sol.FileFormat.Id);
            Assert.AreEqual("MSBuild05", p.FileFormat.Id);
            Assert.AreEqual("2.0", p.ToolsVersion);

            // Add new project

            Project newp = Services.ProjectService.CreateDotNetProject("C#");

            Assert.AreEqual("MSBuild12", newp.FileFormat.Id);
            Assert.AreEqual("4.0", newp.ToolsVersion);

            sol.RootFolder.Items.Add(newp);
            Assert.AreEqual("MSBuild05", newp.FileFormat.Id);
            Assert.AreEqual("2.0", newp.ToolsVersion);

            // Add saved project

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

            Project mp = (Project)msol.Items [0];

            Assert.AreEqual("MSBuild05", mp.FileFormat.Id);

            sol.RootFolder.Items.Add(newp);
            Assert.AreEqual("MSBuild05", mp.FileFormat.Id);

            sol.Dispose();
        }
Exemple #14
0
        public async Task LocalCopyDefault()
        {
            string solFile = Util.GetSampleProject("local-copy-package", "ConsoleProject.sln");

            WorkspaceItem item = await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

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

            var ar = p.References.First(r => r.Reference.Contains("gtk"));

            if (!ar.Package.IsGacPackage)
            {
                Assert.Ignore("This test only works with gtk-sharp as a GAC package.");
            }

            Assert.AreEqual(false, ar.LocalCopy);
            ar.LocalCopy = true;
            Assert.AreEqual(true, ar.LocalCopy);

            ar = p.References.First(r => r.Reference.Contains("System.Data"));
            Assert.AreEqual(false, ar.LocalCopy);
            ar.LocalCopy = true;
            Assert.AreEqual(true, ar.LocalCopy);

            ar = p.References.First(r => r.Reference.Contains("LibProject"));
            Assert.AreEqual(true, ar.LocalCopy);
            ar.LocalCopy = false;
            Assert.AreEqual(false, ar.LocalCopy);

            ar = p.References.First(r => r.Reference.Contains("Xwt"));
            Assert.AreEqual(true, ar.LocalCopy);
            ar.LocalCopy = false;
            Assert.AreEqual(false, ar.LocalCopy);

            await sol.SaveAsync(new ProgressMonitor());

            await sol.Build(new ProgressMonitor(), "Debug");

            AssertOutputFiles(sol, "ConsoleProject", "Debug", new string[] {
                "ConsoleProject.exe",
                p.GetAssemblyDebugInfoFile(sol.Configurations["Debug"].Selector, "ConsoleProject.exe"),
                "System.Data.dll",
                "gtk-sharp.dll",
                "gtk-sharp.dll.config",
                "gtk-sharp.pdb",
            });

            string projectXml1 = Util.GetXmlFileInfoset(p.FileName.ParentDirectory.Combine("ConsoleProject.csproj.saved"));
            string projectXml2 = Util.GetXmlFileInfoset(p.FileName);

            Assert.AreEqual(projectXml1, projectXml2);

            item.Dispose();
        }
Exemple #15
0
        public async Task TestConfigurationMerging()
        {
            string   solFile = Util.GetSampleProject("test-configuration-merging", "TestConfigurationMerging.sln");
            Solution sol     = await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile) as Solution;

            Assert.IsNotNull(sol);
            Assert.AreEqual(1, sol.Items.Count);

            DotNetProject p = sol.Items[0] as DotNetProject;

            Assert.IsNotNull(p);

            // Debug config

            DotNetProjectConfiguration conf = p.Configurations["Debug"] as DotNetProjectConfiguration;

            Assert.IsNotNull(conf);
            Assert.AreEqual("Debug", conf.Name);
            Assert.AreEqual(string.Empty, conf.Platform);

            dynamic pars = conf.CompilationParameters;

            Assert.IsNotNull(pars);
            Assert.AreEqual(2, pars.WarningLevel);

            pars.WarningLevel = 4;

            // Release config

            conf = p.Configurations["Release"] as DotNetProjectConfiguration;
            Assert.IsNotNull(conf);
            Assert.AreEqual("Release", conf.Name);
            Assert.AreEqual(string.Empty, conf.Platform);

            pars = conf.CompilationParameters;
            Assert.IsNotNull(pars);
            Assert.AreEqual("ReleaseMod", Path.GetFileName(conf.OutputDirectory));
            Assert.AreEqual(3, pars.WarningLevel);

            pars.WarningLevel = 1;
            Assert.AreEqual(1, pars.WarningLevel);
            conf.DebugType    = "full";
            conf.DebugSymbols = true;

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

            Assert.AreEqual(1, pars.WarningLevel);

            string savedFile = Path.Combine(p.BaseDirectory, "TestConfigurationMergingSaved.csproj");

            Assert.AreEqual(File.ReadAllText(savedFile), File.ReadAllText(p.FileName));

            sol.Dispose();
        }
Exemple #16
0
        public async Task ReevaluateModifyItem()
        {
            string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");

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

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

            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;

            var file = p.Files.FirstOrDefault(f => f.FilePath.FileName == "Program.cs");

            Assert.IsTrue(file.Visible);

            var it = p.MSBuildProject.GetAllItems().First(i => i.Include == "Program.cs");

            it.Metadata.SetValue("Visible", "False");
            it.Metadata.SetValue("Foo", "Bar");

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

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

            Assert.AreEqual(new [] { @"Properties\AssemblyInfo.cs", "Program.cs" }, p.Files.Select(f => f.Include).ToArray());

            file = p.Files.FirstOrDefault(f => f.FilePath.FileName == "Program.cs");
            Assert.IsFalse(file.Visible);

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

            Assert.AreEqual(File.ReadAllText(p.FileName), File.ReadAllText(p.FileName.ChangeName("ConsoleProject-refresh-item-changed-saved")));

            sol.Dispose();
        }
Exemple #17
0
        public async Task AddNewProjectToSolution_ChangeFileInNewProject()
        {
            FilePath rootProject = Util.GetSampleProject("FileWatcherTest", "Root.csproj");
            string   solFile     = rootProject.ParentDirectory.Combine("FileWatcherTest", "FileWatcherTest3.sln");

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

            var p         = (DotNetProject)sol.Items [0];
            var otherFile = p.Files.First(f => f.FilePath.FileName == "MyClass.cs");
            await FileWatcherService.Add(sol);

            var libraryProjectFile = rootProject.ParentDirectory.Combine("Library", "Library.csproj");
            var p2 = (DotNetProject)await sol.RootFolder.AddItem(Util.GetMonitor(), libraryProjectFile);

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

            var file = p2.Files.First(f => f.FilePath.FileName == "MyClass.cs");
            await FileWatcherService.Update();

            ClearFileEventsCaptured();

            TextFileUtility.WriteText(file.FilePath, string.Empty, Encoding.UTF8);
            await WaitForFileChanged(file.FilePath);

            AssertFileChanged(file.FilePath);
            Assert.IsFalse(file.FilePath.IsChildPathOf(sol.BaseDirectory));

            sol.RootFolder.Items.Remove(p2);
            p2.Dispose();
            await sol.SaveAsync(Util.GetMonitor());

            await FileWatcherService.Update();

            ClearFileEventsCaptured();

            TextFileUtility.WriteText(file.FilePath, string.Empty, Encoding.UTF8);
            TextFileUtility.WriteText(otherFile.FilePath, string.Empty, Encoding.UTF8);
            await WaitForFilesChanged(new [] { file.FilePath, otherFile.FilePath });

            Assert.IsFalse(fileChanges.Any(f => f.FileName == file.FilePath));
        }
        public static async Task TestCreateLoadSaveConsoleProject(MSBuildFileFormat fileFormat)
        {
            Solution sol = CreateConsoleSolution("TestCreateLoadSaveConsoleProject");

            sol.ConvertToFormat(fileFormat);

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

            string solFile = sol.FileName;

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

            CheckConsoleProject(sol);

            // Save over existing file
            await sol.SaveAsync(Util.GetMonitor());

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

            CheckConsoleProject(sol);
        }
Exemple #19
0
        public async Task BuildConsoleProject()
        {
            Solution sol = TestProjectsChecks.CreateConsoleSolution("console-project-msbuild");
            await sol.SaveAsync(Util.GetMonitor());

            // Ensure the project is buildable
            var result = await sol.Build(Util.GetMonitor(), "Debug");

            Assert.AreEqual(0, result.ErrorCount, "#1");

            sol.Dispose();
        }
Exemple #20
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();
        }
Exemple #21
0
        public async Task ReevaluateAddRemoveItem()
        {
            string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");

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

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

            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;

            var it = p.MSBuildProject.GetAllItems().First(i => i.Include == "Program.cs");

            p.MSBuildProject.AddNewItem("Compile", "foo.cs", it);
            p.MSBuildProject.AddNewItem("Compile", "bar.cs");
            p.MSBuildProject.RemoveItem(it);

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

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

            Assert.AreEqual(new [] { @"Properties\AssemblyInfo.cs", "foo.cs", "bar.cs" }, p.Files.Select(f => f.Include).ToArray());
            Assert.AreEqual(new [] { "Compile", "Compile", "Compile" }, p.Files.Select(f => f.BuildAction).ToArray());

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

            Assert.AreEqual(File.ReadAllText(p.FileName), File.ReadAllText(p.FileName.ChangeName("ConsoleProject-refresh-saved")));

            sol.Dispose();
        }
Exemple #22
0
        public async Task SolutionBuildOrder()
        {
            string solFile = Util.GetSampleProject("solution-build-order", "ConsoleApplication3.sln");

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

            var p    = sol.FindProjectByName("ConsoleApplication3");
            var lib1 = sol.FindProjectByName("ClassLibrary1");
            var lib2 = sol.FindProjectByName("ClassLibrary2");

            Assert.IsTrue(p.ItemDependencies.Contains(lib1));
            Assert.IsTrue(p.ItemDependencies.Contains(lib2));
            Assert.AreEqual(2, p.ItemDependencies.Count);

            Assert.IsTrue(lib2.ItemDependencies.Contains(lib1));
            Assert.AreEqual(1, lib2.ItemDependencies.Count);
            Assert.AreEqual(0, lib1.ItemDependencies.Count);

            // Check that dependencies are saved

            var solContent1 = File.ReadAllLines(solFile);

            await sol.SaveAsync(new ProgressMonitor());

            var solContent2 = File.ReadAllLines(solFile);

            Assert.AreEqual(solContent1, solContent2);

            // Check that when an item is removed, it is removed from the dependencies list

            lib1.ParentFolder.Items.Remove(lib1);
            lib1.Dispose();

            Assert.IsTrue(p.ItemDependencies.Contains(lib2));
            Assert.AreEqual(1, p.ItemDependencies.Count);
            Assert.AreEqual(0, lib2.ItemDependencies.Count);

            // Check that when an item is reloaded, it is kept from the dependencies list

            var lib2Reloaded = await lib2.ParentFolder.ReloadItem(Util.GetMonitor(), lib2);

            Assert.AreNotEqual(lib2, lib2Reloaded);
            Assert.IsTrue(p.ItemDependencies.Contains(lib2Reloaded));
            Assert.AreEqual(1, p.ItemDependencies.Count);

            sol.Dispose();
        }
Exemple #23
0
        public async Task FirstBuildFlagNotRemovedAfterClean()
        {
            Solution sol     = TestProjectsChecks.CreateConsoleSolution("console-project-msbuild");
            var      project = sol.GetAllProjects().First();

            project.IsFirstBuild = true;
            Assert.IsTrue(project.UserProperties.GetValue <bool> ("FirstBuild"));

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

            var result = await sol.Clean(Util.GetMonitor(), "Debug");

            Assert.IsTrue(project.UserProperties.HasValue("FirstBuild"));
            Assert.IsTrue(project.IsFirstBuild);
            Assert.IsFalse(result.HasErrors);

            sol.Dispose();
        }
Exemple #24
0
        public async Task BuildConsoleProjectAfterRename()
        {
            Solution sol = TestProjectsChecks.CreateConsoleSolution("console-project-msbuild");
            await sol.SaveAsync(Util.GetMonitor());

            // Ensure the project is still buildable with xbuild after a rename
            var      project = sol.GetAllProjects().First();
            FilePath newFile = project.FileName.ParentDirectory.Combine("Test" + project.FileName.Extension);

            FileService.RenameFile(project.FileName, newFile.FileName);
            project.Name = "Test";

            var result = await sol.Build(Util.GetMonitor(), "Release");

            Assert.AreEqual(0, result.ErrorCount, "#2");

            sol.Dispose();
        }
Exemple #25
0
        public async Task ReevaluateLoadSave()
        {
            string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");

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

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

            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(0, itemAdded);
            Assert.AreEqual(0, itemRemoved);
            Assert.AreEqual(0, configAdded);
            Assert.AreEqual(0, configRemoved);
            Assert.IsFalse(configsChanged);
            Assert.IsFalse(runConfigsChanged);
            Assert.IsFalse(capabilitiesChanged);

            string projectXml = File.ReadAllText(p.FileName);

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

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

            sol.Dispose();
        }
Exemple #26
0
        public async Task Reloading()
        {
            using (Solution sol = TestProjectsChecks.CreateConsoleSolution("reloading")) {
                await sol.SaveAsync(Util.GetMonitor());

                Assert.IsFalse(sol.NeedsReload);
                await FileWatcherService.Add(sol);

                Project p = sol.Items [0] as Project;
                Assert.IsFalse(p.NeedsReload);

                // Changing format must reset the reload flag (it's like we just created a new solution in memory)
                sol.ConvertToFormat(MSBuildFileFormat.VS2010);
                Assert.IsFalse(sol.NeedsReload);
                Assert.IsFalse(p.NeedsReload);
                sol.ConvertToFormat(MSBuildFileFormat.VS2012);
                Assert.IsFalse(sol.NeedsReload);
                Assert.IsFalse(p.NeedsReload);

                sol.RootFolder.Items.Remove(p);
                Assert.IsFalse(p.NeedsReload);
                p.FileFormat = MSBuildFileFormat.VS2012;
                Assert.IsFalse(p.NeedsReload);
                sol.RootFolder.Items.Add(p);
                Assert.IsFalse(p.NeedsReload);
                sol.RootFolder.Items.Remove(p);
                Assert.IsFalse(p.NeedsReload);
                p.FileFormat = MSBuildFileFormat.VS2005;
                Assert.IsFalse(p.NeedsReload);
                sol.RootFolder.Items.Add(p);
                Assert.IsFalse(p.NeedsReload);

                string solFile2 = Util.GetSampleProject("csharp-console", "csharp-console.sln");
                using (Solution sol2 = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile2)) {
                    Project p2 = sol2.Items [0] as Project;
                    Assert.IsFalse(sol2.NeedsReload);
                    Assert.IsFalse(p2.NeedsReload);
                    await FileWatcherService.Add(sol2);

                    // Check reloading flag in another solution

                    string solFile = sol.FileName;
                    using (Solution sol3 = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile)) {
                        Assert.IsFalse(sol3.NeedsReload);
                        await FileWatcherService.Add(sol3);

                        Project p3 = sol3.Items [0] as Project;
                        Assert.IsFalse(p3.NeedsReload);

                        System.Threading.Thread.Sleep(1000);
                        try {
                            fileChangeNotification   = new TaskCompletionSource <bool> ();
                            waitForFileChange        = sol.FileName;
                            FileService.FileChanged += OnFileChanged;
                            sol.Description          = "Foo";                    // Small change to force the solution file save
                            await sol.SaveAsync(Util.GetMonitor());

                            // we need to wait for the file notification to be posted
                            await Task.Run(() => {
                                fileChangeNotification.Task.Wait(TimeSpan.FromMilliseconds(10000));
                            });

                            Assert.IsTrue(fileChangeNotification.Task.IsCompleted);
                        } finally {
                            FileService.FileChanged -= OnFileChanged;
                        }

                        Assert.IsTrue(sol3.NeedsReload);
                    }
                }
            }
        }
//
//		internal ICollection<SD.SolutionSection> Sections {
//			get { return solution.GlobalSections; }
//		}

        internal void Save()
        {
            Runtime.RunInMainThread(() => {
                solution.SaveAsync(new ProgressMonitor());
            }).Wait();
        }
Exemple #28
0
        public async Task MakefileSynchronization()
        {
            if (Platform.IsWindows)
            {
                Assert.Ignore();
            }

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

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

            Assert.AreEqual(2, p.Files.Count);
            string f = Path.Combine(p.BaseDirectory, "Program.cs");

            Assert.IsTrue(p.Files.GetFile(f) != null, "Contains Program.cs");
            f = Path.Combine(p.BaseDirectory, "Properties");
            f = Path.Combine(f, "AssemblyInfo.cs");
            Assert.IsTrue(p.Files.GetFile(f) != null, "Contains Properties/AssemblyInfo.cs");

            List <string> refs = new List <string> ();

            refs.Add("System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            refs.Add("System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            refs.Add("System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            Assert.AreEqual(3, p.References.Count);

            ProjectReference xmlRef = null;

            foreach (ProjectReference pref in p.References)
            {
                Assert.IsTrue(refs.Contains(pref.Reference), "Contains reference " + pref.Reference);
                refs.Remove(pref.Reference);
                if (pref.Reference.StartsWith("System.Xml"))
                {
                    xmlRef = pref;
                }
            }

            // Test saving

            p.References.Remove(xmlRef);
            p.References.Add(ProjectReference.CreateAssemblyReference("System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"));

            p.Files.Remove(f);
            p.Files.Add(new ProjectFile(Path.Combine(p.BaseDirectory, "Class1.cs"), BuildAction.Compile));

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

            string makefile = File.ReadAllText(Path.Combine(p.BaseDirectory, "Makefile"));

            string[] values = GetVariable(makefile, "FILES").Split(' ');
            Assert.AreEqual(2, values.Length);
            Assert.AreEqual("Class1.cs", values [0]);
            Assert.AreEqual("Program.cs", values [1]);

            values = GetVariable(makefile, "REFERENCES").Split(' ');
            Assert.AreEqual(3, values.Length);
            Assert.AreEqual("System", values [0]);
            Assert.AreEqual("System.Data", values [1]);
            Assert.AreEqual("System.Web", values [2]);
        }
        public static async Task TestLoadSaveSolutionFolders(MSBuildFileFormat fileFormat)
        {
            List <string> ids = new List <string> ();

            Solution sol = new Solution();

            sol.ConvertToFormat(fileFormat);
            string dir = Util.CreateTmpDir("solution-folders-" + fileFormat.Name);

            sol.FileName = Path.Combine(dir, "TestSolutionFolders");
            sol.Name     = "TheSolution";

            var p1 = Services.ProjectService.CreateDotNetProject("C#");

            p1.FileName = Path.Combine(dir, "p1");
            sol.RootFolder.Items.Add(p1);
            string idp1 = p1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp1));
            Assert.IsFalse(ids.Contains(idp1));
            ids.Add(idp1);

            SolutionFolder f1 = new SolutionFolder();

            f1.Name = "f1";
            sol.RootFolder.Items.Add(f1);
            string idf1 = f1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf1));
            Assert.IsFalse(ids.Contains(idf1));
            ids.Add(idf1);

            var p2 = Services.ProjectService.CreateDotNetProject("C#");

            p2.FileName = Path.Combine(dir, "p2");
            f1.Items.Add(p2);
            string idp2 = p2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp2));
            Assert.IsFalse(ids.Contains(idp2));
            ids.Add(idp2);

            SolutionFolder f2 = new SolutionFolder();

            f2.Name = "f2";
            f1.Items.Add(f2);
            string idf2 = f2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf2));
            Assert.IsFalse(ids.Contains(idf2));
            ids.Add(idf2);

            var p3 = Services.ProjectService.CreateDotNetProject("C#");

            p3.FileName = Path.Combine(dir, "p3");
            f2.Items.Add(p3);
            string idp3 = p3.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp3));
            Assert.IsFalse(ids.Contains(idp3));
            ids.Add(idp3);

            var p4 = Services.ProjectService.CreateDotNetProject("C#");

            p4.FileName = Path.Combine(dir, "p4");
            f2.Items.Add(p4);
            string idp4 = p4.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp4));
            Assert.IsFalse(ids.Contains(idp4));
            ids.Add(idp4);

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

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

            Assert.AreEqual(4, sol2.Items.Count);
            Assert.AreEqual(2, sol2.RootFolder.Items.Count);
            Assert.AreEqual(typeof(CSharpProject), sol2.RootFolder.Items [0].GetType());
            Assert.AreEqual(typeof(SolutionFolder), sol2.RootFolder.Items [1].GetType());
            Assert.AreEqual("p1", sol2.RootFolder.Items [0].Name);
            Assert.AreEqual("f1", sol2.RootFolder.Items [1].Name);
            Assert.AreEqual(idp1, sol2.RootFolder.Items [0].ItemId, "idp1");
            Assert.AreEqual(idf1, sol2.RootFolder.Items [1].ItemId, "idf1");

            f1 = (SolutionFolder)sol2.RootFolder.Items [1];
            Assert.AreEqual(2, f1.Items.Count);
            Assert.AreEqual(typeof(CSharpProject), f1.Items [0].GetType());
            Assert.AreEqual(typeof(SolutionFolder), f1.Items [1].GetType());
            Assert.AreEqual("p2", f1.Items [0].Name);
            Assert.AreEqual("f2", f1.Items [1].Name);
            Assert.AreEqual(idp2, f1.Items [0].ItemId, "idp2");
            Assert.AreEqual(idf2, f1.Items [1].ItemId, "idf2");

            f2 = (SolutionFolder)f1.Items [1];
            Assert.AreEqual(2, f2.Items.Count);
            Assert.AreEqual(typeof(CSharpProject), f2.Items [0].GetType());
            Assert.AreEqual(typeof(CSharpProject), f2.Items [1].GetType());
            Assert.AreEqual("p3", f2.Items [0].Name);
            Assert.AreEqual("p4", f2.Items [1].Name);
            Assert.AreEqual(idp3, f2.Items [0].ItemId, "idp4");
            Assert.AreEqual(idp4, f2.Items [1].ItemId, "idp4");
        }
        public async Task SaveSharedProject()
        {
            Solution sol = TestProjectsChecks.CreateConsoleSolution("shared-project");

            sol.ConvertToFormat(MSBuildFileFormat.VS2012);
            await sol.SaveAsync(Util.GetMonitor());

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

            // Add shared project

            var sp = new SharedAssetsProject()
            {
                LanguageName     = "C#",
                DefaultNamespace = "TestNamespace"
            };

            sp.AddFile(sol.ItemDirectory.Combine("Test.cs"));
            await sp.SaveAsync(Util.GetMonitor(), sol.ItemDirectory.Combine("Shared"));

            sol.RootFolder.AddItem(sp);
            await sol.SaveAsync(Util.GetMonitor());

            // Make sure we compare using the same guid

            string solXml                = File.ReadAllText(sol.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            string projectXml            = Util.GetXmlFileInfoset(pc.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
            string sharedProjectXml      = Util.GetXmlFileInfoset(sp.FileName).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            string sharedProjectItemsXml = Util.GetXmlFileInfoset(sp.FileName.ChangeExtension(".projitems")).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

            string refSolXml                = Util.ToWindowsEndings(File.ReadAllText(Util.GetSampleProjectPath("generated-shared-project", "TestSolution.sln")));
            string refProjectXml            = Util.ToWindowsEndings(Util.GetXmlFileInfoset(Util.GetSampleProjectPath("generated-shared-project", "TestProject.csproj")));
            string refSharedProjectXml      = Util.ToWindowsEndings(Util.GetXmlFileInfoset(Util.GetSampleProjectPath("generated-shared-project", "Shared.shproj")));
            string refSharedProjectItemsXml = Util.ToWindowsEndings(Util.GetXmlFileInfoset(Util.GetSampleProjectPath("generated-shared-project", "Shared.projitems")));

            Assert.AreEqual(refSolXml, solXml);
            Assert.AreEqual(refProjectXml, projectXml);
            Assert.AreEqual(refSharedProjectXml, sharedProjectXml);
            Assert.AreEqual(refSharedProjectItemsXml, sharedProjectItemsXml);

            // Add a reference

            var r = ProjectReference.CreateProjectReference(sp);

            pc.References.Add(r);
            await sol.SaveAsync(Util.GetMonitor());

            solXml                = File.ReadAllText(sol.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            projectXml            = Util.GetXmlFileInfoset(pc.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
            sharedProjectXml      = Util.GetXmlFileInfoset(sp.FileName).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            sharedProjectItemsXml = Util.GetXmlFileInfoset(sp.FileName.ChangeExtension(".projitems")).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

            refProjectXml = Util.ToWindowsEndings(Util.GetXmlFileInfoset(Util.GetSampleProjectPath("generated-shared-project", "TestProject.csproj.saved1")));

            Assert.AreEqual(refSolXml, solXml);
            Assert.AreEqual(refProjectXml, projectXml);
            Assert.AreEqual(refSharedProjectXml, sharedProjectXml);
            Assert.AreEqual(refSharedProjectItemsXml, sharedProjectItemsXml);

            // Add a file and change the default namespace

            sp.DefaultNamespace = "TestNamespace2";
            var file = sp.AddFile(sol.ItemDirectory.Combine("Test2.cs"));
            await sol.SaveAsync(Util.GetMonitor());

            solXml                = File.ReadAllText(sol.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            projectXml            = Util.GetXmlFileInfoset(pc.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
            sharedProjectXml      = Util.GetXmlFileInfoset(sp.FileName).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            sharedProjectItemsXml = Util.GetXmlFileInfoset(sp.FileName.ChangeExtension(".projitems")).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

            refSharedProjectItemsXml = Util.ToWindowsEndings(Util.GetXmlFileInfoset(Util.GetSampleProjectPath("generated-shared-project", "Shared.projitems.saved1")));

            Assert.AreEqual(refSolXml, solXml);
            Assert.AreEqual(refProjectXml, projectXml);
            Assert.AreEqual(refSharedProjectXml, sharedProjectXml);
            Assert.AreEqual(refSharedProjectItemsXml, sharedProjectItemsXml);

            // Remove a file and restore the namespace

            sp.DefaultNamespace = "TestNamespace";
            sp.Files.Remove(file);
            await sol.SaveAsync(Util.GetMonitor());

            solXml                = File.ReadAllText(sol.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            projectXml            = Util.GetXmlFileInfoset(pc.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
            sharedProjectXml      = Util.GetXmlFileInfoset(sp.FileName).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            sharedProjectItemsXml = Util.GetXmlFileInfoset(sp.FileName.ChangeExtension(".projitems")).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

            refSharedProjectItemsXml = Util.ToWindowsEndings(Util.GetXmlFileInfoset(Util.GetSampleProjectPath("generated-shared-project", "Shared.projitems")));

            Assert.AreEqual(refSolXml, solXml);
            Assert.AreEqual(refProjectXml, projectXml);
            Assert.AreEqual(refSharedProjectXml, sharedProjectXml);
            Assert.AreEqual(refSharedProjectItemsXml, sharedProjectItemsXml);

            // Remove reference

            pc.References.Remove(r);
            await sol.SaveAsync(Util.GetMonitor());

            solXml                = File.ReadAllText(sol.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            projectXml            = Util.GetXmlFileInfoset(pc.FileName).Replace(pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
            sharedProjectXml      = Util.GetXmlFileInfoset(sp.FileName).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
            sharedProjectItemsXml = Util.GetXmlFileInfoset(sp.FileName.ChangeExtension(".projitems")).Replace(sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

            refProjectXml = Util.ToWindowsEndings(Util.GetXmlFileInfoset(Util.GetSampleProjectPath("generated-shared-project", "TestProject.csproj")));

            Assert.AreEqual(refSolXml, solXml);
            Assert.AreEqual(refProjectXml, projectXml);
            Assert.AreEqual(refSharedProjectXml, sharedProjectXml);
            Assert.AreEqual(refSharedProjectItemsXml, sharedProjectItemsXml);

            sol.Dispose();
        }