如何使用 Visual Studio Automation 设置活动项目?
语境: 我正在使用 Visual Studio 2010 构建一个外接程序。其中一项操作是确保相关项目上存在界面。如果接口不存在,则必须创建它。
检查接口是否存在,不是问题。创建界面是。 我想使用 AddNewItem() 创建界面,但这只能在当前活动项目中正常工作。
代码:
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" );
}
有人有想法吗? PS 需要明确的是:该加载项是从同一解决方案中的不同项目调用的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你会想使用 Project.ProjectItems.AddFromTemplate() 代替。轻松获得正确的项目参考。
I think you'll want to use Project.ProjectItems.AddFromTemplate() instead. No trouble getting the right Project reference.