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? PS 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.