开发者

How to set active project using visual studio automation?

开发者 https://www.devze.com 2023-01-24 05:26 出处:网络
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.

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

精彩评论

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