开发者

How to set active project using visual studio automation?

Context: I am building an Add-in using visual studio 2010. One of the actions is to ensure an Interface exists on a related project. If the interface does not exist, it must be created.

Checking if the interface exists, it not the problem. Creating the interface is. I would like to create the interface using AddNewItem(), but this will only work properly on the current active project.

code:

ProjectItem item = VsProject.ProjectItems.Cast< ProjectItem >( ).FirstOrDefault( p =>开发者_如何转开发 p.Name == interfaceName );
if ( item == null )
{
   item = VsProject.ProjectItems.DTE.ItemOperations.AddNewItem( @"Visual C# Items\Code\Interface", interfaceName+".cs" );
}

Has anybody an idea? P.S. To be clear: the Add-in is called from a different project in the same solution.


I think you'll want to use Project.ProjectItems.AddFromTemplate() instead. No trouble getting the right Project reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜