2
votes

perhaps Im getting old but Im really confused on how to use a nupkg on Linux. Resolving and installing dependencies/adding libs for C is easier for me (never would thought I would say so).

I got a package from a vendor (YYYYY_linux.3.0.77.nupkg) and want to run their example code (version for windows with visual studio worked out of the box) but they told me their linux pack would also work.

What I did:

dotnet init
... coding ...
dotnet restore
dotnet build

/home/tobiass/code/XXXX/Program.cs(27,11): error CS0246: The type or namespace name 'YYYYY' could not be found (are you missing a using directive or an assembly reference?)

Afterwards I tried two things:

1.

I edited NuGet.Config

dotnet restore

The nupkg shows up as a feed. But I still get the same error.


2.

I also tried to create a local feed

mono nuget.exe add ../YYYYYYY_linux.3.0.77.nupkg -source ./

but it always results in

The requested feature is not implemented.

What is the correct way on Linux to add a library? Must it be also a part of project.json? Some config in .nuget?

Best,

Tobias

1

1 Answers

1
votes

I suspect your project is not a .NET Core project so you should be using nuget.exe instead of dotnet.

So first I would take a look at the example code. Does it have a .csproj file? Does it have a packages.config file? Does it have a packages folder with the .nupkg file in it already? If so then nothing needs to be done and it should just compile.

From the error message one or more of the above are not correct. If the project file (.csproj) has references to the files in the NuGet package and there is an existing packages.config file then all you need to do is restore the package. To do that you need to put the NuGet package somewhere so it can be restored. You could simply just copy the .nupkg file into ~/.local/share/NuGet/Cache/ which is the machine cache for all NuGet packages and then restore it into the project by running nuget restore Path/To/YourSolution.sln.

If the project does not have a packages.config file then you would need to install it into the project. The simplest way would be to use MonoDevelop. That has built-in support for adding NuGet packages to projects.

Otherwise you could just unzip the .nupkg file and copy the files where they need to go into the solution's packages directory based on the information in the .csproj file.