How to add a folder called "Foo" to a project?

            IProjectFolder folder = project.GetOrCreateProjectFolder(FileSystemPath.Parse("Foo"));
 
I'm unable to add a new folder called "Foo" to a IProject of an existing project. The returned value is always null.
2 comments
Comment actions Permalink

I think the path you pass in has to be fully qualified, not relative. Looking at the implementation of GetOrCreateProjectFolder, it first checks that path is defined under the location of the project/project folder you're calling the extension method on. This is to ensure that you don't try to create a project item that lives outside of the project hierarchy. You can easily handle this with something like:

var location = project.Location.Combine("Foo");
var folder = project.GetOrCreateProjectFolder(location);

 

0
Comment actions Permalink

Thanks Matt, that was the trick.

0

Please sign in to leave a comment.