Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DotNet Core App 2.1 - Can't add DLL reference

I have a DotNetCore 2.1 Web App (just created it today from the VS 2017 scaffold). This solution also includes a DotNet Core 2.1 Library DLL project. The solution builds ok.

I have another (brand new) DotNetCore 2.1 Web App that wants to use the Library DLL. But when I try to add a new reference (on the Browse tab), it complains:

One or more errors occurred.
The reference is invalid or unsupported.

Any suggestions?

(Curiously, the DLL doesn't show up directly under the Bin\Debug folder like it does in classic .Net; It's under Bin\Debug\netcoreapp2.1)

like image 634
Bob.at.Indigo.Health Avatar asked Jun 13 '18 01:06

Bob.at.Indigo.Health


3 Answers

I got this error after I moved some of my code repos around and suddenly my .NET Core 2.1 console app wouldn't recognize a .NET 4.5 DLL anymore when I added it.

Turned out that although the broken reference did not show in the solution explorer, the project file still contained it, along with the now broken HintPath to the DLL's old location. Manually removing this reference from the project file solved it.

like image 190
Simmetric Avatar answered Nov 16 '22 05:11

Simmetric


Go into your .csproj and make sure the <Reference Include=... is pointing to the correct directory.

For example, my references were pointing to the bin\Debug path of another project when the only build that was actually there was the bin\Release

like image 42
Aaron Jordan Avatar answered Nov 16 '22 07:11

Aaron Jordan


When you create a new project from the Visual Studio 2017 Class Library (.NET Core) template, the csproj file contains:

<TargetFramework>netcoreapp2.1</TargetFramework>

Since this is a library, it (apparently) needs to target netstandard2.0. (BTW, creating a library project from the dotnet command line command correctly targets netstandard2.0. Go figure.)

So changing the line in the library's csproj file to

<TargetFramework>netstandard2.0</TargetFramework>

and rebuilding the library now allows me to reference the library from the DotNet Core 2.1 (netcoreapp2.1) application.

like image 43
Bob.at.Indigo.Health Avatar answered Nov 16 '22 06:11

Bob.at.Indigo.Health