fharreau fharreau - 1 month ago 16
C# Question

.NET Core Reference Type project not working

I am having trouble with project reference and .NET Core.

I have a library (

MyLib
) in the src folder and two project in the test folder (
MyLib.Tests
and
MyLib.Tests.Support
)

Summarized:

|-- global.json
|-- src
| \-- MyLib
\-- test
|-- MyLib.Tests
\-- MyLib.Tests.Support


MyLib is already available through NuGet and the tests projects are not (and won't be).

When I reference (with the
right click > add reference
option)
MyLibTest.Support
within
MyLib.Tests
, the
dotnet-restore
works fine. In visual studio, under "References", I have the small icon indicating it is a project reference. When I reference (still with the
right click > add reference
option)
MyLib
within
MyLib.Tests
, the
dotnet-restore
works also fine but I have the small icon indicating it is a nuget reference.

It is the expected behaviour but I don't want my test project to test the "old" NuGet package but the actual code.

According to the documention and a lots of tutorial I found on the internet, I then configure in
MyLib.Tests\project.json
the
MyLib
dependency as a project dependency:

{
"dependencies": {
"NETStandard.Library": "1.6.0",
"SimpleDao": {
"target": "project"
"version": "2.0.0-*"
},
"MyLib.Tests.Support": "1.0.0-*"
}
}


But then, the
dotnet-restore
fails:


  1. Visual Studio error:
    NU1001 The dependency MyLib could not be resolved.

  2. Console error:
    Unable to resolve 'MyLib' for '.NETStandard,Version=v1.6'



Here is my global.json:

{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003131"
}
}


Ask me for anything else that could be relevant to explain my troubles

Thanks in advance.
(Excuse me for my english, I am not a native speaker)




Edit:

I realized there is also something wrong with my lib : actually
MyLib
is composed of three libs:


  1. MyLib
    , mostly interfaces, targetting
    .netstandard1.1

  2. MyLib.Impl1
    , first implementation, targetting
    .net451
    and
    .netstandard1.3
    (not yet on NuGet)

  3. MyLib.Impl2
    , second implementation, targetting
    .net45
    (there is already a first version of it on NuGet)



Always with the same methodology for adding the reference (
right click > add reference
). I did not edit the project.json files (both are adding the reference like this: "MyLib": "2.0.0-*").

In the first implementation, visual studio get the dependencies through NuGet (there is the NuGet icon in the references tab). And I do not have the lastest edit on the interfaces of MyLib.

In the second implementation, visual studio get the dependencies within the project (there is the project icon in the references tab), and I do have the lastest edit on the interfaces.

If I try to edit the project.json to configure the dependency to MyLib as a project dependency, I can not restore the package too, same error than for the tests...

Is it a bug in .NET Core (I am trying to restore with both Visual Studio and dotnet-cli) or am I doing Something wrong?

Edit 3: I had published pre-release version of
MyLib
and
MyLib.Impl2
on NuGet. I deleted those version and get back to my solution. Now,
MyLib.Impl1
and
MyLib.Impl2
are targetting correctly my project reference (for
MyLib.Impl1
I had to specify the target in the project.json and not for
MyLib.Impl2
. I don't know why but at least it works now -_-).

But I still can't fix my test project. It still don't want to work with the project reference...




Edit 2:

Here is my github repository where you can find my whole code (within the migration branch).

Answer

Well, it was a tough one ...

I was porting my lib from full .NET to .NET Core and during the process, I misnamed one project (upper/lower case issue). I renamed it with the right case but I didn't change anything in the .sln.

When I added this project as a reference in another project, Visual Studio was using the olg unchanged name from the .sln and not the current one.

It looks like it was easier to find the reference on NuGet than on local projects when there is a case issue like this ...