I am trying to create a Nuget package from my project following this guide http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package
I have successfully created a nuspec and nupkg. My project contains a dependency to Json.NET which I installed via Nuget. However, I want to specify a specific version of Json.NET to use, version 4.0.7. I added the below to my nuspec:
<dependencies>
<dependency id="Newtonsoft.Json" version="[4.0.7]" />
</dependencies>
When I run nuget pack it seems to detect I have a packages.config
Using 'MyProject.nuspec' for metadata.
Found packages.config. Using packages listed as dependencies.
This seems to completely ignore my defined dependency in the nuspec as installing the Nuget package lists the dependencies as >= 4.0.7 which pulls in the latest version 4.0.8.
How can I stop this or preferably keep Nuget pulling in dependencies from the packages.config but allow me to overwrite specific dependencies?
I hit the same issue. You need to define an exact version like this
<dependencies>
<dependency id="Newtonsoft.Json" version="[4.0.7,4.0.7]" />
</dependencies>
So that will ensure when the project pulls in the dependencies it will be = 4.0.7 not >= 4.0.7
The way you specified your version is correct; as shown in our versioning docs, [1.0] means 'version == 1.0'. The behavior you're describing would be a bug, but I couldn't reproduce the bug. What I did:
Created a class library
Added Json.NET via NuGet (it installed 4.0.8)
Exec'd nuget spec
Added <dependencies><dependency id="Newtonsoft.Json" version="[4.0.7]" /> to the .nuspec
Exec'd nuget pack
Opened the package in Package Explorer; it shows the dependency as '= 4.0.7'
Installed my package in a new project; it shows the dependency as '= 4.0.7' and installs 4.0.7
Perhaps you aren't using the latest version of nuget.exe or the NuGet Visual Studio extension? When you say it "lists the dependency", where are you seeing that? When your package is installed, in Package Explorer, or somewhere else?
Related
I have came across this line of code in a code and its quite confusing
One of my client send a dependancy file that contains
<ItemGroup>
<PackageReference Include="xyzrefrence" Version="1.3.0" />
and said it is console application. I created same kind of application but within packages.config
I found this thing
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="xyz" version="1.7.7.7" targetFramework="net452" />
My question is that where the dependacy file located with the client setting(First settings)
The reference (<ItemGroup><PackageReference.....) to the dependency can be
found by editing the Visual Studio project file. *.csproj
The dependency file itself can be found in your project's /bin/debug or /bin/release folders.
Where is PackageReference located in console application C#
There are two nuget mamangement format(Packages.config and PackageReference) to intall nuget packages.
In fact, PackageReference is a new nuget management format for new sdk projects(net standard and net core) since VS2017 while Packages.config is an old tranitional nuget management format for net framework projects.
However, you should note that for traditional framework projects, Microsoft made a concession to use the new SDK's pacakgeReference format, but there are still various compatibility issues.--------(net frameowork projects can use both of them while net core/net standard projects can only use PackageReference).
If you use a net framework project, you can change these two format before you install nuget packages at the beginning by Tools-->Options-->NuGet Package Manager-->General-->Package Management.
And you should specifiy this format before you install the first nuget package at the beginning and when you specify this format, the nugets you install later will use this method by default and cannot be changed.
My question is that where the dependacy file located with the client
setting(First settings)
1) If you use a net framework console project with PackageReference, l am afraid that you cannnot see the depenencies of the nuget. The old sdk projects with PackageReference does not support showing the depenencies of the nuget packages due to several compatibility issues.
2) If you use a net core console project, you can see the dependencies in the Solution Explorer and the latest new sdk projects does support this. It has a new behavior that you can see every nuget package's depenencies under its branch in the Soluton Explorer.
Besides, since you use a framework project with packages.config, you can only see all of them(the premise is that this nuget package has dependencies.) in the packages.config file or in the xxxx.csproj file but it cannot subdivide dependencies for every nuget package.
In additon, if you still want to show the depenencies of the net framework projects with PackageReference, l suggest you could post a feature request in our User Voice forum(DC)-suggest a feature to get Micorosft's attention.
I have a .NET 4.5.2 library using Visual Studio 2017 (v 15.9.7).
In my library project (i.e. csproj), I've added a Nuget dependency on CEFSharp for WPF (which itself includes other dependencies).
I've converted my library Nuget references to use the newer "PackageReference" mode.
When running nuget pack from the command line, I expect that the created *.nupkg would automatically include references to the CEFSharp components that my library references.
It doesn't look like this is the case. When I open the nupkg as a zip, I can't see any references to CEFSharp.
Do I really need to make my library's nuspec file redundantly declare the CEFSharp dependency even though my csproj already essentially defines the CEFSharp dependency?
If you're generating your nuget from a nuspec file then yes, this file must declare the dependencies to other nugets. For instance:
<dependencies>
<group>
<dependency id="CefSharp.Wpf" version="71.0.0" exclude="Build,Analyzers" />
</group>
</dependencies>
It's my own custom nuget package that I've not published yet and testing locally.
The nuget package consists of a dll file and nuspec file is as follows.
<?xml version="1.0"?>
<package >
<metadata>
<id>MyLib</id>
<version>1.0.0</version>
<authors>Author</authors>
<owners>Owner</owners>
<licenseUrl>license url</licenseUrl>
<projectUrl>project url</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>some description</copyright>
<tags>Tag1 Tage2</tags>
</metadata>
<files>
<file src="bin\Debug\netstandard1.4\*.dll" target="lib" />
<file src="bin\Debug\netstandard1.4\*.pdb" target="lib" />
</files>
</package>
I've copied the nupkg file to a location and added it to the
Visual studio Tools -> Options -> Packages -> sources directory
Error:
Package MyLib 1.0.0 is not compatible with netcoreapp1.0 (.NETCoreApp,Version=v1.0). Package MyLib 1.0.0 supports: net (.NETFramework,Version=v0.0)
Package restore failed. Rolling back package changes for 'WebApplication1'.
Not sure how can I resolve the issue or find more information.
More Info
The dll file was created using template (.Net Framework 4.5.2)
Templates -> Visual C# -> .NET Core -> Class Library (.NET Standard)
The web application was crated using template. (Empty Web Application)
Templates -> Visual C# -> .NET Core -> ASP.NET Core Web Application (.NET Core)
Edit
I found more details under Output window
One or more packages are incompatible with .NETCoreApp,Version=v1.0.
What kind of class library should I create which is compatible with .NETCoreApp?
Edit2
I saw this URL. it suggests to create the nupkg using dotnet.exe pack --no-build whereas earlier I downloaded the nuget.exe from nuget.org to create the package.
I tried above command but then visual studio says
"... Target pack doesn't exists in the project ... "
Followed instructions on this site as well but failed URL
You need clear the Nuget Cache. To do this, go to Tools -> Options and click on it like this picture
Your project is targetting an incompatible version of .Net Framework. Right click on the project, select properties and note the value of the Target Framework. Look at the Nuget package for Microsoft and then install a more suitable NuGet package. Either install the older version of the NuGet package or update your project to target a newer version.
I had to change the Build Configuration due to an NU1603: warning.
In my Build configuration the "Treat warnings as errors" was set to All.
This was blocking Nuget from upgrading the Package due to the NU1603 warning.
When updating a nuget package to a new version, dependencies of the package being updated are removed and reinstated as the lowest allowable version of those dependent packages. The package manager console output is as follows:
Update-Package web.CMS -version 6.5.0-develop-140728152
Updating 'Web.CMS' from version '6.5.0-Trunk-1406031714' to '6.5.0-develop-1407281525' in project 'App.Cms'.
Remove 'Web.CMS 6.5.0-Trunk-1406031714' from project App.Cms.
Remove 'Cms.Assemblies 6.1.379' from project App.Cms.
Remove 'Web 7.3.0' from project App.Cms.
Remove 'Core 8.0.0-Trunk-1406251804' from project App.Cms.
Add 'Core 6.1.0' to project App.Cms.
Add 'Web 6.0.0' to project App.Cms.
Add 'Cms.Assemblies 6.0.530' to project App.Cms.
Add 'Web.CMS 6.5.0-develop-1407281525' to project App.Cms.
The dependencies section of the Web.CMS package nuspec file is as follows, as you can see the dependent package versions are those that have been installed as part of the package update.
<dependencies>
<dependency id="Core" version="6.1" />
<dependency id="Web" version="6.0" />
<dependency id="Cms.Assemblies" version="[6.0.530,7)"/>
</dependencies>
Is there a way to update a package without the dependent packages reverting to older versions, as happens here? We can do it by uninstalling the package and installing the new version, that's for from ideal however as some packages are used by several projects in a solution and it has to be done for each project individually.
This was fixed by including the -IgnoreDependencies switch:
Update-Package web.CMS -version 6.5.0-develop-140728152 -IgnoreDependencies
I've been working on this MVC 3 application on my home computer for a while now. I'm out of town on a different computer, so I got the project from my source control. This new computer didn't have MVC 3 yet, so I installed it after I copied the project to the new computer.
A lot of my dlls (like MvcContrib.dll) were missing since I didn't set Copy Local to true when I first created the project on my home computer. So I've been going in and downloading all the missing dlls and adding them to my project.
The only one I can't find is EntityFramework.dll. I can't find a download for it, and I don't see it as a .NET dll when I try to add a reference.
I'm getting this warning when I try to build:
Could not resolve this reference. Could not locate the assembly "EntityFramework"
This can also happen when you manually remove the EntityFramework reference in a project.
If you've lost the reference you can remove the entry in packages.config for EntityFramework
<packages>
<package id="EntityFramework" version="5.0.0" targetFramework="net40" />
</packages>
After removal you are able to re-install the package through the Package Manager (Manage NuGet Packages)
Download and install Framework 4.0 and it's included.
http://www.microsoft.com/download/en/details.aspx?id=17851
You need to download and install Entity Framework separately:
http://blogs.msdn.com/b/adonet/archive/2011/04/11/ef-4-1-released.aspx
If you have not - install the Nuget extension in Visual Studio.
Install ASP .NET MVC 3 Tools Update (using WebPI is easiest)
Then install the EntityFramework Package.
Other packages are likely available for items such as MvcContrib, which may be missing.
Using Nuget will not only enable you to have the packages with the source (in the packages directory), but will also help you keep things up to date. External dependencies you rely on should ideally be included with your solution so situations like yours do not occur.
As The Evil Greebo noted, you will need to go here to obtain the Visual Studio tooling. While the Nuget package will provide the code level support, the tooling is in the installer. I use both, so if there is an update to the package, it will show up in the Nuget update notices.
I resolved a similar problem myself by downloading the ASP.NET MVC Tools Update. Any chance you are just missing that on this other computer?
If EntityFramework was installed previously you can also manually add reference with browse. Select the following file in your project folder: \packages\EntityFramework.5.0.0\lib\net4x\EntityFramework.dll
Then add the following if missing in your packages.config:
<packages>
<package id="EntityFramework" version="5.0.0" targetFramework="net4x" />
</packages>