Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 error: Cannot find project info for “” This can indicate a missing project reference - with Console App .NET Core 2.1

  • VS 15.7.5

I have a .NET Standard 2.0 class library:

enter image description here

It exists in its own solution but I have now added it to a different solution so that I can use it with my .NET Core 2.1 Console test runner:

enter image description here

However as soon as I do this I get the error. If I remove the console application then everything compiles without error.

So what am I missing here? Why can a .NET Core 2.1 Console application not find my .NET Standard 2.0 class library?

like image 370
TheEdge Avatar asked Aug 01 '18 06:08

TheEdge


3 Answers

I just tried to replicate what you did and it worked for me !

My .net 2 standard enter image description here

That has only one class

 public class School
    {
        public string Name => "Mango Hill";
    }

And my .net core 2.1 project

enter image description here

that calls the class from the library enter image description here

you can see the output. So I suggest you check the common project to see if it references any full library and then try to isolate the references.

like image 192
Toan Nguyen Avatar answered Oct 20 '22 00:10

Toan Nguyen


  • The issue here is that for whatever reason .NET Core Console apps will fail with the error I received if the following are true:

    1. You create the standard project within a folder under the original solution that contains it. So say you have a solution called slnStandard in the path D:\Rubbish\slnStandard.

You then add a new standard class library project Standard.Project.cproj in the path:

a) D:\Rubbish\slnStandard\Standard.Project   <== Will Compile in slnStandard
b) D:\Rubbish\slnStandard\SubFolder\Standard.Project <== Will Compile in slnStandard
  1. Create second solution slnSecond and add a solution folder called MySolutionFolder. Add Standard.Project.cproj from 1 above (both versions). slnSecond will compile

  2. Add a MSTest .NET Core Console application to slnSecond. Then "Add Reference" > Project using what has been added in 2.

If the reference is 1b) it will NOT COMPILE. So basically you need to keep the folder structure flat. Hopefully this will be fixed moving forward.

like image 30
TheEdge Avatar answered Oct 20 '22 00:10

TheEdge


Just try running "build" or "restore" command using Dotnet CLI 2.1 version. from command window

c:\path> dotnet restore [.net core 2.1 console].csproj

this may be required once if you switch TargetFramework using visual studio. either from .net core 2.0 to 2.1 or vice versa

If you could build the console project from dotnet CLI command "build". and you are getting this error only in visual studio.

Please try to create solution using dotnet "sln" and "add" command to refer the projects.

like image 27
fedcbaeln Avatar answered Oct 19 '22 22:10

fedcbaeln