Computer
Computer

Reputation: 2227

Excluding files from Nuget package

I have a few projects, which could be a console application, Web Application, WebAPI, MVC etc) and a normal Class Library (not Core/.Net 6) which contains Newtonsoft.Json dll (latest version).

Each of the applications have their own version of Newtonsoft.Json dll that has been added manually for that project. In doing this it means an older app could have used version 1.0 the next application could have used v 2.0 and later apps could have used a much later version etc

I would like to share this class library through a Nuget package but i have added the latest version of Newtonsoft.Json dll into my own class library.

When i create a .nuspec file i would like to exclude this file but using this code

<files>
    <file src="bin\Release\Newtonsoft.dll" target="\" />
</files>

within the .nuspec file doesnt seem to work, reading https://learn.microsoft.com/en-us/nuget/reference/nuspec suggests to use the exclude but i cant get the syntax right.

What am i missing here?

Upvotes: 0

Views: 193

Answers (1)

Palle Due
Palle Due

Reputation: 6292

In your nuspec include this:

<dependencies>
    <dependency id="Newtonsoft.Json" version="[3.5,14)" />
</dependencies>

Where 3.5 is the oldest version you support and 14 is the newest you do not support. Then you can leave out newtonsoft.dll from you own package and the project you install the nuget into will be able to determine which newtonsoft to use.

Upvotes: 1

Related Questions