简体   繁体   English

Intellisense和类库的问题

[英]Issues with Intellisense and class library

I am using Visual Studio 2013. I am trying to start unit testing by using this tutorial . 我正在使用Visual Studio 2013.我正在尝试使用本教程开始单元测试。

I have added a class library and a reference to MVC. 我添加了一个类库和对MVC的引用。 However, the Intellisense/Autocompletion is not working properly within my class library. 但是,Intellisense / Autocompletion在我的类库中无法正常工作。 Currently, this is all the code I have in my test class: 目前,这是我在测试类中的所有代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NUnit.Framework;
using System.Web.Mvc;
using System.Web;
using Application_Portal;
using Application_Portal.Controllers;

namespace ApplicationPortalTests
{
    [TestFixture]
    public class HomeControllerTest
    {
        HomeController home = new HomeController();
    }
}

The Intellisense does not seem to recognize the home variable (no suggested properties, etc.) Typing home.Index() gives the following error: Intellisense似乎没有识别home变量(没有建议的属性等)。键入home.Index()会出现以下错误:

ApplicationPortalTests.HomeControllerTest.home' is a 'field' but is used like a 'type'  

Furthermore, it does not even seem to recognize "var" (as in var result = ...). 此外,它似乎甚至没有识别“var”(如var result = ...)。 Instead, when I type var and hit space, it autocompletes it as EnvironmentVariableTarget. 相反,当我输入var并命中空格时,它会将其自动填充为EnvironmentVariableTarget。

I have tried cleaning and rebuilding the project, and closing and reopening Visual Studio, but with no success. 我已经尝试过清理和重建项目,关闭并重新打开Visual Studio,但没有成功。

What might the issue be? 问题可能是什么? I appreciate any advice. 我很感激任何建议。

You have declared your variable inside the class. 您已在类中声明了您的变量。 If you want to use this variable, it must be within the context of a member. 如果要使用此变量,则它必须位于成员的上下文中。 For instance: 例如:

[Test]
public void test_my_index_page()
{
     var result = home.index();
}

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

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