为什么 EnvDTE.ProjectItem.FileCodeModel = Nothing?

发布于 2024-09-15 19:24:35 字数 367 浏览 1 评论 0原文

我编写了一个 VMacro(在 VS2010 中),它解析解决方案并向 cpp 文件添加 try 和 catch 语句。到目前为止一直运行良好。我不得不重新格式化我的电脑并重新安装 VS2010,现在它崩溃了。这是宏的一个片段。

Sub Foo(ByVal file As EnvDTE.ProjectItem)
    Dim fileCM As EnvDTE.FileCodeModel
    fileCM = file.FileCodeModel
End Sub

我已检查该文件是否是有效对象,它确实指向 cpp 文件。但由于某种原因 file.FileCodeModel = Nothing。为什么 FileCodeModel 会什么都没有?

I wrote a VSMacro (in VS2010) that parses a solution and adds try and catch statements to cpp files. It's been working fine up until now. I had to reformat my pc and reinstall VS2010 and now it crashes. Here's a snippet from the macro.

Sub Foo(ByVal file As EnvDTE.ProjectItem)
    Dim fileCM As EnvDTE.FileCodeModel
    fileCM = file.FileCodeModel
End Sub

I've checked to see if that file is a valid object, and it does point to a cpp file. But for some reason file.FileCodeModel = Nothing. Why would FileCodeModel be Nothing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独自唱情﹋歌 2024-09-22 19:24:35

在 Visual Studio 中的多种情况下,ProjectItem 不会返回 FileCodeModel 对象。例如,如果 ProjectItem 指向解决方案资源管理器中的文件夹或非代码文件项。

您能否验证 ProjectItem 在这种情况下代表什么?特别

  • 是它指向一个文件吗?
  • 这是什么类型的项目(Web、控制台应用程序等)?

There are several scenarios in Visual Studio where a ProjectItem will not return a FileCodeModel object. For example if the ProjectItem points to a folder or a non-code file item in solution explorer.

Can you verify what the ProjectItem represents in this scenario. In particular

  • Is it pointing to a file?
  • What type of project is this in (Web, console app, etc ...)?
め七分饶幸 2024-09-22 19:24:35

通常,当项目无法编译时会发生这种情况。您需要首先尝试构建解决方案。

Usually, it happens when the project is not compilable. You need to try to build the solution first.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文