6
votes

I am running a private Nuget Server locally on IIS. I am creating packages and uploading them all via commadline using nuget.exe (Later on I have to put this on build server, hence the command line). However there is one issue I am stuck at.

I am trying to declare dependencies. I generate the nuspec file in the folder where the .csproj file is there. Then I manually edit the nuspec file to add this under the metadata tag:

<metadata>
    <dependencies>
        <group targetFramework=".NETFramework4.5">
            <dependency id="DemoProject" version="2.0.0.0" />
        </group>
   </dependencies>
</metadata>

DemoProject, version 2.0.0.0 is present on the Nuget Server. The project I am creating package for, MyProj.csproj does not have the reference to the DemoProject added to it via Visual Studio. It is just at the packing time I want to create the dependency. It sounds strange but is needed for some initial validation.

Then I run pack command:

"C:\nuget\NuGet.exe" pack MyProj.csproj -IncludeReferencedProjects -Prop Configuration=Release

Then I push it to NuGet server using command line. When I do an install via command line, then only MyProj package is present at the install location.

When I use Nuget Package Explorer and create a package, I can use the Package Dependency Editor to specify the dependency. It asks for the URL of my local Nuget Server and then adds the dependency. And when I install that package, it works !!

There seem to be no difference in the generated nuspec file in both the cases. Obviously Nuget Package manager is doing something which I am missing out on.

Any hints?

More details: When I create a lib folder in the Package manager console and put my dll manually, lib->net45->MyProj.dll, then when I install the package thus created also "does not" install the dependency. Back to reading documentation again.

2

2 Answers

0
votes

I know this doesn't directly answer your question but I had an issue with NuGet dependencies and my solution may possibly provide a hint.

DLL#1 was had no NuGet Dependencies. Pushed that to my private repo. DLL#2 referenced DLL#1 NuGet package. Pushed that to my private repo.

All fine and dandy except from the Application project when I go to "Manage NuGet Packages...", the NuGet Package for DLL#2 is listed on the Browse tab but it shows no dependencies. I was forced to install both DLL#1 AND DLL#2 nuget packages. I desired to install DLL#2 nuget package and get DLL#1 automatically.

The way I fixed this was uninstalling all NuGet packages from DLL#2 solution. Then going to Tools > Options > NuGet Package Manager > General. Then set the Default package management format to Packages.config and then unchecking the option "Allow format selection on first package install".

Then i installed all the needed NuGet packages. Now when i pack it up and push it up to the server, it shows the proper dependencies when going to "Manage NuGet Packages...".

nuget pack doesn't see the dependencies because its looking for them in the \packages folder. That folder didn't exist because I was using PackageReference for package management.

All worked after switching to Packages.config for package management.

I know the problem I had wasn't the same as yours but if you're not using Packages.config for package management, perhaps its related.

0
votes

Late answer but the issue with this nuspec is <group targetFramework=".NETFramework4.5">. I feel confident that ".NETFramework4.5" is an invalid targetFramework. A full list of the available Target Frameworks is here.

When working with the Dependency section, you may not need to use the group tag. Any users who encounter similar errors would do well to read through that section. They have samples of proper usage.