I have 2 Projects Libraries in my Example Solution > Visual Studio.
I directly reference one of them in the other. When I now publish my nuget package, on the dependency overview I get that my directly referenced nuget is >= 1.0.0.0
, when I do it via nuget the reference means no direct reference because same solution I get the right version number under >= dependency overview. I won't change the default dependency behavior lowest
.
What I've tried is to update my nuspec file with dependencies / references / files elements none of them worked for me.
I would like to see the same version of the given nuget in the directly referenced nuget as dependency.
From the last sentence in you question and your emphasis on direct references makes me feel I know what you are after:
NuGet defines the -IncludeReferencedProjects
option to instruct nuget.exe
how it should treat referenced projects, either as dependencies or as part of the package:
.nuspec
file that has the same name as the project, then that referenced project is added as an explicit NuGet dependency.My guess is that you are after the former.
Let us simplify the problem to its most basic form: Let's say you have a solution where LibraryA
references LibraryB
directly as a project reference. When you build the solution, the assembly output from LibraryA
is copied to LibraryB
~/
│ Solution.sln
├───LibraryA
│ │ ClassA.cs
│ │ LibraryA.csproj
│ │ LibraryA.nuspec
│ ├───bin
│ │ ├───Debug
│ │ │ LibraryA.dll
│ │ │ LibraryA.pdb
│ │ └───Release
│ └───Properties
│ AssemblyInfo.cs
└───LibraryB
│ ClassB.cs
│ LibraryB.csproj
│ LibraryB.nuspec
├───bin
│ ├───Debug
│ │ LibraryA.dll
│ │ LibraryA.pdb
│ │ LibraryB.dll
│ │ LibraryB.pdb
│ └───Release
└───Properties
AssemblyInfo.cs
For illustration purposes I will use the pattern
[assembly: AssemblyVersion("1.0.*")]
in myAssemblyInfo.cs
files and will do a couple of separate builds on each project to ensure my assemblies get some different interesting versions.
Make sure that each project contains a .nuspec file with the same name as the project. This is specially important for project LibraryA
, as it is the project being referenced by LibraryB
. I'll do it for both as good practice. Let us use a basic template for now:
In the .nuspec
below, the replacement tokens $id$
and $version$
will get their values inferred when you run nuget.exe
against a .csproj
file that has been built.
<?xml version="1.0"?>
<package >
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>The author... (**mandatory element**)</authors>
<description>Your description... (**mandatory element**)</description>
</metadata>
</package>
nuget pack -IncludeReferencedProjects
Now, I am going to run nuget.exe
in the command line from the solution directory (~
) on project LibraryB
:
PS> nuget pack .\LibraryB\LibraryB.csproj -IncludeReferencedProjects -Verbosity detailed
Attempting to build package from 'LibraryB.csproj'.
Packing files from '~\LibraryB\bin\Debug'.
Using 'LibraryB.nuspec' for metadata.
Add file '~\LibraryB\bin\Debug\LibraryB.dll' to package as 'lib\net451\LibraryB.dll'
Id: LibraryB
Version: 1.0.5993.6096
Authors: The author... (**mandatory element**)
Description: Your description... (**mandatory element**)
Dependencies: LibraryA (= 1.0.5993.7310)
Added file 'lib\net451\LibraryB.dll'.
Successfully created package '~\LibraryB.1.0.5993.6096.nupkg'.
PS>
The above command will create a NuGet package LibraryB.1.0.5993.6096.nupkg
with a explicit NuGet dependency to LibraryA.1.0.5993.7310.nupkg
.
When you inspect the contents of LibraryB.1.0.5993.6096.nupkg
, you will see that the .nuspec
generated by nuget.exe
will have replaced all the $version$
replacement tokens to that of the actual versions used.
One last thing, the command above will create the NuGet package only for LibraryB
but obviously you can create the one for LibraryA
just by running it again targeting LibraryA.csproj
I hope this is what you were after, or that at least sheds some light to what you can do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With