简体   繁体   English

在Visual Studio中查找引用

[英]Finding references in Visual Studio

I'm using Visual Studio and COM with C# for the first time and there's something I don't quite understand about the 'references'. 我是第一次将Visual Studio和COM与C#结合使用,对于“引用”我有些不太了解。 How do you know what to reference with a given 'using something.something'? 您如何知道给定的“使用某物”引用什么? The .Net references seem fairly simple, but COM is less obvious. .Net引用似乎很简单,但是COM不太明显。 I'm running Visual Studio 2005 and have the latest VSTO installed, but for the life of me, I can't figure out what I need to reference to satisfy: 我正在运行Visual Studio 2005并安装了最新的VSTO,但是对于我一生来说,我无法弄清楚需要满足哪些要求:

using Microsoft.VisualStudio.Tools.Applications.Runtime; 使用Microsoft.VisualStudio.Tools.Applications.Runtime;

There are a few Microsoft.VisualStudio things in the .Net tab, but none that continue with .Tools or anything like it. .Net选项卡中有一些Microsoft.VisualStudio内容,但没有任何以.Tools或类似名称继续的内容。 I feel like I'm missing a key concept here. 我觉得我在这里缺少一个关键概念。

There are two issues here - 这里有两个问题-

First, a reference doesn't necessarily correspond to a namespace. 首先,引用不一定对应于名称空间。 A single reference can contain multiple namespaces, and a single namespace can be shared by multiple assemblies which would need to be referenced. 单个引用可以包含多个名称空间,并且单个名称空间可以由需要引用的多个程序集共享。 Needing to include a reference allows you to use specific types, not entire namespaces. 需要包括一个引用,您可以使用特定类型,而不是整个名称空间。

Second, this is something you'll need to know in advance. 其次,这是您需要事先知道的。 If you're using Microsoft's classes, such as the ones in the namespace you listed, MSDN can be a great help. 如果您使用的是Microsoft的类,例如列出的名称空间中的类,则MSDN可能会提供很大的帮助。

For example, take Microsoft.VisualStudio.Tools.Applications.Runtime.ServerDocument 例如,以Microsoft.VisualStudio.Tools.Applications.Runtime.ServerDocument

If you look at the MSDN page for this class (in that namespace), near the top it includes: 如果您查看该类的MSDN页面(在该名称空间中),则在顶部附近包括:

Namespace: Microsoft.VisualStudio.Tools.Applications.Runtime 命名空间:Microsoft.VisualStudio.Tools.Applications.Runtime

Assembly: Microsoft.VisualStudio.Tools.Applications.Runtime (in microsoft.visualstudio.tools.applications.runtime.dll) 程序集:Microsoft.VisualStudio.Tools.Applications.Runtime(在microsoft.visualstudio.tools.applications.runtime.dll中)

This specifically tells you which assembly is required. 这专门告诉您需要哪个程序集。

That reference is part of the Visual Studio SDK. 该参考是Visual Studio SDK的一部分。 I am currently using VS 2008, but the assemblies should be the same for VS 2005. The link for the SDK is here . 我目前正在使用VS 2008,但是VS 2005的程序集应该相同。SDK的链接在此处

Going the other way is pretty easy. 换种方式很容易。 If you're given a reference, you can open that reference in the object browser to see what namespaces it contains, and from that, determine what usings to add. 如果获得了引用,则可以在对象浏览器中打开该引用以查看其包含的名称空间,然后从中确定要添加的用途。 Its not trivial to determine what to reference for a given using, as there's no guarantee that there exists exactly one DLL for each namespace. 确定给定使用引用什么并不是易事,因为不能保证每个命名空间都存在一个DLL。 How is it that you arrived at a 你是怎么到达的

using Microsoft.VisualStudio.Tools.Applications.Runtime;

Without knowing what to reference? 不知道参考什么? If its a code sample somewhere, they ought to mention what the external references and dependencies of the project are. 如果它是某个地方的代码示例,则应提及项目的外部引用和依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM