简体   繁体   中英

Unable to project reference a .NET Core Class Library from Full .NET Project

I'm trying to split my .NET Core project into separate concerns using Class Librairies. I want one (or many) Class libraries and one host project. Class librairies will define the MVC Controllers and the business logic while the host project will be in charge of providing a working host. Unfortunately, the project reference refuses to work.

Let me give you the steps I took to arrive to this issue.

  1. Create empty solution in Visual Studio 2015 Update 3
  2. Create a project of type Class Library (.NET Core) named ClassLibrary1
  3. Go in the project.json and modify it to make it look like below.
  4. Create a project of type Console Application (not .NET Core) named ConsoleApplication1
  5. Right-click in References under ConsoleApplication1 and add ClassLibrary1 as a Project reference .
  6. Refer to a type that exists in ClassLibrary1 .
  7. Build the solution.

This will lead the a Build failure in the ConsoleApplication1 project with the code error CS0246: The type or namespace name 'ClassLibrary1' could not be found (are you missing a using directive or an assembly reference?) . If instead of adding the reference as a Project reference I go and browse to the bin folder and refer the dll directly, everything builds without an issue. However, this is not a solution since the Build target may change, so the path will change as well.

Code of the project.json :

{
  "version": "1.0.0-*",

  "dependencies": {

  },

  "frameworks": {
    "net452": {
    }
  }
}

Is this a Visual Studio bug, or am I doing something wrong? I tried using netstandard1.2 , net452 , but the result remains the same.

EDIT I created an issue in the .NET CLI Github repository. Here is the link: https://github.com/dotnet/cli/issues/3926 .

I had a similar issue with Microsoft.NETCore 5.0.1 in a PCL. It didn't even find System.Object.

I tried downgrading to 5.0.0 and that solved it for me.

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