简体   繁体   中英

Can't find “resolve” in context menu of Visual Studio 2010 Ultimate

As in subject I can't find "resolve" in context menu of Visual Studio 2010 Ultimate. I have seen it in my teacher computer in the internet but I can't find it in the context menu, look at screen. How to get it?

在此输入图像描述

In order for the Resolve menu to show up, you must be positioned over a keyword that VS believes it's able to resolve. If you've mistyped a keyword or don't have an assembly referenced, VS won't be able to resolve anything.

If you think about this a bit, you could type any legal keyword into your code, and there could be an assembly somewhere that might contain that class, and your keyword would then be resolve-able provided you referenced that assembly. Since this is not only impossible for VS to know and would also require project changes in order to reference that assembly, it makes some sense for this to be out of scope with respect to the "Resolve" dialog.

If you'd like to see this in action, just create a line of code with a missing class in it:

namespace ResolveTest
{
    class Program
    {
        static void Main(string[] args)
        {
            OtherClass.OtherMethod();
        }
    }
}

Notice that OtherClass is flagged because it cannot be found. If you right-click on it, there's no Resolve.

Now, add in a class definition (in another namespace):

namespace NotInTheSameSpace
{
    public class OtherClass
    {
        public static void OtherMethod()
        {

        }
    }
}

Typically, this will be in another file or another assembly altogether, but for demo purposes, you can drop this right below your existing code. You should now see the "Resolve" menu show up in Main().

The other thing you're seeing here, I believe, is that when the "Resolve" dialog doesn't have anything to resolve, it's missing from that context menu, rather than being disabled but visible. This might seem a bit confusing, but it's really an effort to keep the context menu relevant to your current context.

Type in File.Open("Test.txt"); Then click on File en see if you can find resolve then. Should be able to resolve it to System.IO.File .

And for the record, you opened the context menu on a function. A function can't be resolved only types. So you could instead just type: Debug then open the context menu and resolve it to System.Diagnostics . Then you could call the WriteLine function.

So besides your question, you need System.Diagnostics.Debug.WriteLine(object) instead of System.Diagnostics.Debugger.WriteLine which doesn't exist.

A long shoot - Maybe you write the wrong name of the function. So VS just can't resolve it for you?

If not, the resolve only adding Using statement to the beginning of the file in order to resolve the issue. For that you project must have the correct reference to the library which have the function. you can use the "Solution Explorer" (the right menu in your attached picture) and under the project you have the tab of "References" make sure it's there and if not right-click and "Add Reference..."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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