public void BuildSolutionWithUnsupportedProjects() { string solFile = Util.GetSampleProject("unsupported-project", "console-with-libs.sln"); Solution sol = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var res = sol.Build(Util.GetMonitor(), "Debug"); // The solution has a console app that references an unsupported library. The build of the solution should fail. Assert.IsTrue(res.ErrorCount == 1); var app = (DotNetAssemblyProject)sol.GetAllSolutionItems <SolutionEntityItem> ().FirstOrDefault(it => it.FileName.FileName == "console-with-libs.csproj"); // The console app references an unsupported library. The build of the project should fail. res = 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(); sol.Save(Util.GetMonitor()); res = sol.Build(Util.GetMonitor(), "Debug"); Assert.IsTrue(res.ErrorCount == 0); // Regular project not referencing anything else. Should build. res = app.Build(Util.GetMonitor(), ConfigurationSelector.Default, true); Assert.IsTrue(res.ErrorCount == 0); }
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); }
public void BuildConsoleProject() { var current = PropertyService.Get("MonoDevelop.Ide.BuildWithMSBuild", false); try { PropertyService.Set("MonoDevelop.Ide.BuildWithMSBuild", true); Solution sol = TestProjectsChecks.CreateConsoleSolution("console-project-msbuild"); sol.Save(Util.GetMonitor()); // Ensure the project is buildable var result = sol.Build(Util.GetMonitor(), "Debug"); Assert.AreEqual(0, result.ErrorCount, "#1"); // Ensure the project is still buildable with xbuild after a rename ProjectOptionsDialog.RenameItem(sol.GetAllProjects() [0], "Test"); result = sol.Build(Util.GetMonitor(), "Release"); Assert.AreEqual(0, result.ErrorCount, "#2"); } finally { PropertyService.Set("MonoDevelop.Ide.BuildWithMSBuild", current); } }
public void LoadSaveBuildConsoleProject() { string solFile = Util.GetSampleProject("csharp-console-mdp", "csharp-console-mdp.mds"); WorkspaceItem item = Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); Assert.IsTrue(item is Solution); Solution sol = (Solution)item; TestProjectsChecks.CheckBasicMdConsoleProject(sol); string projectFile = ((Project)sol.Items [0]).FileName; BuildResult cr = item.Build(Util.GetMonitor(), (SolutionConfigurationSelector)"Debug"); Assert.IsNotNull(cr); Assert.AreEqual(0, cr.ErrorCount); Assert.AreEqual(0, cr.WarningCount); string solXml = Util.GetXmlFileInfoset(solFile); string projectXml = Util.GetXmlFileInfoset(projectFile); sol.Save(Util.GetMonitor()); Assert.AreEqual(solXml, Util.GetXmlFileInfoset(solFile), "Saved solution file"); Assert.AreEqual(projectXml, Util.GetXmlFileInfoset(projectFile), "Saved project file"); }
public void ReloadingKeepsBuildConfigurationAndStartupProject() { string solFile = Util.GetSampleProject("console-with-libs", "console-with-libs.sln"); Solution sol = (Solution)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"; sol.Save(Util.GetMonitor()); // Test that build configuration info is not lost when reloading a project lib2 = (DotNetProject)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)p.ParentFolder.ReloadItem(Util.GetMonitor(), p); Assert.AreSame(sol.StartupItem, p); }
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 void LoadSaveBuildConsoleProject() { string solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln"); WorkspaceItem item = Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); Assert.IsTrue(item is Solution); Solution sol = (Solution)item; TestProjectsChecks.CheckBasicVsConsoleProject(sol); string projectFile = ((Project)sol.Items [0]).FileName; BuildResult cr = item.Build(Util.GetMonitor(), "Debug"); Assert.IsNotNull(cr); Assert.AreEqual(0, cr.ErrorCount); Assert.AreEqual(0, cr.WarningCount); string solXml = File.ReadAllText(solFile); string projectXml = Util.GetXmlFileInfoset(projectFile); sol.Save(Util.GetMonitor()); Assert.AreEqual(solXml, File.ReadAllText(solFile)); Assert.AreEqual(projectXml, Util.GetXmlFileInfoset(projectFile)); }
//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 LoadKnownUnsupportedProjects() { string solFile = Util.GetSampleProject("unsupported-project", "console-with-libs.sln"); Solution sol = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); var app = sol.GetAllSolutionItems <SolutionEntityItem> ().FirstOrDefault(it => it.FileName.FileName == "console-with-libs.csproj"); var lib1 = sol.GetAllSolutionItems <SolutionEntityItem> ().FirstOrDefault(it => it.FileName.FileName == "library1.csproj"); var lib2 = sol.GetAllSolutionItems <SolutionEntityItem> ().FirstOrDefault(it => it.FileName.FileName == "library2.csproj"); Assert.IsInstanceOf <DotNetAssemblyProject> (app); Assert.IsInstanceOf <UnknownSolutionItem> (lib1); Assert.IsInstanceOf <UnknownProject> (lib2); var p = (UnknownProject)lib2; Assert.AreEqual(2, p.Files.Count); p.AddFile(p.BaseDirectory.Combine("Test.cs"), BuildAction.Compile); var solText = File.ReadAllLines(solFile); sol.Save(new NullProgressMonitor()); Assert.AreEqual(Util.GetXmlFileInfoset(p.FileName + ".saved"), Util.GetXmlFileInfoset(p.FileName)); Assert.AreEqual(solText, File.ReadAllLines(solFile)); }
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 MakefileSynchronization() { string solFile = Util.GetSampleProject("console-project-with-makefile", "ConsoleProject.sln"); Solution sol = (Solution)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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); refs.Add("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); refs.Add("System.Data, Version=2.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(new ProjectReference(ReferenceType.Gac, "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)); sol.Save(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 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 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 void NestedSolutions() { string solFile = Util.GetSampleProject("nested-solutions-mdp", "nested-solutions-mdp.mds"); WorkspaceItem item = Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); Assert.IsTrue(item is Solution); Solution sol = (Solution)item; BuildResult cr = item.Build(Util.GetMonitor(), (SolutionConfigurationSelector)"Debug"); Assert.IsNotNull(cr); Assert.AreEqual(0, cr.ErrorCount); Assert.AreEqual(0, cr.WarningCount); Assert.AreEqual(6, cr.BuildCount); 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"); sol.Save(Util.GetMonitor()); 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 LocalCopyDefault() { string solFile = Util.GetSampleProject("local-copy-package", "ConsoleProject.sln"); WorkspaceItem item = 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); sol.Save(new NullProgressMonitor()); sol.Build(new NullProgressMonitor(), "Debug"); string exeDebug = Platform.IsWindows ? ".pdb" : ".exe.mdb"; AssertOutputFiles(sol, "ConsoleProject", "Debug", new string[] { "ConsoleProject.exe", "ConsoleProject" + exeDebug, "System.Data.dll", "gtk-sharp.dll" }); string projectXml1 = Util.GetXmlFileInfoset(p.FileName.ParentDirectory.Combine("ConsoleProject.csproj.saved")); string projectXml2 = Util.GetXmlFileInfoset(p.FileName); Assert.AreEqual(projectXml1, projectXml2); }
public void TestConfigurationMerging() { string solFile = Util.GetSampleProject("test-configuration-merging", "TestConfigurationMerging.sln"); Solution sol = 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); CSharpCompilerParameters pars = conf.CompilationParameters as CSharpCompilerParameters; 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 as CSharpCompilerParameters; Assert.IsNotNull(pars); Assert.AreEqual("ReleaseMod", Path.GetFileName(conf.OutputDirectory)); Assert.AreEqual(3, pars.WarningLevel); pars.WarningLevel = 1; Assert.AreEqual(1, pars.WarningLevel); conf.DebugMode = true; sol.Save(Util.GetMonitor()); Assert.AreEqual(1, pars.WarningLevel); string savedFile = Path.Combine(p.BaseDirectory, "TestConfigurationMergingSaved.csproj"); Assert.AreEqual(Util.GetXmlFileInfoset(savedFile), Util.GetXmlFileInfoset(p.FileName)); }
public void SaveReferenceWithCondition() { string solFile = Util.GetSampleProject("console-project-conditional-reference", "ConsoleProject.sln"); Solution sol = Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile) as Solution; string proj = sol.GetAllProjects().First().FileName; string projectXml1 = Util.GetXmlFileInfoset(proj); sol.Save(new NullProgressMonitor()); string projectXml2 = Util.GetXmlFileInfoset(proj); Assert.AreEqual(projectXml1, projectXml2); }
public void ProjectWithCustomConfigPropertyGroupBug20554() { string solFile = Util.GetSampleProject("console-project-custom-configs", "ConsoleProject.sln"); Solution sol = Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile) as Solution; string proj = sol.GetAllProjects().First().FileName; string projectXml1 = Util.GetXmlFileInfoset(proj); sol.Save(new NullProgressMonitor()); string projectXml2 = Util.GetXmlFileInfoset(proj); Assert.AreEqual(projectXml1, projectXml2); }
public void BuildConsoleProject() { Solution sol = TestProjectsChecks.CreateConsoleSolution("console-project-msbuild"); sol.Save(Util.GetMonitor()); // Ensure the project is buildable var result = sol.Build(Util.GetMonitor(), "Debug"); Assert.AreEqual(0, result.ErrorCount, "#1"); // Ensure the project is still buildable with xbuild after a rename ProjectOptionsDialog.RenameItem(sol.GetAllProjects() [0], "Test"); result = sol.Build(Util.GetMonitor(), "Release"); Assert.AreEqual(0, result.ErrorCount, "#2"); }
public void UnloadProject() { string solFile = Util.GetSampleProject("console-with-libs", "console-with-libs.sln"); Solution sol = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); SolutionEntityItem p = sol.FindProjectByName("console-with-libs"); SolutionEntityItem lib1 = sol.FindProjectByName("library1"); SolutionEntityItem 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; p.ParentFolder.ReloadItem(Util.GetMonitor(), p); p = sol.GetAllSolutionItems <SolutionEntityItem> ().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; 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; sol.Save(Util.GetMonitor()); sol.Dispose(); sol = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile); lib1 = sol.GetAllSolutionItems <SolutionEntityItem> ().FirstOrDefault(it => it.Name == "library1"); Assert.IsNotNull(lib1); lib1.Enabled = true; lib1.ParentFolder.ReloadItem(Util.GetMonitor(), lib1); lib1 = sol.FindProjectByName("library1"); Assert.IsNotNull(lib1); Assert.IsTrue(sol.Configurations [0].BuildEnabledForItem(lib1)); }
public void SolutionBuildOrder() { string solFile = Util.GetSampleProject("solution-build-order", "ConsoleApplication3.sln"); Solution sol = Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile) as Solution; SolutionEntityItem p = sol.FindProjectByName("ConsoleApplication3"); SolutionEntityItem lib1 = sol.FindProjectByName("ClassLibrary1"); SolutionEntityItem 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); sol.Save(new NullProgressMonitor()); 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 = lib2.ParentFolder.ReloadItem(Util.GetMonitor(), lib2); Assert.AreNotEqual(lib2, lib2Reloaded); Assert.IsTrue(p.ItemDependencies.Contains(lib2Reloaded)); Assert.AreEqual(1, p.ItemDependencies.Count); }
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 AddNewImportWithConditionToProject() { Solution sol = TestProjectsChecks.CreateConsoleSolution("console-project-msbuild"); var project = sol.GetAllProjects().First() as DotNetProject; string condition = @"Exists('packages\Xamarin.Forms\build\Xamarin.Forms.targets')"; project.AddImportIfMissing(@"packages\Xamarin.Forms\build\Xamarin.Forms.targets", condition); sol.Save(Util.GetMonitor()); var doc = new XmlDocument(); doc.Load(project.FileName); var manager = new XmlNamespaceManager(doc.NameTable); manager.AddNamespace("ms", "http://schemas.microsoft.com/developer/msbuild/2003"); XmlElement import = (XmlElement)doc.SelectSingleNode(@"//ms:Import[@Project='packages\Xamarin.Forms\build\Xamarin.Forms.targets']", manager); Assert.AreEqual(condition, import.GetAttribute("Condition")); }
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 void SaveSharedProject() { Solution sol = TestProjectsChecks.CreateConsoleSolution("shared-project"); sol.ConvertToFormat(Util.FileFormatMSBuild12, true); sol.Save(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")); sp.Save(sol.ItemDirectory.Combine("Shared"), Util.GetMonitor()); sol.RootFolder.AddItem(sp); sol.Save(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 = new ProjectReference(sp); pc.References.Add(r); sol.Save(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")); sol.Save(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); sol.Save(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); sol.Save(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); }
public static void TestLoadSaveSolutionFolders(string fileFormat) { List <string> ids = new List <string> (); Solution sol = new Solution(); sol.ConvertToFormat(Services.ProjectService.FileFormats.GetFileFormat(fileFormat), true); string dir = Util.CreateTmpDir("solution-folders-" + fileFormat); sol.FileName = Path.Combine(dir, "TestSolutionFolders"); sol.Name = "TheSolution"; DotNetAssemblyProject p1 = new DotNetAssemblyProject("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); DotNetAssemblyProject p2 = new DotNetAssemblyProject("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); DotNetAssemblyProject p3 = new DotNetAssemblyProject("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); DotNetAssemblyProject p4 = new DotNetAssemblyProject("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); sol.Save(Util.GetMonitor()); Solution sol2 = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), sol.FileName); Assert.AreEqual(4, sol2.Items.Count); Assert.AreEqual(2, sol2.RootFolder.Items.Count); Assert.AreEqual(typeof(DotNetAssemblyProject), 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(DotNetAssemblyProject), 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(DotNetAssemblyProject), f2.Items [0].GetType()); Assert.AreEqual(typeof(DotNetAssemblyProject), 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"); }
// // internal ICollection<SD.SolutionSection> Sections { // get { return solution.GlobalSections; } // } internal void Save() { DispatchService.GuiSyncDispatch(() => { solution.Save(new NullProgressMonitor()); }); }