【问题标题】:Resharper mark red using statement to use class library in asp.net coreResharper 标记红色 using 语句在 asp.net core 中使用类库
【发布时间】:2016-10-29 10:36:36
【问题描述】:

我创建了类库,创建了Web Application项目,然后在Web Application项目as explained here中添加了对类库的引用,但不能为其添加“使用”。 (customer.cs 的命名空间也是“CDemoLib”) (当我添加“使用 CDemoLib;”时,我得到“无法解析符号 CDemoLib”

customer.cs的代码是

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CDemoLib
{
 public class Customer
 {
    private int _age;
    private string _name;

    public Customer()
    {
        Age = 0;
        Name = "Not available";
    }

    public int Age
    {
        get { return _age; }
        set { _age = value; }
    }
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
  }
}

【问题讨论】:

  • 那么Customer.cs 中声明了什么命名空间,这似乎是CDemoLib 中唯一的文件?使用指令是关于命名空间,而不是程序集。
  • 课程是公开的吗?请向我们展示代码,而不是我们必须要求提供每一点信息。
  • 不,看起来应该没问题。并且您能够毫无问题地添加参考?如果你扩大参考,你会看到什么?
  • 那么究竟是什么报错呢?您是否尝试过禁用 Resharper 等插件?
  • 老实说,我对它所不理解的细节了解得不够多,无法得出一个明智的答案。也许它不知道 .NET Core 或您正在使用的版本。

标签: c# reference asp.net-core using class-library


【解决方案1】:

好吧,using 不会添加对 程序集 的引用,而是添加对程序集中声明的 namespaces 的引用。程序集中声明的命名空间可能与程序集文件名有很大不同。

双击解决方案资源管理器中的引用(屏幕截图中的右箭头)以打开“对象目录”。您将能够在那里看到命名空间。

【讨论】:

  • customer.cs的命名空间也是“CDemoLib”
【解决方案2】:

正如@Jon Skeet 提供的那样——它看起来像是一个 Resharper 问题。它可以编译,如果我暂停 Resharper,它会修复...

你可以下载new resharper来解决这个问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多