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(); }
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(); }
public void FormatConversions() { Solution sol = TestProjectsChecks.CreateConsoleSolution("reloading"); Project p = (Project)sol.Items [0]; Assert.AreEqual(Services.ProjectService.DefaultFileFormat.Id, sol.FileFormat.Id); Assert.AreEqual(Services.ProjectService.DefaultFileFormat.Id, p.FileFormat.Id); Assert.AreEqual("4.0", MSBuildProjectService.GetHandler(p).ToolsVersion); // Change solution format of unsaved solution sol.ConvertToFormat(Util.FileFormatMSBuild08, true); Assert.AreEqual("MSBuild08", sol.FileFormat.Id); Assert.AreEqual("MSBuild08", p.FileFormat.Id); Assert.AreEqual("3.5", MSBuildProjectService.GetHandler(p).ToolsVersion); sol.ConvertToFormat(Util.FileFormatMSBuild10, true); Assert.AreEqual("MSBuild10", sol.FileFormat.Id); Assert.AreEqual("MSBuild10", p.FileFormat.Id); Assert.AreEqual("4.0", MSBuildProjectService.GetHandler(p).ToolsVersion); // Change solution format of saved solution sol.Save(Util.GetMonitor()); sol.ConvertToFormat(Util.FileFormatMSBuild05, false); Assert.AreEqual("MSBuild05", sol.FileFormat.Id); Assert.AreEqual("MSBuild05", p.FileFormat.Id); Assert.AreEqual("2.0", MSBuildProjectService.GetHandler(p).ToolsVersion); // Add new project Project newp = new DotNetAssemblyProject("C#"); Assert.AreEqual("MSBuild12", newp.FileFormat.Id); Assert.AreEqual("4.0", MSBuildProjectService.GetHandler(newp).ToolsVersion); sol.RootFolder.Items.Add(newp); Assert.AreEqual("MSBuild05", newp.FileFormat.Id); Assert.AreEqual("2.0", MSBuildProjectService.GetHandler(newp).ToolsVersion); // Add saved project string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); Solution msol = (Solution)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); }
public void Reloading() { Solution sol = TestProjectsChecks.CreateConsoleSolution("reloading"); sol.Save(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(Util.FileFormatMD1, true); Assert.IsFalse(sol.NeedsReload); Assert.IsFalse(p.NeedsReload); sol.ConvertToFormat(Util.FileFormatMSBuild05, true); Assert.IsFalse(sol.NeedsReload); Assert.IsFalse(p.NeedsReload); sol.RootFolder.Items.Remove(p); Assert.IsFalse(p.NeedsReload); p.FileFormat = Util.FileFormatMD1; Assert.IsFalse(p.NeedsReload); sol.RootFolder.Items.Add(p); Assert.IsFalse(p.NeedsReload); sol.RootFolder.Items.Remove(p); Assert.IsFalse(p.NeedsReload); p.FileFormat = Util.FileFormatMSBuild05; Assert.IsFalse(p.NeedsReload); sol.RootFolder.Items.Add(p); Assert.IsFalse(p.NeedsReload); string mdsSolFile = Util.GetSampleProject("csharp-console-mdp", "csharp-console-mdp.mds"); Solution mdsSol = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), mdsSolFile); Project pmds = mdsSol.Items [0] as Project; Assert.IsFalse(mdsSol.NeedsReload); Assert.IsFalse(pmds.NeedsReload); // Check reloading flag in another solution string solFile = sol.FileName; Solution sol2 = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); Assert.IsFalse(sol2.NeedsReload); Project p2 = sol2.Items [0] as Project; Assert.IsFalse(p2.NeedsReload); System.Threading.Thread.Sleep(1000); sol.Save(Util.GetMonitor()); Assert.IsTrue(sol2.NeedsReload); }
public void CreateConsoleProject() { Solution sol = TestProjectsChecks.CreateConsoleSolution("console-project-msbuild"); sol.ConvertToFormat(Util.FileFormatMSBuild10, true); sol.Save(Util.GetMonitor()); // msbuild format string solXml = File.ReadAllText(sol.FileName); string projectXml = Util.GetXmlFileInfoset(((SolutionEntityItem)sol.Items [0]).FileName); // Make sure we compare using the same guid Project p = sol.Items [0] as Project; string guid = p.ItemId; solXml = solXml.Replace(guid, "{969F05E2-0E79-4C5B-982C-8F3DD4D46311}"); projectXml = projectXml.Replace(guid, "{969F05E2-0E79-4C5B-982C-8F3DD4D46311}"); string solFile = Util.GetSampleProjectPath("generated-console-project", "TestSolution.sln"); string projectFile = Util.GetSampleProjectPath("generated-console-project", "TestProject.csproj"); Assert.AreEqual(Util.ToWindowsEndings(File.ReadAllText(solFile)), solXml); Assert.AreEqual(Util.ToWindowsEndings(Util.GetXmlFileInfoset(projectFile)), projectXml); }
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); }
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); }
//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); } }
public static void CheckGenericItemProject(string fileFormat) { Solution sol = new Solution(); sol.ConvertToFormat(Services.ProjectService.FileFormats.GetFileFormat(fileFormat), true); string dir = Util.CreateTmpDir("generic-item-" + fileFormat); sol.FileName = Path.Combine(dir, "TestGenericItem"); sol.Name = "TheItem"; GenericItem it = new GenericItem(); it.SomeValue = "hi"; sol.RootFolder.Items.Add(it); it.FileName = Path.Combine(dir, "TheItem"); it.Name = "TheItem"; sol.Save(Util.GetMonitor()); Solution sol2 = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), sol.FileName); Assert.AreEqual(1, sol2.Items.Count); Assert.IsTrue(sol2.Items [0] is GenericItem); it = (GenericItem)sol2.Items [0]; Assert.AreEqual("hi", it.SomeValue); }
//TODO: find solution that contains the project if possible public Solution GetWrapperSolution(IProgressMonitor monitor, string filename) { // First of all, check if a solution with the same name already exists FileFormat[] formats = Services.ProjectService.FileFormats.GetFileFormats(filename, typeof(SolutionEntityItem)); if (formats.Length == 0) { formats = new [] { DefaultFileFormat } } ; Solution tempSolution = new Solution(); FileFormat solutionFileFormat = formats.FirstOrDefault(f => f.CanWrite(tempSolution)) ?? DefaultFileFormat; string solFileName = solutionFileFormat.GetValidFileName(tempSolution, filename); if (File.Exists(solFileName)) { return((Solution)Services.ProjectService.ReadWorkspaceItem(monitor, solFileName)); } else { // Create a temporary solution and add the project to the solution tempSolution.SetLocation(Path.GetDirectoryName(filename), Path.GetFileNameWithoutExtension(filename)); SolutionEntityItem sitem = Services.ProjectService.ReadSolutionItem(monitor, filename); tempSolution.ConvertToFormat(solutionFileFormat, false); tempSolution.RootFolder.Items.Add(sitem); tempSolution.CreateDefaultConfigurations(); tempSolution.Save(monitor); return(tempSolution); } }
public void ProjectName() { int nameChanges = 0; var prj = Services.ProjectService.CreateDotNetProject("C#"); prj.FileFormat = MSBuildFileFormat.VS2005; prj.NameChanged += delegate { nameChanges++; }; prj.Name = "test1"; Assert.AreEqual("test1", prj.Name); Assert.AreEqual("test1.csproj", (string)prj.FileName); Assert.AreEqual(1, nameChanges); prj.Name = "test2"; Assert.AreEqual("test2", prj.Name); Assert.AreEqual("test2.csproj", (string)prj.FileName); Assert.AreEqual(2, nameChanges); string fname = Path.Combine(Path.GetTempPath(), "test3.csproj"); prj.FileName = fname; Assert.AreEqual("test3", prj.Name); Assert.AreEqual(fname, (string)prj.FileName); Assert.AreEqual(3, nameChanges); prj.Name = "test4"; Assert.AreEqual("test4", prj.Name); Assert.AreEqual(Path.Combine(Path.GetTempPath(), "test4.csproj"), (string)prj.FileName); Assert.AreEqual(4, nameChanges); prj.FileFormat = MSBuildFileFormat.VS2012; Assert.AreEqual("test4", prj.Name); Assert.AreEqual(Path.Combine(Path.GetTempPath(), "test4.csproj"), (string)prj.FileName); Assert.AreEqual(4, nameChanges); Assert.AreEqual("MSBuild12", prj.FileFormat.Id); // Projects inherit the file format from the parent solution Solution sol = new Solution(); sol.ConvertToFormat(MSBuildFileFormat.VS2005); sol.RootFolder.Items.Add(prj); Assert.AreEqual("test4", prj.Name); Assert.AreEqual(Path.Combine(Path.GetTempPath(), "test4.csproj"), (string)prj.FileName); Assert.AreEqual(4, nameChanges); Assert.AreEqual("MSBuild05", prj.FileFormat.Id); // Removing the project from the solution should not restore the old format sol.RootFolder.Items.Remove(prj); Assert.AreEqual("MSBuild05", prj.FileFormat.Id); Assert.AreEqual("test4", prj.Name); Assert.AreEqual(Path.Combine(Path.GetTempPath(), "test4.csproj"), (string)prj.FileName); Assert.AreEqual(4, nameChanges); prj.Dispose(); }
public void ProjectName() { int nameChanges = 0; DotNetAssemblyProject prj = new DotNetAssemblyProject("C#"); prj.FileFormat = Util.FileFormatMSBuild05; prj.NameChanged += delegate { nameChanges++; }; prj.Name = "test1"; Assert.AreEqual("test1", prj.Name); Assert.AreEqual("test1.csproj", (string)prj.FileName); Assert.AreEqual(1, nameChanges); prj.Name = "test2"; Assert.AreEqual("test2", prj.Name); Assert.AreEqual("test2.csproj", (string)prj.FileName); Assert.AreEqual(2, nameChanges); string fname = Path.Combine(Path.GetTempPath(), "test3.csproj"); prj.FileName = fname; Assert.AreEqual("test3", prj.Name); Assert.AreEqual(fname, (string)prj.FileName); Assert.AreEqual(3, nameChanges); prj.Name = "test4"; Assert.AreEqual("test4", prj.Name); Assert.AreEqual(Path.Combine(Path.GetTempPath(), "test4.csproj"), (string)prj.FileName); Assert.AreEqual(4, nameChanges); prj.FileFormat = Util.FileFormatMD1; Assert.AreEqual("test4", prj.Name); Assert.AreEqual(Path.Combine(Path.GetTempPath(), "test4.mdp"), (string)prj.FileName); Assert.AreEqual(4, nameChanges); Assert.AreEqual("MD1", prj.FileFormat.Id); // Projects inherit the file format from the parent solution Solution sol = new Solution(); sol.ConvertToFormat(Util.FileFormatMSBuild05, true); sol.RootFolder.Items.Add(prj); Assert.AreEqual("test4", prj.Name); Assert.AreEqual(Path.Combine(Path.GetTempPath(), "test4.csproj"), (string)prj.FileName); Assert.AreEqual(4, nameChanges); Assert.AreEqual("MSBuild05", prj.FileFormat.Id); // Removing the project from the solution should not restore the old format sol.RootFolder.Items.Remove(prj); Assert.AreEqual("MSBuild05", prj.FileFormat.Id); Assert.AreEqual("test4", prj.Name); Assert.AreEqual(Path.Combine(Path.GetTempPath(), "test4.csproj"), (string)prj.FileName); Assert.AreEqual(4, nameChanges); }
public void CreateConsoleProject() { Solution sol = TestProjectsChecks.CreateConsoleSolution("console-project-msbuild"); sol.ConvertToFormat(Util.FileFormatMSBuild05, true); sol.Save(Util.GetMonitor()); // msbuild format string solXml = File.ReadAllText(sol.FileName); string projectXml = Util.GetXmlFileInfoset(((SolutionEntityItem)sol.Items [0]).FileName); // Make sure we compare using the same guid Project p = sol.Items [0] as Project; string guid = p.ItemId; solXml = solXml.Replace(guid, "{DC577202-654B-4FDB-95C7-8CC5DDF6D32D}"); projectXml = projectXml.Replace(guid, "{DC577202-654B-4FDB-95C7-8CC5DDF6D32D}"); string solFile = Util.GetSampleProjectPath("generated-console-project", "TestSolution.sln"); string projectFile = Util.GetSampleProjectPath("generated-console-project", "TestProject.csproj"); Assert.AreEqual(File.ReadAllText(solFile), solXml); Assert.AreEqual(Util.GetXmlFileInfoset(projectFile), projectXml); // MD1 format sol.ConvertToFormat(Util.FileFormatMD1, true); sol.Save(Util.GetMonitor()); solXml = Util.GetXmlFileInfoset(sol.FileName); projectXml = Util.GetXmlFileInfoset(((SolutionEntityItem)sol.Items [0]).FileName); solFile = Util.GetSampleProjectPath("generated-console-project", "TestSolution.mds"); projectFile = Util.GetSampleProjectPath("generated-console-project", "TestProject.mdp"); Assert.AreEqual(Util.GetXmlFileInfoset(solFile), solXml, "solXml: " + sol.FileName); Assert.AreEqual(Util.GetXmlFileInfoset(projectFile), projectXml, "projectXml: " + ((SolutionEntityItem)sol.Items [0]).FileName); // sol.FileFormat = Services.ProjectService.FileFormats.GetFileFormat ("MSBuild08"); // sol.Save (Util.GetMonitor ()); }
public static void TestCreateLoadSaveConsoleProject(string fileFormat) { Solution sol = CreateConsoleSolution("TestCreateLoadSaveConsoleProject"); sol.ConvertToFormat(Services.ProjectService.FileFormats.GetFileFormat(fileFormat), true); sol.Save(Util.GetMonitor()); string solFile = sol.FileName; sol = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); CheckConsoleProject(sol); // Save over existing file sol.Save(Util.GetMonitor()); sol = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); CheckConsoleProject(sol); }
public void CreateNestedSolutions() { Solution sol = TestProjectsChecks.CreateProjectWithFolders("nested-solutions-md1"); sol.ConvertToFormat(Util.FileFormatMD1, true); sol.Save(Util.GetMonitor()); string solFile = Util.GetSampleProjectPath("nested-solutions-mdp", "nested-solutions-mdp.mds"); string dir = Path.GetDirectoryName(solFile); string solXml = Util.GetXmlFileInfoset(solFile); string p1Xml = Util.GetXmlFileInfoset(dir, "console-project", "console-project.mdp"); string s1Xml = Util.GetXmlFileInfoset(dir, "nested-solution1", "nested-solution1.mds"); string s2Xml = Util.GetXmlFileInfoset(dir, "nested-solution2", "nested-solution2.mds"); string plib1Xml = Util.GetXmlFileInfoset(dir, "nested-solution1", "library1", "library1.mdp"); string plib2Xml = Util.GetXmlFileInfoset(dir, "nested-solution1", "library2", "library2.mdp"); string p2Xml = Util.GetXmlFileInfoset(dir, "nested-solution2", "console-project2", "console-project2.mdp"); string s3Xml = Util.GetXmlFileInfoset(dir, "nested-solution2", "nested-solution3", "nested-solution3.mds"); string plib3Xml = Util.GetXmlFileInfoset(dir, "nested-solution2", "nested-solution3", "library3", "library3.mdp"); string plib4Xml = Util.GetXmlFileInfoset(dir, "nested-solution2", "nested-solution3", "library4", "library4.mdp"); dir = Path.GetDirectoryName(sol.FileName); string solXml2 = Util.GetXmlFileInfoset(solFile); string p1Xml2 = Util.GetXmlFileInfoset(dir, "console-project", "console-project.mdp"); string s1Xml2 = Util.GetXmlFileInfoset(dir, "nested-solution1", "nested-solution1.mds"); string s2Xml2 = Util.GetXmlFileInfoset(dir, "nested-solution2", "nested-solution2.mds"); string plib1Xml2 = Util.GetXmlFileInfoset(dir, "nested-solution1", "library1", "library1.mdp"); string plib2Xml2 = Util.GetXmlFileInfoset(dir, "nested-solution1", "library2", "library2.mdp"); string p2Xml2 = Util.GetXmlFileInfoset(dir, "nested-solution2", "console-project2", "console-project2.mdp"); string s3Xml2 = Util.GetXmlFileInfoset(dir, "nested-solution2", "nested-solution3", "nested-solution3.mds"); string plib3Xml2 = Util.GetXmlFileInfoset(dir, "nested-solution2", "nested-solution3", "library3", "library3.mdp"); string plib4Xml2 = Util.GetXmlFileInfoset(dir, "nested-solution2", "nested-solution3", "library4", "library4.mdp"); Assert.AreEqual(solXml, solXml2, "solXml"); Assert.AreEqual(p1Xml, p1Xml2, "p1Xml"); Assert.AreEqual(s1Xml, s1Xml2, "s1Xml"); Assert.AreEqual(s2Xml, s2Xml2, "s2Xml"); Assert.AreEqual(plib1Xml, plib1Xml2, "plib1Xml"); Assert.AreEqual(plib2Xml, plib2Xml2, "plib2Xml"); Assert.AreEqual(p2Xml, p2Xml2, "p2Xml"); Assert.AreEqual(s3Xml, s3Xml2, "s3Xml"); Assert.AreEqual(plib3Xml, plib3Xml2, "plib3Xml"); Assert.AreEqual(plib4Xml, plib4Xml2, "plib4Xml"); }
public void RoundtripPropertyWithXmlCharacters() { Solution sol = TestProjectsChecks.CreateConsoleSolution("roundtrip-property-with-xml"); sol.ConvertToFormat(Util.FileFormatMSBuild05, true); var value = "Hello<foo>&.exe"; var p = (DotNetProject)sol.GetAllProjects().First(); var conf = ((DotNetProjectConfiguration)p.Configurations [0]); conf.OutputAssembly = value; sol.Save(Util.GetMonitor()); sol = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), sol.FileName); p = (DotNetProject)sol.GetAllProjects().First(); conf = ((DotNetProjectConfiguration)p.Configurations [0]); Assert.AreEqual(value, conf.OutputAssembly); }
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); }
public void SolutionName() { int nameChanges = 0; Solution sol = new Solution(); sol.NameChanged += delegate { nameChanges++; }; string tmp = Path.GetTempPath(); sol.Name = "test1"; Assert.AreEqual("test1", sol.Name); Assert.AreEqual("test1.sln", (string)sol.FileName); Assert.AreEqual(1, nameChanges); sol.Name = "test2"; Assert.AreEqual("test2", sol.Name); Assert.AreEqual("test2.sln", (string)sol.FileName); Assert.AreEqual(2, nameChanges); sol.FileName = Path.Combine(tmp, "test3.sln"); Assert.AreEqual("test3", sol.Name); Assert.AreEqual(Path.Combine(tmp, "test3.sln"), (string)sol.FileName); Assert.AreEqual(3, nameChanges); sol.Name = "test4"; Assert.AreEqual("test4", sol.Name); Assert.AreEqual(Path.Combine(tmp, "test4.sln"), (string)sol.FileName); Assert.AreEqual(4, nameChanges); sol.ConvertToFormat(MSBuildFileFormat.VS2010); Assert.AreEqual("test4", sol.Name); Assert.AreEqual(Path.Combine(tmp, "test4.sln"), (string)sol.FileName); Assert.AreEqual(4, nameChanges); sol.Dispose(); }
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); } } } }
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(); }