没有返回对通过 AddFromTemplate() 创建的项目项的引用
在成功创建表单的 Visual Studio 加载项中,但没有提供对 EnvDTE 的 prjItem 实例的引用。
下面是将表单添加到项目中的代码片段:
string templatePath = solution.GetProjectItemTemplate("Form.zip", "csproj");
ProjectItem prjItem = project.ProjectItems.AddFromTemplate(templatePath, "myForm.cs");
Obs.: 'solution' is an EnvDTE80.Solution2 object。
当然,我可以通过其他方式获取引用,例如 proj.ProjectItems.Item([index]) (执行循环并检查名称),但这不是我想要的方式,而且我需要此引用向该窗体添加控件。
我做错了什么吗?
In a Visual Studio Add-In that successfully creates a form, but gives me no reference back to the EnvDTE's prjItem instance.
Here's the piece of code that adds the form to the project:
string templatePath = solution.GetProjectItemTemplate("Form.zip", "csproj");
ProjectItem prjItem = project.ProjectItems.AddFromTemplate(templatePath, "myForm.cs");
Obs.: 'solution' is an EnvDTE80.Solution2 object.
Of cource I can get the reference by other ways, like proj.ProjectItems.Item([index]) (doing a loop and checking for names), but that's not how I want to do it, and I need this reference in orther to add controls to this form.
Am I doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
刚刚在MSDN上找到一条评论:
http://msdn。 microsoft.com/en-us/library/envdte.projectitems.addfromtemplate(v=vs.80).aspx#1
Just found a comment on MSDN:
http://msdn.microsoft.com/en-us/library/envdte.projectitems.addfromtemplate(v=vs.80).aspx#1