Force nuget to always update a dependency - nuget

I wish to ensure my nuget package always updates to the latest version of another dependent package. Is there anyway I can do this?
My current nuspec looks like
<?xml version="1.0"?>
<package>
<metadata>
<id>Engine</id>
<version>$version$</version>
<title>Engine</title>
<authors>AgResearch</authors>
<owners>Overseer </owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>My budget model</description>
<releaseNotes>Release model</releaseNotes>
<copyright>Copyright 2014</copyright>
<tags>Overseer engine</tags>
<dependencies>
<dependency id="OverseerEngine.Schema" version="" />
<dependency id="Rezare.Lib" version="1.0.23.2" />
</dependencies>
</metadata>
<files>
<file src="OverseerEngine.dll" target="lib\net40\OverseerEngine.dll" />
<file src="OvrFileImport.dll" target="Content" />
</files>
</package>
It is the OverseerEngine.Schema package that I wish to always be updated (if an update is available) whenever this package is.

Currently there is not an automated way to do this. User has to manually update the package using the console or the update tab of manage nuget packages dialog.

Related

nuget not installing file in project\bin directory

Working in VS 2019 .NET framework 4.8
For my C# class library project, I ran nuget spec to create a nuspec file for the dll and its dependencies:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>MyId</id>
<version>1.0.0</version>
<title>MyTitle</title>
<authors>Me</authors>
....
<dependencies>
<dependency id="dll1" version="1.0.0" />
<dependency id="dll2" version="2.0.0" />
</dependencies>
</metadata>
</package>
No problems building the nuget package. In my consuming project (MyProject), I installed that package, and after building MyProject, the class library dll and the dependency files are placed in the MyProject\bin directory. Great.
However I need to get another file into directory MyProject\bin, let's call that file MyFile.txt. I first tried using the element:
.....
<dependency id="dll2" version="2.0.0" />
</dependencies>
</metadata>
<files>
<file src="MyFile.txt" target="lib" />
</files>
</package>
No luck. While the file is in the packages\lib folder, it does not get placed in MyProject\bin.
I then removed the element and tried the element within the tag:
.....
<contentFiles>
<files include="MyFile.txt" buildAction="None" copyToOutput="true" flatten="true" />
</contentFiles>
</metadata>
</package>
No luck that way either. Is there a way to accomplish what I need to do? It looks like it may involve having some folders in my class library root folder, but not sure what folders (content?) or how to properly reference them in the nuspec file. Thanks.
Neglected to update this post with the answer I found.
Using the <files><file /></files> logic is what solved it. It involved the use of the target attribute and using the content keyword in the value:
<files>
<file src="content\bin\MyFile.txt" target="content\bin" />
</files>
It's in the documentation, I unfortunately missed that even upon multiple readings. See https://learn.microsoft.com/en-us/nuget/reference/nuspec#dependencies-element

Nuget pack does not carry dependency versions correctly

I have Nuget packages created from two projects: foo.csproj and bar.csproj. When using nuget update, I would like bar to update foo to the latest version matching 3.0.*, and reject any 3.1.*:
bar packages.config
<packages>
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net461" />
<package id="foo" version="3.0.4" targetFramework="net472" allowedVersions="3.0" />
</packages>
bar.nuspec
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>var</id>
<version>3.0.4</version>
<!-- omitted -->
<!-- no dependency node in this .nuspec file - good, I think -->
</metadata>
</package>
and in my Nuget feed I have:
foo.3.0.0.nupkg
foo.3.0.1.nupkg
foo.3.0.2.nupkg
foo.3.0.3.nupkg
foo.3.0.4.nupkg
If I call nuget update, it updates the packages.config file correctly - yay!
However, when I call nuget pack bar.csproj, it generates a .nupkg file that includes the following bar.nuspec file:
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>var</id>
<version>3.0.4</version>
<!-- omitted -->
<dependencies>
<dependency id="Newtonsoft.Json" version="12.0.1" />
<dependency id="foo" version="3.0.0" />
</dependencies>
</metadata>
</package>
I expected nuget pack to abide by the packages.config allowedVersions attribute when generating the dependency node inside the .nupkg file.
How do I get nuget update and nuget pack to work together to keep bar up to date with the latest 3.0.* version of foo (in this example, 3.0.4)?
I expect it will work as you desire if you remove the allowedVersions attribute from your packages.config file.

Very confused around creating a nuspec file with specific targets

I have a nuspec file with the following structure
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>XLabs.Forms</id>
<version>2.2.0-pre05</version>
<title>XLabs - Forms</title>
<authors>XLabs Team</authors>
<owners>XLabs Team</owners>
<licenseUrl>https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/XLabs/Xamarin-Forms-Labs</projectUrl>
<iconUrl>https://raw.githubusercontent.com/XLabs/Xamarin-Forms-Labs/master/Design/Icons/nuget/icon_nuget.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This package contains the cross-platform XLabs Forms framework and controls.</description>
<summary>XLabs is a open source project that aims to provide a powerfull and cross platform set of controls tailored to work with Xamarin Forms.</summary>
<releaseNotes>Updated for Xamarin Forms 2.2</releaseNotes>
<copyright>Copyright © 2016 XLabs Team</copyright>
<tags>Xamarin XLabs Forms Controls GridView ListView</tags>
<dependencies>
<group>
<dependency id="XLabs.Platform" version="[2.2.0-pre05]" />
<dependency id="Xamarin.Forms" version="2.2.0.31" />
</group>
</dependencies>
</metadata>
<files>
<!-- Assemblies: Android -->
<file src="..\..\source\Forms\XLabs.Forms\bin\$configuration$\XLabs.Forms.dll" target="lib\monoandroid" />
<file src="..\..\source\Forms\XLabs.Forms\bin\$configuration$\XLabs.Forms.pdb" target="lib\monoandroid" />
<file src="..\..\source\Forms\XLabs.Forms.Droid\bin\$configuration$\XLabs.Forms.Droid.dll" target="lib\monoandroid" />
<file src="..\..\source\Forms\XLabs.Forms.Droid\bin\$configuration$\XLabs.Forms.Droid.pdb" target="lib\monoandroid" />
<!-- Assemblies: iOS -->
<file src="..\..\source\Forms\XLabs.Forms\bin\$configuration$\XLabs.Forms.dll" target="lib\Xamarin.iOS10" />
<file src="..\..\source\Forms\XLabs.Forms\bin\$configuration$\XLabs.Forms.pdb" target="lib\Xamarin.iOS10" />
<file src="..\..\source\Forms\XLabs.Forms.iOS\bin\$configuration$\XLabs.Forms.iOS.pdb" target="lib\Xamarin.iOS10" />
<file src="..\..\source\Forms\XLabs.Forms.iOS\bin\$configuration$\XLabs.Forms.iOS.dll" target="lib\Xamarin.iOS10" />
</files>
</package>
and it is driving me a little crazy :) The nupkg file that is created with this nuspec should ONLY install in a Xamarin iOS or base Xamarin Android project right? Not true, it is installing in any type of project (PCL, Windows 10, Windows 8, etc). I am at the point where I am not sure what else to do to limit the package so that it can only be installed in the targets that I need.
Can anyone see what I might be doing wrong?
UPDATE: Here is the latest version of the nuspec file that I have tried that still DOES NOT work. The following will create a package that installed in a Windows 8, Windows Mobile, and PCL project even though it only contains Android bases assemblies
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>XLabs.Forms</id>
<version>2.2.0-pre05</version>
<title>XLabs - Forms</title>
<authors>XLabs Team</authors>
<owners>XLabs Team</owners>
<licenseUrl>https://github.com/XLabs/Xamarin-Forms-Labs/blob/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/XLabs/Xamarin-Forms-Labs</projectUrl>
<iconUrl>https://raw.githubusercontent.com/XLabs/Xamarin-Forms-Labs/master/Design/Icons/nuget/icon_nuget.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This package contains the cross-platform XLabs Forms framework and controls.</description>
<summary>XLabs is a open source project that aims to provide a powerfull and cross platform set of controls tailored to work with Xamarin Forms.</summary>
<releaseNotes>Updated for Xamarin Forms 2.2</releaseNotes>
<copyright>Copyright © 2016 XLabs Team</copyright>
<tags>Xamarin XLabs Forms Controls GridView ListView</tags>
<dependencies>
<group targetFramework="monoandroid">
<dependency id="XLabs.Core" version="[2.2.0-pre05]" />
<dependency id="XLabs.IoC" version="[2.2.0-pre05]" />
<dependency id="XLabs.Platform" version="[2.2.0-pre05]" />
<dependency id="XLabs.Serialization" version="[2.2.0-pre05]" />
<dependency id="Xamarin.Forms" version="2.2.0.31" />
</group>
</dependencies>
</metadata>
<files>
<!-- Content Files -->
<file src="..\..\docs\XLabs.Forms.Readme.md" target="content\XLabs.Forms.Readme.md" />
<!-- Assemblies: Android -->
<file src="..\..\source\Forms\XLabs.Forms\bin\$configuration$\XLabs.Forms.dll" target="lib\monoandroid" />
<file src="..\..\source\Forms\XLabs.Forms\bin\$configuration$\XLabs.Forms.pdb" target="lib\monoandroid" />
<file src="..\..\source\Forms\XLabs.Forms.Droid\bin\$configuration$\XLabs.Forms.Droid.dll" target="lib\monoandroid" />
<file src="..\..\source\Forms\XLabs.Forms.Droid\bin\$configuration$\XLabs.Forms.Droid.pdb" target="lib\monoandroid" />
</files>
</package>
I believe it is because you have a group dependency that does not have a target framework. The group dependency will cause NuGet to install the Xamarin.Forms and XLabs.Platform NuGet packages whilst the assemblies in your lib directories would not be used unless you are installing into an iOS or Android project.
I would try adding a target framework for iOS and Android.
<group targetFramework="Xamarin.iOS10">
<dependency id="XLabs.Platform" version="[2.2.0-pre05]" />
<dependency id="Xamarin.Forms" version="2.2.0.31" />
</group>
<group targetFramework="MonoAndroid">
<dependency id="XLabs.Platform" version="[2.2.0-pre05]" />
<dependency id="Xamarin.Forms" version="2.2.0.31" />
</group>
Turns out the issue was with this line
<!-- Content Files -->
<file src="..\..\docs\XLabs.Forms.Readme.md" target="content\XLabs.Forms.Readme.md" />
Since that doesn't have a target moniker in it, it is valid for ALL target frameworks. Once I removed that, everything started working. I think the nuspec file format needs a LOT more details in its documentation :)

Prerelease versioning in NuGet

I am trying to create a NuGet pre-release package. Here is my NuSpec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>xxx.Web.Mvc</id>
<version>1.0.3-prelrelease1</version>
<authors>xxx</authors>
<owners>xxx</owners>
<projectUrl>https://xxx</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>xxxx.</description>
<releaseNotes>NuGet package.</releaseNotes>
<copyright>Copyright 2013 xxx</copyright>
<tags>asmx xxx</tags>
<dependencies>
<dependency id="Microsoft.AspNet.Mvc" version="4.0.30506.0" />
<dependency id="Microsoft.AspNet.Razor" version="2.0.30506.0" />
<dependency id="Microsoft.AspNet.WebPages" version="2.0.30506.0" />
<dependency id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
<dependency id="xxx" version="1.0.6" />
</dependencies>
</metadata>
</package>
Note I am using the SemVer mechanism for the pre-release version.
However, when I build my package using:
PM> nuget pack Package.nuspec
I get:
nuget : Input string was not in a correct format.
At line:1 char:1
+ nuget pack Package.nuspec
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Input string wa...correct format.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
This directly refers to my having alphabetic characters in the version string.
I am using NuGet 2.2/VS2012.
How come my version string isn't being recognised?
Update
I've reduced the file to:
<?xml version="1.0"?> <package > <metadata>
<id>xxx</id>
<version>1.0.3-test1</version>
<authors>xxx</authors>
<owners>xxx</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>xxx</description> </metadata> </package>
and a single file in the ~\content folder:
~\content\New Journal Document.jnt
(First time I've seen Windows Journal. Thought I'd try it to make a simple file. :/ )
Fixed it.
Despite reinstalling NuGet 2.x, it seems I still have a v1.5 hanging around.
Seems the Powershell environment was using this version and the Package Manager Console Host Version 2.7.40911.225 message didn't refer to the version of PowerShell, just the host. Seems obvious now I know.
I've manhandled the file and overwritten it.
All now working.
So both this:
NuGet.exe" pack ".\MyPackage.nuspec" -Version 1.0.1-alpha
and
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>MyCoolPackage</id>
<version>1.0.1-alpha</version>
<authors>MyAuthors</authors>
<owners>MyOwner</owners>
<!-- <licenseUrl>http://www.yourLicenseUrl.com</licenseUrl> -->
<projectUrl>http://www.yourProjectUrl</projectUrl>
<iconUrl>http://www.yourIconUrl.com</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>BuildDate : 2013_10_16__17:13:46</description>
<releaseNotes>My Release Notes.</releaseNotes>
<copyright>Copyright 2013</copyright>
<tags>MyTag1 MyTag2</tags>
<dependencies>
<!--
<dependency id="SampleDependency" version="1.0" />
-->
</dependencies>
</metadata>
</package>
worked for me.
I am using 2.7.40809.172.
So try:
( Number 1 )
take out your
<dependencies>
(just for kicks)
( Number 2 )
~try a later version of
NuGet.exe
(although based on the documentation, you should be ok)
I pulled
1.0.1-alpha
straight from the documentation.
Start with that, then work your way up to your custom value.
http://docs.nuget.org/docs/reference/versioning
So I took your nuspec , and put it in my demo code.
and it worked! (I'm xml updating the description, fyi, thus the small discrepancy) (see xml below)
But I got a nice "xxx.Web.Mvc.1.0.3-prelrelease1.nupkg" file created.
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>xxx.Web.Mvc</id>
<version>1.0.3-prelrelease1</version>
<authors>xxx</authors>
<owners>xxx</owners>
<projectUrl>https://xxx</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>BuildDate : 2013_10_17__11:29:15</description>
<releaseNotes>NuGet package.</releaseNotes>
<copyright>Copyright 2013 xxx</copyright>
<tags>asmx xxx</tags>
<dependencies>
<dependency id="Microsoft.AspNet.Mvc" version="4.0.30506.0" />
<dependency id="Microsoft.AspNet.Razor" version="2.0.30506.0" />
<dependency id="Microsoft.AspNet.WebPages" version="2.0.30506.0" />
<dependency id="Microsoft.Web.Infrastructure" version="1.0.0.0" />
</dependencies>
</metadata>
</package>
So maybe it has something to do with the "contents", not the spec.
So you can do a "basic" package, like:
.\Package.nuspec
.\content\
.\content\SomeImageFile.png
.\lib\
.\lib\net20\SomeDll.dll
and see if that works with your nuspec file with the pre-release versioning?

NuGet: How to increment nuget package version when any file in the solution changes?

I have a NuGet nuspec file responsible for creating a NuGet package from HelloWorld.Main.dll
and the package version is incremented each time I make a change in HelloWorld.Main project.
What if I want to get the version incremented whenever I make a change to any other project in my solution.
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>HelloWorld.Main</id>
<version>$version$</version>
<title>$title$</title>
<authors>$author$</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes />
<copyright>Copyright 2013</copyright>
<tags>HelloWorld</tags>
<dependencies>
<dependency id="HelloWorld.Helpers" version="[0.0.7,0.1)" />
</dependencies>
</metadata>
</package>
You can increment version number somewhere else and pass it to nuget via param:
NuGet Pack MyPackage.nuspec -Version 1.2.0