Shared Library with NetCoreApp fails

Hey All,

Playing around with Visual Studio Mac and netcore (latest of both installed yesterday) and can't get it to reference a shared project.

Here's what I did:

  1. Create a new netcore1.1 console app - built it and ran fine.
  2. Created a shared C# project
  3. Added a reference from the console app to the shared project.

Visual Studio displays "Could not restore packages" and the log ends with this:

All packages and projects are compatible with .NETCoreApp,Version=v1.1 (win-x86).
Committing restore...
Lock file has not changed. Skipping lock file write. Path: /Users/brad/Projects/DotNetCoreTest/DotNetCoreTest/obj/project.assets.json
Restore completed in 2.47 sec for /Users/brad/Projects/DotNetCoreTest/DotNetCoreTest/DotNetCoreTest.csproj.

NuGet Config files used:
    /Users/brad/.config/NuGet/NuGet.Config

Feeds used:
    https://api.nuget.org/v3/index.json
Object reference not set to an instance of an object

Am I missing something simple? Is this a known issue? That last line looks ominous.

Best Answers

  • BradRobinsonBradRobinson AUMember ✭✭✭
    Accepted Answer

    Thanks Guys!

Answers

  • mattwardmattward GBMember Xamurai

    This is a known bug which is being tracked on the bug tracking system.

  • BradRobinsonBradRobinson AUMember ✭✭✭
    Accepted Answer

    Thanks Guys!

  • BradRobinsonBradRobinson AUMember ✭✭✭
    edited May 25

    Hey Guys... just getting back to trying this now and I think I might still be missing something.

    Firstly, I turned off Preferences -> NuGet -> General -> Automatically Restore packages but when I add a reference to a shared project it still seems to insist on doing a package restore and fails.

    Second, I manually edited the project file and added the appropriate for the shared project and I can now open and build the project that references it, however VS solution explorer shows all the files imported from the shared project in the referencing project in one long list (which is super annoying since the shared project has about 160 files in it).

    Finally, once I've got the project open with the shared project referenced... if I then try to add a reference to another class library project, the shared project reference seems to be removed and I'm back to square one.

    Is there something else I need to do to make this work normally, or is shared project support just not ready yet.

  • mattwardmattward GBMember Xamurai

    @BradRobinson - The shared project reference is not removed from the project file. It may look like it is because it is not displayed in the Dependencies folder, due to the restore failure, however the project will still have the project added as an import. If you close and re-open the solution the project reference should be displayed.

    The only real workaround for now is to disable NuGet restore, as you have, and then use dotnet restore from the command line to fix the generated MSBuild files in the obj directory so the projects will compile correctly.

    The files from the shared project being shown in the project referencing that shared project is another bug which will be fixed in the next release, which should be 7.1. Whilst 7.1 is currently available from the alpha channel that build does not contain the shared project fixes currently.

  • BradRobinsonBradRobinson AUMember ✭✭✭

    Thanks @mattward - actually multiple times I've seen it remove things from the project file including nuget references and references to other class library projects. I've even had the csproj open in sublime text and watched the entries disappear while XS was trying to restore packages.

    The biggest problem here seems to be the inability to properly disable package restore. The option I mentioned stopped the restore when opening the solution but doing anything else with the project invokes the restore and then things get stomped so I'm constantly closing the solution tweaking the csproj file and then reopening the solution.

    Is there some other setting I've missed? A setting in the csproj perhaps?

  • mattwardmattward GBMember Xamurai

    No. If you edit the .csproj in the text editor or change a reference in the solution window then a restore will be run. The generated files in the obj directory need to be updated when things change.

    Do you have a repro for things being removed from the project file when you are not expecting them to be removed?

  • BradRobinsonBradRobinson AUMember ✭✭✭

    Hey @mattward sorry for slow reply... since my last post I switched to the alpha channel and things seem to be reasonably stable now. If I switch back to the stable channel at any point I'll try to repro again. Right now I'm just happy to be working again. Thanks for the help.

Sign In or Register to comment.