how to define dependencies correctly in nuspec - nuget

I created a library for Xamarin forms and I want to publish it as Nuget package. There are several dependencies and in nuspec I used the following notation
<dependencies>
<group targetFramework="netstandard1.1">
<dependency id="NETStandard.Library" version="1.6.1" />
<dependency id="Xamarin.Forms" version="2.5.0.91635" />
<dependency id="Newtonsoft.Json" version="10.0.3" />
</group>
<group targetFramework="MonoAndroid">
<dependency id="Xamarin.GooglePlayServices.Location" version="42.1021.1" />
<dependency id="Xamarin.GooglePlayServices.Places" version="42.1021.1" />
<dependency id="Xamarin.Android.Maps.Utils" version="0.5.0" />
<dependency id="Xamarin.Forms" version="2.5.0.91635" />
<dependency id="Newtonsoft.Json" version="10.0.3" />
</group>
</dependencies>
Now when I reference the nuget package in a project that uses the latest Xamarin Google libraries, I get an error
Detected package version outside of dependency constraint: Xamarin.GooglePlayServices.Location 42.1021.1 requires Xamarin.GooglePlayServices.Basement (= 42.1021.1) but version Xamarin.GooglePlayServices.Basement 71.1620.0 was resolved.
Referencing the Nuget Docs my notation sais: accept all versions greater than or equal to 42.1021.1. So what's the correct notation to include 42.1021.1 and 71.1620.0 as well?

Try adding square brackets to the version to fully restrict the version you are using.
<!-- Accept only version 6.1. -->
<dependency id="ExamplePackage" version="[6.1]" />
<!-- Accepts any 6.x.y version. -->
<dependency id="ExamplePackage" version="[6,7)" />
For more documentation please look here:
https://learn.microsoft.com/en-gb/nuget/concepts/package-versioning#Constraining_Upgrades_To_Allowed_Versions

Related

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 :)

Force nuget to always update a dependency

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.

Nuget Pack with -IncludeReferencedProjects includes itself

My nuget build script,
<BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform);TargetPath=$(OutDir)$(AssemblyName)$(TargetExt)" $(NonInteractiveSwitch) $(PackageOutputSwitch) -IncludeReferencedProjects -verbosity detailed</BuildCommand>
is for some of my projects including the project itself as a dependency. I have no idea why.
outputted nuget spec in the nupkg
<package xmlns="http://schemas.microsoft.com/packaging/2011/10/nuspec.xsd">
<metadata>
<id>Ascend.Data.ServiceBus</id>
<version>1.0.0-pre-2014052105</version>
<title>Ascend.Data.ServiceBus</title>
<authors>Ascend Aps</authors>
<owners>Ascend Aps</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright 2014</copyright>
<tags>Tag1 Tag2</tags>
<dependencies>
<dependency id="AzureWebRole.MessageProcessor.Core" version="1.0.0-CI00028" />
<dependency id="AzureWebRole.MessageProcessor.ServiceBus" version="1.0.0-CI00028" />
<dependency id="S-Innovations.Azure.TableStorageRepository" version="1.0.0-CI00020" />
<dependency id="Unity" version="3.5.1404.0" />
<dependency id="Ascend.Data.ServiceBus" version="1.0.0-pre-2014052105" />
</dependencies>
</metadata>
</package>
By any chance, your solution has a circular dependency? If possible, can you please share a simplified repro project and report an issue on http://nuget.codeplex.com? Thanks.

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?

Ivy downloading more jars than expected

Summary:
Ivy is downloading more jars than I expect and I don't know why.
Details:
I'm converting my project from using Maven Ant Tasks for dependency management to Ivy.
So far, I have done the following:
Installed IvyDE into my Eclipse (Helios)
Created an ivy.xml
Since I was previously successfully using Maven Ant Tasks I copied my
dendencies from my build.xml to the ivy.xml. I made sure to change
the dependency declarations to use the Ivy format (org, name, rev).
Added the IvyDE classpath container to my Eclipse project.
Now when I run Ivy > Resolve in Eclipse I can see that 279 jars are downloaded to ".ivy2\cache". This is way more than the 65 jars the Maven Ant Tasks were previously downloading.
Why is Ivy bringing down so many more jars? I understand that Ivy is also bringing down source and some javadoc jars. That explains some of the extra jars but I figure at most Ivy should download 195 jars (65*3) not 279.
What am I missing or doing wrong? I'd appreciate any feedback and suggestions.
Here's the contents of my ivy.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info
organisation="org.robbins"
module="FlashCardsWeb"
status="integration">
</info>
<dependencies>
<dependency org="org.apache.struts" name="struts2-core" rev="2.2.3"/>
<dependency org="org.apache.struts" name="struts2-spring-plugin" rev="2.2.3">
<exclude org="org.springframework" name="spring-web" />
<exclude org="org.springframework" name="spring-beans" />
<exclude org="org.springframework" name="spring-context" />
<exclude org="org.springframework" name="spring-core" />
</dependency>
<dependency org="org.springframework" name="spring-web" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-beans" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-context" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-core" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-jdbc" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-orm" rev="3.0.5.RELEASE"/>
<dependency org="org.apache.struts" name="struts2-tiles-plugin" rev="2.2.1.1"/>
<dependency org="com.jgeppert.struts2.jquery" name="struts2-jquery-plugin" rev="3.0.1"/>
<dependency org="com.jgeppert.struts2.jquery" name="struts2-jquery-richtext-plugin" rev="3.0.1"/>
<dependency org="org.hibernate" name="hibernate-core" rev="3.6.2.Final"/>
<dependency org="org.hibernate" name="hibernate-c3p0" rev="3.6.2.Final"/>
<dependency org="org.hibernate" name="hibernate-entitymanager" rev="3.6.2.Final"/>
<dependency org="org.hibernate" name="hibernate-tools" rev="3.2.4.GA"/>
<dependency org="c3p0" name="c3p0" rev="0.9.1"/>
<dependency org="org.slf4j" name="slf4j-simple" rev="1.6.1"/>
<dependency org="commons-logging" name="commons-logging" rev="1.0.4"/>
<dependency org="mysql" name="mysql-connector-java" rev="5.1.15"/>
<dependency org="junit" name="junit" rev="4.8.1"/>
<dependency org="log4j" name="log4j" rev="1.2.14"/>
<dependency org="org.openid4java" name="openid4java-nodeps" rev="0.9.6" />
<dependency org="org.apache.httpcomponents" name="httpclient" rev="4.0" />
<dependency org="net.sourceforge.nekohtml" name="nekohtml" rev="1.9.10" />
</dependencies>
I had a similar issue and found this mail message helped.
The problem is that if you don't specify any conf, Ivy assumes you want all
the configurations of spring, which includes the optional conf. Try that
instead:
<dependency org="org.springframework" name="spring" rev="2.0.3"
conf="*->default"/>
http://mail-archives.apache.org/mod_mbox/ant-ivy-user/200703.mbox/%3C635a05060703310946q2f50880aqe07219c9e3026b83#mail.gmail.com%3E