public async Task DotNetCoreProjectTemplateUsingBackslashesInPrimaryOutputPathsIsSupported()
        {
            var templatingService = new TemplatingService();

            string templateId = "MonoDevelop.Ide.Tests.TwoProjects.CSharp";
            string scanPath   = Util.GetSampleProjectPath("DotNetCoreTemplating");
            var    template   = MicrosoftTemplateEngineProjectTemplatingProvider.CreateTemplate(templateId, scanPath);

            string tempDirectory    = Util.CreateTmpDir("BackslashInPrimaryOutputTest");
            string projectDirectory = Path.Combine(tempDirectory, "BackslashInPrimaryOutputTestProject");

            Directory.CreateDirectory(projectDirectory);
            string library1FileToOpen = Path.Combine(projectDirectory, "Library1", "MyClass.cs");
            string library2FileToOpen = Path.Combine(projectDirectory, "Library2", "MyClass.cs");

            var result = await templatingService.ProcessTemplate(template, new NewProjectConfiguration()
            {
                CreateSolution = true,
                Location       = tempDirectory,
                SolutionName   = "BackslashInPrimaryOutputTest",
                ProjectName    = "BackslashInPrimaryOutputTestProject",
                CreateProjectDirectoryInsideSolutionDirectory = false,
            }, null);

            solution = result.WorkspaceItems.OfType <Solution> ().Single();

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

            Assert.AreEqual(2, solution.GetAllProjects().Count());
            Assert.IsNotNull(solution.FindProjectByName("Library1"));
            Assert.IsNotNull(solution.FindProjectByName("Library2"));
            Assert.AreEqual(2, result.Actions.Count());
            Assert.That(result.Actions, Contains.Item(library1FileToOpen));
            Assert.That(result.Actions, Contains.Item(library2FileToOpen));
        }
예제 #2
0
        async Task CreateAndBuild(
            SolutionTemplate template,
            NewProjectConfiguration config)
        {
            var result = await templatingService.ProcessTemplate(template, config, null);

            var solution = result.WorkspaceItems.FirstOrDefault() as Solution;
            await solution.SaveAsync(Util.GetMonitor());

            RunMSBuild($"/t:Restore {solution.FileName}");
            RunMSBuild($"/t:Build {solution.FileName}");
        }
        async Task CreateAndBuild(
            SolutionTemplate template,
            NewProjectConfiguration config)
        {
            var result = await templatingService.ProcessTemplate(template, config, null);

            solution = result.WorkspaceItems.FirstOrDefault() as Solution;
            await solution.SaveAsync(Util.GetMonitor());

            // RestoreDisableParallel prevents parallel restores which sometimes cause
            // the restore to fail on Mono.
            RunMSBuild($"/t:Restore /p:RestoreDisableParallel=true \"{solution.FileName}\"");
            RunMSBuild($"/t:Build \"{solution.FileName}\"");
        }
예제 #4
0
        public async Task <SolutionTemplate> CreateAndBuild()
        {
            var template = FindTemplate();
            var result   = await templatingService.ProcessTemplate(template, Config, null);

            Solution = result.WorkspaceItems.FirstOrDefault() as Solution;
            await Solution.SaveAsync(Util.GetMonitor());

            // RestoreDisableParallel prevents parallel restores which sometimes cause
            // the restore to fail on Mono.
            RunMSBuild($"/t:Restore /p:RestoreDisableParallel=true \"{Solution.FileName}\"");
            RunMSBuild($"/t:Build \"{Solution.FileName}\"");

            return(template);
        }
        public async Task DotNetCoreProjectTemplate_ExcludeFile(string exclude)
        {
            var templatingService = new TemplatingService();

            string templateId = "MonoDevelop.Ide.Tests.FileFormatExclude.CSharp";
            string scanPath   = Util.GetSampleProjectPath("FileFormatExclude");

            var    xmlFilePath = Path.Combine(scanPath, "test.xml");
            string expectedXml = "<root><child/></root>";

            File.WriteAllText(xmlFilePath, expectedXml);

            var template = MicrosoftTemplateEngineProjectTemplatingProvider.CreateTemplate(templateId, scanPath) as MicrosoftTemplateEngineSolutionTemplate;

            template.FileFormattingExclude = exclude;

            string tempDirectory = Util.CreateTmpDir("FileFormatExcludeTest");

            string projectDirectory = Path.Combine(tempDirectory, "FileFormatExcludeTestProject");

            Directory.CreateDirectory(projectDirectory);

            var result = await templatingService.ProcessTemplate(template, new NewProjectConfiguration()
            {
                CreateSolution = true,
                Location       = tempDirectory,
                SolutionName   = "FileFormatExcludeTest",
                ProjectName    = "FileFormatExcludeTestProject",
                CreateProjectDirectoryInsideSolutionDirectory = false,
            }, null);

            solution = result.WorkspaceItems.OfType <Solution> ().Single();

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

            xmlFilePath = Path.Combine(projectDirectory, "test.xml");
            string xml = File.ReadAllText(xmlFilePath);

            if (string.IsNullOrEmpty(exclude))
            {
                // Ensure formatting occurs if file is not excluded.
                Assert.AreNotEqual(expectedXml, xml);
            }
            else
            {
                Assert.AreEqual(expectedXml, xml);
            }
        }
예제 #6
0
        async Task <bool> CreateProject()
        {
            if (!projectConfiguration.IsValid())
            {
                MessageService.ShowError(projectConfiguration.GetErrorMessage());
                return(false);
            }

            if (ParentFolder != null && ParentFolder.ParentSolution.FindProjectByName(projectConfiguration.ProjectName) != null)
            {
                MessageService.ShowError(GettextCatalog.GetString("A Project with that name is already in your Project Space"));
                return(false);
            }

            if (ParentWorkspace != null && SolutionAlreadyExistsInParentWorkspace())
            {
                MessageService.ShowError(GettextCatalog.GetString("A solution with that filename is already in your workspace"));
                return(false);
            }

            SolutionTemplate template = GetTemplateForProcessing();

            if (ProjectNameIsLanguageKeyword(template.Language, projectConfiguration.ProjectName))
            {
                MessageService.ShowError(GettextCatalog.GetString("Illegal project name.\nName cannot contain a language keyword."));
                return(false);
            }

            ProcessedTemplateResult result = null;

            try {
                if (Directory.Exists(projectConfiguration.ProjectLocation))
                {
                    var question = GettextCatalog.GetString("Directory {0} already exists.\nDo you want to continue creating the project?", projectConfiguration.ProjectLocation);
                    var btn      = MessageService.AskQuestion(question, AlertButton.No, AlertButton.Yes);
                    if (btn != AlertButton.Yes)
                    {
                        return(false);
                    }
                }

                Directory.CreateDirectory(projectConfiguration.ProjectLocation);
            } catch (IOException) {
                MessageService.ShowError(GettextCatalog.GetString("Could not create directory {0}. File already exists.", projectConfiguration.ProjectLocation));
                return(false);
            } catch (UnauthorizedAccessException) {
                MessageService.ShowError(GettextCatalog.GetString("You do not have permission to create to {0}", projectConfiguration.ProjectLocation));
                return(false);
            }

            DisposeExistingNewItems();

            try {
                result = await TemplatingService.ProcessTemplate(template, projectConfiguration, ParentFolder);

                SetFirstBuildProperty(result.WorkspaceItems);
                if (!result.WorkspaceItems.Any())
                {
                    return(false);
                }
            } catch (UserException ex) {
                MessageService.ShowError(ex.Message, ex.Details);
                return(false);
            } catch (Exception ex) {
                MessageService.ShowError(GettextCatalog.GetString("The project could not be created"), ex);
                return(false);
            }
            processedTemplate = result;
            return(true);
        }
        public async Task Bug57840()
        {
            var templatingService            = new TemplatingService();
            var mutliplatformLibraryCategory = templatingService.GetProjectTemplateCategories().Single(c => c.Id == "multiplat")
                                               .Categories.Single(c => c.Id == "library")
                                               .Categories.Single(c => c.Id == "general");
            var pclTemplate      = mutliplatformLibraryCategory.Templates.Single(t => t.GroupId == "md-project-portable-library").GetTemplate("C#");
            var standardTemplate = mutliplatformLibraryCategory.Templates.Single(t => t.GroupId == "Microsoft.Common.Library").GetTemplate("C#");

            var tempDirectory = Util.CreateTmpDir("Bug57840Test");
            var result        = await templatingService.ProcessTemplate(pclTemplate, new Ide.Projects.NewProjectConfiguration()
            {
                CreateSolution = true,
                Location       = tempDirectory,
                SolutionName   = "Bug57840Test",
                ProjectName    = "Bug57840PclTestProject",
                CreateProjectDirectoryInsideSolutionDirectory = false
            }, null);

            solution = result.WorkspaceItems.OfType <Solution> ().Single();

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

            var project = solution.GetAllProjects().Single();

            project.Policies.Set <TextStylePolicy> (new TextStylePolicy(1, 1, 1, true, true, true, EolMarker.Mac), "text/x-csharp");

            var file = project.Files.Single(f => f.FilePath.FileName == "MyClass.cs").FilePath;
            var fileContentBeforeFormat = await TextFileUtility.ReadAllTextAsync(file);

            await FormatFile(project, file);

            var fileContentAfterFormat = await TextFileUtility.ReadAllTextAsync(file);

            Assert.AreNotEqual(fileContentBeforeFormat.Text, fileContentAfterFormat.Text);             //Make sure our weird formatting applied

            solution.Policies.Set <TextStylePolicy> (new TextStylePolicy(3, 3, 3, true, true, true, EolMarker.Mac), "text/x-csharp");

            var result2 = await templatingService.ProcessTemplate(standardTemplate, new Ide.Projects.NewProjectConfiguration()
            {
                CreateSolution = false,
                Location       = solution.BaseDirectory,
                ProjectName    = "Bug57840StandardTestProject",
                CreateProjectDirectoryInsideSolutionDirectory = false
            }, solution.RootFolder);

            var standardProject = result2.WorkspaceItems.OfType <DotNetProject> ().Single();

            solution.RootFolder.AddItem(standardProject);
            await solution.SaveAsync(Util.GetMonitor());

            var fileContentAfterSecondProject = await TextFileUtility.ReadAllTextAsync(file);

            Assert.AreEqual(fileContentAfterSecondProject.Text, fileContentAfterFormat.Text);             //Make sure our weird formatting is preserved
            var class1File = standardProject.Files.Single(f => f.FilePath.FileName == "Class1.cs").FilePath;
            var fileContentAfterCreation = await TextFileUtility.ReadAllTextAsync(class1File);

            standardProject.Policies.Set <TextStylePolicy> (new TextStylePolicy(3, 3, 3, true, true, true, EolMarker.Mac), "text/x-csharp");
            await FormatFile(standardProject, class1File);

            standardProject.Dispose();
            var fileContentAfterForceFormatting = await TextFileUtility.ReadAllTextAsync(class1File);

            Assert.AreEqual(fileContentAfterForceFormatting.Text, fileContentAfterCreation.Text,
                            "We expect them to be same because we placed same formatting policy on solution before creataion as after creation on project when we manually formatted.");
        }