Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        public async Task OnConfigureTargetEvaluationContext()
        {
            var node = new CustomItemNode <EvalContextCreationTestExtension> ();

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

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

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

                var cs = new SolutionConfigurationSelector("Debug");

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

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

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

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

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

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

                sol.Dispose();
            } finally {
                WorkspaceObject.UnregisterCustomExtension(node);
            }
        }
Ejemplo n.º 4
0
        public async Task Resources()
        {
            string   solFile = Util.GetSampleProject("resources-tester", "ResourcesTester.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            CheckResourcesSolution(sol);

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

            Assert.AreEqual(0, res.ErrorCount);
            Assert.AreEqual(0, res.WarningCount);
            Assert.AreEqual(1, res.BuildCount);

            string spath = Util.Combine(sol.BaseDirectory, "ResourcesTester", "bin", "Debug", "ca", "ResourcesTesterApp.resources.dll");

            Assert.IsTrue(File.Exists(spath), "Satellite assembly not generated");

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

            Assert.IsFalse(File.Exists(spath), "Satellite assembly not removed");

            // msbuild doesn't delete this directory
            // Assert.IsFalse (Directory.Exists (Path.GetDirectoryName (spath)), "Satellite assembly directory not removed");

            sol.Dispose();
        }
Ejemplo n.º 5
0
        public async Task SkipBuildingUnmodifiedProjects(bool enabled, int expectedSuccessful, int expectedUpToDate)
        {
            var settingBefore = Runtime.Preferences.SkipBuildingUnmodifiedProjects.Value;

            try {
                Runtime.Preferences.SkipBuildingUnmodifiedProjects.Value = enabled;
                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");
                var buildResult = await lib2.Build(Util.GetMonitor(), sol.Configurations [0].Selector, true);

                Assert.AreEqual(2, buildResult.BuildCount);
                buildResult = await sol.Build(Util.GetMonitor(), sol.Configurations [0].Selector);

                Assert.AreEqual(expectedSuccessful + expectedUpToDate, buildResult.BuildCount);

                FileService.NotifyFileChanged(p.Files.Single(f => Path.GetFileName(f.Name) == "Program.cs").FilePath);

                buildResult = await p.Build(Util.GetMonitor(), sol.Configurations [0].Selector, true);

                Assert.AreEqual(expectedSuccessful, buildResult.SuccessfulBuildCount);
                Assert.AreEqual(expectedUpToDate, buildResult.UpToDateBuildCount);

                sol.Dispose();
            } finally {
                Runtime.Preferences.SkipBuildingUnmodifiedProjects.Value = settingBefore;
            }
        }
Ejemplo n.º 6
0
        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");
        }
Ejemplo n.º 7
0
        async Task CheckSolutionBuildClean(Solution sol, string configuration)
        {
            SolutionConfigurationSelector config = (SolutionConfigurationSelector)configuration;
            string        tag  = "CheckSolutionBuildClean config=" + configuration;
            DotNetProject lib1 = (DotNetProject)sol.FindProjectByName("Lib1");
            DotNetProject lib2 = (DotNetProject)sol.FindProjectByName("Lib2");
            DotNetProject lib3 = (DotNetProject)sol.FindProjectByName("Lib3");
            DotNetProject lib4 = (DotNetProject)sol.FindProjectByName("Lib4");

            Assert.IsFalse(File.Exists(lib1.GetOutputFileName(config)), tag);
            Assert.IsFalse(File.Exists(lib2.GetOutputFileName(config)), tag);
            Assert.IsFalse(File.Exists(lib3.GetOutputFileName(config)), tag);
            Assert.IsFalse(File.Exists(lib4.GetOutputFileName(config)), tag);

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

            Assert.AreEqual(0, res.WarningCount, tag);
            Assert.AreEqual(0, res.ErrorCount, tag);

            Assert.IsTrue(File.Exists(lib1.GetOutputFileName(config)), tag);
            Assert.IsTrue(File.Exists(lib2.GetOutputFileName(config)), tag);
            Assert.IsTrue(File.Exists(lib3.GetOutputFileName(config)), tag);
            Assert.IsTrue(File.Exists(lib4.GetOutputFileName(config)), tag);

            await sol.Clean(Util.GetMonitor(), config);

            Assert.IsFalse(File.Exists(lib1.GetOutputFileName(config)), tag);
            Assert.IsFalse(File.Exists(lib2.GetOutputFileName(config)), tag);
            Assert.IsFalse(File.Exists(lib3.GetOutputFileName(config)), tag);
            Assert.IsFalse(File.Exists(lib4.GetOutputFileName(config)), tag);
        }
Ejemplo n.º 8
0
        public async Task BasicEvents()
        {
            string   solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");
            Solution item    = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            var myLogger = new MSBuildLogger();
            TargetEvaluationContext ctx = new TargetEvaluationContext();

            ctx.Loggers.Add(myLogger);
            myLogger.EnabledEvents = MSBuildEvent.BuildStarted | MSBuildEvent.BuildFinished | MSBuildEvent.TargetStarted;

            int started = 0, finished = 0, targetStarted = 0;

            myLogger.EventRaised += (sender, e) => {
                switch (e.Event)
                {
                case MSBuildEvent.BuildStarted: started++; break;

                case MSBuildEvent.BuildFinished: finished++; break;

                case MSBuildEvent.TargetStarted: targetStarted++; break;

                default: throw new InvalidOperationException("Unexpected event: " + e.Event);
                }
            };
            await item.Build(Util.GetMonitor(), "Debug", ctx);

            Assert.AreEqual(1, started);
            Assert.AreEqual(1, finished);
            Assert.IsTrue(targetStarted > 0);
        }
Ejemplo n.º 9
0
        public async Task FastCheckNeedsBuildWithContext()
        {
            string   solFile = Util.GetSampleProject("fast-build-test", "FastBuildTest.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

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

            var cs = new SolutionConfigurationSelector("Debug");

            var ctx = new TargetEvaluationContext();

            ctx.GlobalProperties.SetValue("Foo", "Bar");

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

            ctx = new TargetEvaluationContext();
            ctx.GlobalProperties.SetValue("Foo", "Bar");

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

            Assert.IsFalse(res.HasErrors);

            ctx = new TargetEvaluationContext();
            ctx.GlobalProperties.SetValue("Foo", "Bar");
            Assert.IsFalse(app.FastCheckNeedsBuild(cs, ctx));

            ctx = new TargetEvaluationContext();
            ctx.GlobalProperties.SetValue("Foo", "Modified");
            Assert.IsTrue(app.FastCheckNeedsBuild(cs, ctx));

            sol.Dispose();
        }
Ejemplo n.º 10
0
        static void AssertCleanBuild(Solution sol, string configuration)
        {
            BuildResult cr = sol.Build(Util.GetMonitor(), configuration);

            Assert.IsNotNull(cr);
            Assert.AreEqual(0, cr.ErrorCount);
            Assert.AreEqual(0, cr.WarningCount);
        }
Ejemplo n.º 11
0
        public async Task BuildPortableLibrary()
        {
            string   solFile = Util.GetSampleProject("portable-library", "portable-library.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

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

            Assert.AreEqual(0, res.Errors.Count);
        }
Ejemplo n.º 12
0
        public async Task BuildPortableLibrary()
        {
            string   solFile = Util.GetSampleProject("portable-library", "portable-library.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

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

            Assert.IsNull(res.Errors.FirstOrDefault()?.ToString());
        }
Ejemplo n.º 13
0
        static async Task AssertCleanBuild(Solution sol, string configuration)
        {
            BuildResult cr = await sol.Build(Util.GetMonitor(), configuration);

            Assert.IsNotNull(cr);
            Assert.AreEqual(0, cr.ErrorCount);

            // Warning check disabled due to bug #15121
            // Assert.AreEqual (0, cr.WarningCount);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 15
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();
        }
Ejemplo n.º 16
0
        public async Task NoLog()
        {
            string   solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");
            Solution item    = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            TargetEvaluationContext ctx = new TargetEvaluationContext();

            ctx.LogVerbosity = MSBuildVerbosity.Quiet;
            var mon = new StringMonitor();
            await item.Build(mon, "Debug", ctx);

            Assert.AreEqual(string.Empty, mon.GetLogText());
        }
Ejemplo n.º 17
0
        public async Task ProjectReferencingDisabledProject_SolutionBuildWorks()
        {
            // If a project references another project that is disabled for the solution configuration it should
            // not be built when building the solution as a whole.

            // Build the solution. It should work.
            string   solFile = Util.GetSampleProject("invalid-reference-resolution", "InvalidReferenceResolution.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

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

            Assert.AreEqual(0, res.ErrorCount);
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        public async Task AllEvents()
        {
            string   solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");
            Solution item    = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            var myLogger = new MSBuildLogger();
            TargetEvaluationContext ctx = new TargetEvaluationContext();

            ctx.Loggers.Add(myLogger);
            myLogger.EnabledEvents = MSBuildEvent.All;

            int buildStarted = 0, buildFinished = 0, targetStarted = 0, targetFinished = 0, projectStarted = 0,
                projectFinished = 0, taskStarted = 0, taskFinished = 0;

            myLogger.EventRaised += (sender, e) => {
                switch (e.Event)
                {
                case MSBuildEvent.BuildStarted: buildStarted++; break;

                case MSBuildEvent.BuildFinished: buildFinished++; break;

                case MSBuildEvent.TargetStarted: targetStarted++; break;

                case MSBuildEvent.TargetFinished: targetFinished++; break;

                case MSBuildEvent.ProjectStarted: projectStarted++; break;

                case MSBuildEvent.ProjectFinished: projectFinished++; break;

                case MSBuildEvent.TaskStarted: taskStarted++; break;

                case MSBuildEvent.TaskFinished: taskFinished++; break;
                }
            };
            var mon = new StringMonitor();
            await item.Build(mon, "Debug", ctx);

            Assert.AreEqual(1, buildStarted);
            Assert.AreEqual(1, buildFinished);
            Assert.AreEqual(1, projectStarted);
            Assert.AreEqual(1, projectFinished);
            Assert.AreEqual(taskStarted, taskFinished);
            Assert.AreEqual(targetStarted, targetFinished);
            Assert.AreNotEqual(string.Empty, mon.GetLogText());

            item.Dispose();
        }
Ejemplo n.º 20
0
        public async Task NoEvents()
        {
            string   solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");
            Solution item    = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            var myLogger = new MSBuildLogger();
            TargetEvaluationContext ctx = new TargetEvaluationContext();

            ctx.Loggers.Add(myLogger);
            myLogger.EnabledEvents = MSBuildEvent.None;

            int events = 0;

            myLogger.EventRaised += (sender, e) => events++;
            await item.Build(Util.GetMonitor(), "Debug", ctx);

            Assert.AreEqual(0, events);
        }
Ejemplo n.º 21
0
        public async Task FirstBuildFlagRemovedAfterBuild()
        {
            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.Build(Util.GetMonitor(), "Debug");

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

            sol.Dispose();
        }
Ejemplo n.º 22
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();
        }
Ejemplo n.º 23
0
        public async Task FastBuildCheckWithLibrary()
        {
            string   solFile = Util.GetSampleProject("fast-build-test", "FastBuildTest.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

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

            var cs = new SolutionConfigurationSelector("Debug");

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

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

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

            var myClass = sol.ItemDirectory.Combine("MyClass.cs");

            File.WriteAllText(myClass, "public class MyClass { public const string Message = \"Bye\" ; }");
            FileService.NotifyFileChanged(myClass);

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

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

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

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

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

            sol.Dispose();
        }