NiKiZh

  • RSS

VSX: Solution Folders

Recently I’ve been working on few extensions for Visual Studio 2010. In a series of post I’ll share different snippets and techniques that I’ve learned.

In this post, I’ll show you how to create, and how to find an existing Solution folder.

First we need a reference to a DTE2 object (http://bit.ly/szlrOt) and then to a Solution2 object.

DTE2 dte2 = ...; // Get a reference to DTE2 object.

Solution2 solution = (Solution2)dte2.Solution;

Then to add the folder, just invoke the AddSolutionFolder method and pass the name of the folder:

Project projectItem = solution.AddSolutionFolder("MyNewSolutionFolder");

SolutionFolder solutionFolder = (SolutionFolder)(projectItem.Object);

There is trick, though. If a folder with the same name already exists an exception will be thrown. Here is a way to find an existing Solution folder:

SolutionFolder foundSolutionFolder = null;
string folderName = "MyNewSolutionFolder";

foreach (Project project in solution.Projects)
{
	if (project.Kind == ProjectKinds.vsProjectKindSolutionFolder)
	{
		if (string.Compare(project.Name, folderName, StringComparison.CurrentCultureIgnoreCase) == 0)
		{
			foundSolutionFolder = (SolutionFolder)project.Object;
			break;
		}
	}
}

I hope that you will find this information useful.

’till next time.

    • VSX
  • 28 days ago
  • {lang:Permalink}
  • 171 days ago
  • {lang:Permalink}
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

~Martin Golding

  • 207 days ago
  • {lang:Permalink}

by Sehsucht™

  • 208 days ago
  • {lang:Permalink}

Hello world!

Welcome to my website. It’s been a long time since I bought this domain and since then I’ve tried several times to start a blog, but unfortunately I was not writing consistently. This time I intend to take time off for blogging, because I think it will be useful for me.

I’ll write mostly about software development, testing, .net, silverlight, wpf and technical stuff that’s interesting to me. However, this doesn’t mean that I’m not going to write about other interesting (and not so interesting) topics.

I think this is enough for a “Hello World!” post, so thanks for reading and keep checking for new posts and articles ツ

  • 211 days ago
  • {lang:Permalink}

About

My name is Nikolay Zhekov, and this is my blog. I'm passionate about software development. It is my hobby and profession.