简体   繁体   中英

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:

在此输入图像描述

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:

在此输入图像描述

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?

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

My .net 2 standard 在此输入图像描述

That has only one class

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

And my .net core 2.1 project

在此输入图像描述

that calls the class from the library 在此输入图像描述

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.

  • 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.

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.

This happened to me when the path was cloned from git with spaces "%20". After I removed the spaces, it built without issues in Visual Studio 2017. Interestingly, I had the same issue in JetBrains Ryder, but not the command line ( dotnet build ).

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