【问题标题】:dotnet core 2.0 ProjectReference errordotnet core 2.0 ProjectReference 错误
【发布时间】:2017-10-27 23:42:20
【问题描述】:

在 vs2017 中使用 dotnet core 2.0-preview1 时。我收到有关项目参考的错误。

我有两个项目的解决方案。



这是Common.Bll 项目

Common.Web 引用了项目Common.Bll。但是 ide 告诉我找不到 Common.Bll 错误 Using directive is not required by the code and can be safely removed. Cannot resolve symbol 'Bll'

这是Common.Web 项目

Common.Bll.csproj

Common.Web.csproj


但是可以构建成功并正常运行。 有什么办法解决吗?

更新:

按照@Svek 将Common.Bllnetstandard2.0 更改为netcoreapp2.0 正在工作。

【问题讨论】:

  • 您能否在您尝试引用的Common.Bll 命名空间下显示class 的代码?
  • 在包管理器中运行:Update-Package -reinstall...docs.microsoft.com/en-us/nuget/consume-packages/…
  • 运行Update-Package -reinstall 后仍然无法正常工作。 csproj 文件已添加。
  • 在您的Common.Bll 中将netstandard2.0 更改为netcoreapp2.0
  • 它工作正常。非常感谢!

标签: reference .net-core visual-studio-2017


【解决方案1】:

你的 csproj 文件

Visual Studio 不喜欢在 TargetFramework 不完全匹配时表现得非常正确。

Common.Bll.csproj

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

Common.Web.csproj

<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

让它们都一样,你应该很高兴。


错误:

cannot resolve symbol '<  >'

简单的解决方案是重新安装所有包,并确保所有依赖项都正确显示在每个项目下的 Visual Studio 中。 (依赖项 --> 项目 | 或 | 依赖项 --> 程序集)。

在包管理器中

Update-Package -reinstall

更多细节可以在here找到重新安装你的包。


引用未使用的库

- 更新:你可以忽略这个。您更新后的问题使本节不再适用。 -

在您实际使用库之前,Visual Studio 会通知您引用的库不是必需的。

using directive is not required by the code and can be safely removed.

您可以做以下两件事之一:

1.) 使用您引用的库

在你的情况下:

var obj = new Common.Bll.<Your Class>;

2.) 删除您正在引用的库

这可以通过右键单击并选择Remove Unused Usings来快速完成。

替代方法是使用键盘快捷键Ctrl+R, Ctrl+G

【讨论】:

  • 使用new Common.Bll.UserBiz() 时不起作用。在依赖中我们可以找到Common.Bll的引用。我已经更新了问题并添加了依赖项。谢谢
  • 你先恢复你的包了吗?
猜你喜欢
  • 2018-02-11
  • 1970-01-01
  • 1970-01-01
  • 2018-04-05
  • 2017-08-21
  • 2018-06-25
  • 2017-12-27
  • 1970-01-01
  • 2018-07-25
相关资源
最近更新 更多