Finding references in Visual Studio

房东的猫 提交于 2020-01-04 15:16:26

问题


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'. How do you know what to reference with a given 'using something.something'? The .Net references seem fairly simple, but COM is less obvious. 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:

using 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. I feel like I'm missing a key concept here.


回答1:


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.

For example, take Microsoft.VisualStudio.Tools.Applications.Runtime.ServerDocument

If you look at the MSDN page for this class (in that namespace), near the top it includes:

Namespace: Microsoft.VisualStudio.Tools.Applications.Runtime

Assembly: Microsoft.VisualStudio.Tools.Applications.Runtime (in microsoft.visualstudio.tools.applications.runtime.dll)

This specifically tells you which assembly is required.




回答2:


That reference is part of the 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.




回答3:


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. 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.



来源:https://stackoverflow.com/questions/858877/finding-references-in-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!