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:
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
Create second solution slnSecond and add a solution folder called MySolutionFolder. Add Standard.Project.cproj from 1 above (both versions). slnSecond will compile
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With