AddDirectory() публичный Метод

Adds a directory to the project.
The directory is created if it doesn't exist
public AddDirectory ( string relativePath ) : ProjectFile
relativePath string /// Relative path of the directory. ///
Результат ProjectFile
Пример #1
0
        public async Task GetParentFileTest(string inputFile, string expectedParentFile)
        {
            string   solFile = Util.GetSampleProject("console-project", "ConsoleProject.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

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

            string inputFileDestination  = Path.Combine(dir, "FileNesting", inputFile);
            string parentFileDestination = Path.Combine(dir, "FileNesting", expectedParentFile);

            p.AddDirectory("FileNesting");
            p.AddFile(inputFileDestination);
            p.AddFile(parentFileDestination);

            string parentFile = FileNestingService.GetParentFile(p, inputFileDestination);

            Assert.That(parentFile, Is.EqualTo(parentFileDestination), $"Was expecting parent file {parentFileDestination} for {inputFileDestination} but got {parentFile}");

            // Now check we get nothing when parent file doesn't exist
            p.Files.Remove(parentFileDestination);
            parentFile = FileNestingService.GetParentFile(p, inputFileDestination);
            Assert.Null(parentFile, $"Was expecting no parent file for {inputFileDestination} but got {parentFile}");

            sol.Dispose();
        }
Пример #2
0
        public override bool AddToProject(SolutionItem policyParent, Project project,
		                                   string language, string directory, string name)
        {
            bool addedSomething = false;
            directory = Path.Combine (directory, dirName);
            if (templates.Count == 0) {
                string relPath = FileService.AbsoluteToRelativePath (project.BaseDirectory, directory);
                if (project.AddDirectory (relPath) != null)
                    addedSomething = true;
            }

            foreach (FileDescriptionTemplate t in templates)
                addedSomething |= t.AddToProject (policyParent, project, language, directory, name);

            return addedSomething;
        }
        string GetFileLocationForProject(string fileName, Project project)
        {
            //project not null, copy file to resources folder, warn on overwrite
            string resFolder = System.IO.Path.Combine (project.BaseDirectory.FullPath, "Resources");
            string newFile = System.IO.Path.Combine (resFolder, fileName);

            if (Directory.Exists (resFolder)) {
                if (File.Exists (newFile)) {
                    bool overwrite = MessageService.Confirm (GettextCatalog.GetString (
                        "Overwrite existing file?"),
                                                             GettextCatalog.GetString (
                        "A file named {0} already exists in the Resources folder.",
                        fileName),
                                                             AlertButton.OverwriteFile);
                    if (!overwrite)
                        return null; // cancelled
                }
            } else {
                Directory.CreateDirectory (resFolder);
                project.AddDirectory ("Resources");
                project.Save (null); //FIXME: ok to save users project here? did this with generate resources wizard too?
            }

            return newFile;
        }