NuGet version constraints doesn't work - c#-4.0

I have Project which references from NuGet repository Module of version 1.0.0.0.
For some time Module versions are changed to 1.1.0.0, 1.1.0.1, 1.1.1.0, 1.1.5.0, 1.2.0.0, 1.2.1.0. And my Project supports just 1.1.X.X versions set. And the latest version NuGet should upgrade Project reference is 1.1.5.0, but NuGet suggests 1.2.1.0.
Due this article: http://docs.nuget.org/docs/reference/versioning I need to modify packages.config of my Project and set 'allowedVersions' attribute:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Module" version="1.0.0.0" allowedVersions="[1.1,1.2)" />
</packages>
Does NuGet supports constraints on minor versions?
NuGet version is 2.7.41101.299

can you please provide more details about your project type and the packages installed? or a simplified repro app is fine, which will help us diagnosis the issue.
Btw, the latest version of NuGet is 2.7.2, which can be downloaded at http://docs.nuget.org/docs/start-here/installing-nuget. Please see if your issue still reproes with the latest version. Thanks!

Related

Unable to deploy app with nuget references on server

I am having a hard time deploying my first .net core app with nuget references on the server. Locally, the app works absolutely fine (able to use nuget packages).
Apparently, there is no packages.config. I am using Dapper, Newtonsoft.Json, etc. Where is the project storing reference to these packages? There is no packages folder.
In the solutions folder, there is nuget.config file which for some reason is empty.
What should I add here
Unable to deploy app with nuget references on server
That because you are using the old version nuget restore task in the build pipeline, which only supports for the package management type packages.config not PackageReference.
That the reason why the old version task ask you to provide the path to the packages.config. The PackageReference is a follow-up product, so the previous version of nuget restore task does not support it.
Check the blog for some more details.
To resolve this issue, please use the V2 of the nuget restore task:
Note:
The PackageReference needs the nuget.exe 4.1 and above, please add
a NuGet tool installer to install the nuget version above 4.1.
Using .NET Core restore task should be also work for this issue.
Update:
Yes, using TFS 2016
Since you are using TFS 2016, you could try to use the command line to invoke the nuget.exe to restore the package instead of the nuget installer task:
Download the nuget.exe above 4.0 from the nuget.org, then set it on the TFS server.
Hope this helps.
You need to create a NuGet.config file that points to whatever NuGet feed you're using, add it to source control, and reference it in your build. I'll use the official feed for my example. This feed is already present by default if you're developing using Visual Studio, which might explain why the build runs locally but not on Azure DevOps.
At the very least, your NuGet.config file needs to look like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="NuGet.org Feed" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
In .NET Core, packages are now stored globally in your User directory. packages.config has been dropped in favor of the PackageReference node in a project file, so check your csproj to see the NuGets you're referencing.
You should use task dotnetcorecli task which has
#command: 'build' # Options: build, push, pack, publish, restore, run, test, custom

Tfs and nuget: project files are forever in check out after build with restore nuget packages

MS VS 2012
I have solution in tfs with enabled nuget packages restore. Every time when I build solution all my project files are cheked out with this changes:
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
How to fix this behaviour?
As of NuGet v2.7, MSBuild-Integrated Package Restore has been deprecated and replaced with Automatic Package Restore.
See documentation on how to migrate your solution to the new feature: Migrating MSBuild-Integrated solutions to use Automatic Package Restore
To learn more about Automatic Package Restore see
NuGet Package Restore
Both articles discuss how this effects TFS integration.

How to upgrade nuget packages if the installed version is missing?

Running into a situation where I deployed an application to production a few months ago and now I need to do some work on it, on an entirely new machine. The first I do is pull source and nuget restore won't restore because it can't find the particular version of the package it was developed under. When I check nuget.org for this package version it is not there. So how do I upgrade my solution to the latest binaries?
Visual Studio 2013 trying to update ServiceStack '4.0.39' to latest, which is '4.0.40' at the time of this post.
Thank you,
Stephen
The best solution I've come up with for this is to manually edit the Packages.config file(s) and set the version number to whatever you want. Restore should then work. It's not a perfect solution but it has dug me out of some holes.
(I know this is an old answer, but it just came up in some Googling)
One issue with the accepted answer (of just updating the version # in packages.config) is that this is just triggering a "package restore"--and will skip any "installation steps" the package might have (things that were done automatically when you first added the package, such as adding assembly references, modifying config files, etc.).
An alternative way would be to edit the packages.config and REMOVE the package in question from there---then start up VS and add the new version. This will trigger the package's usual install routine to do it's thing.
I recommend you to use the NuGet Package Manager Console of Visual Studio:
TOOLS > NuGet Package Manager > Package Manager Console
Command to update a NuGet package to the latest version:
Update-Package ServiceStack
Command to update a NuGet package to a specific version:
Update-Package ServiceStack -version 4.0.40

Unable to resolve JetBrains.ReSharper.SDK while installing a ReSharper's plugin

I'm trying to install a custom ReSharper's plugin I wrote using the ReSharper Extension Manager but I get the error
Attempting to resolve dependency 'JetBrains.ReSharper.SDK (≥
8.2.1158)'.
Unable to resolve dependency 'JetBrains.ReSharper.SDK (≥ 8.2.1158)'.
I followed the official documentation and here is my .nuspec.
<?xml version="1.0"?>
<package >
<metadata>
<id>CustomMacro</id>
<version>1.0.0.0</version>
<title>Custom macro</title>
<authors>Me</authors>
<description>do something</description>
<copyright>Copyright © 2014</copyright>
<tags>Cool Plugin</tags>
<dependencies>
<dependency id="ReSharper" version="[8.2,8.3]" />
</dependencies>
</metadata>
<files>
<file src="bin\Release\*.dll" target="ReSharper\vAny\vs12.0\plugins" />
</files>
</package>
Note: The nuget packaged is pushed inside my company's nuget repository and when I search for the package in the Extension Manager I do it from Online -> All tag
That .nuspec file looks fine, but doesn't match the error message. The error message indicates that the .nupkg has a dependency on "JetBrains.ReSharper.SDK". ReSharper uses NuGet packages in a runtime capacity, so development dependencies shouldn't be included. When installing, ReSharper will try to resolve any dependencies and install them (as runtime extensions, not assembly references). The "JetBrains.ReSharper.SDK" package is a nuget assembly reference package, and isn't required, or available on ReSharper's extension package gallery, so it fails to install.
I'd suggest getting NuGet Package Explorer and double clicking on the .nupkg to see if it's got the same .nuspec as you've shown.
Also, you should be copying the *.dll files into ReSharper\v8.2\plugins. It can't live in vAny because ReSharper plugins are compiled against specific versions of ReSharper. And it should only go in the vs12.0 folder if it's specific to Visual Studio 2013, i.e. it uses VS2013 assemblies and functionality.

MvvMCross 3.0.6 Nuget package installation issue

I am trying to install MVVMCross NuGet package using NuGet 2.5 version. I have added the mono android and touch file to Profile104 folder. Still I am getting following exception:
Attempting to resolve dependency 'MvvmCross.HotTuna.StarterPack (≥ 3.0.6)'.
Attempting to resolve dependency 'MvvmCross.HotTuna.CrossCore (≥ 3.0.6)'.
Attempting to resolve dependency 'MvvmCross.PortableSupport (≥ 3.0.6)'.
Installing 'MvvmCross.PortableSupport 3.0.6'.
Successfully installed 'MvvmCross.PortableSupport 3.0.6'.
Installing 'MvvmCross.HotTuna.CrossCore 3.0.6'.
Successfully installed 'MvvmCross.HotTuna.CrossCore 3.0.6'.
Installing 'MvvmCross.HotTuna.StarterPack 3.0.6'.
Successfully installed 'MvvmCross.HotTuna.StarterPack 3.0.6'.
Installing 'MvvmCross 3.0.6'.
Successfully installed 'MvvmCross 3.0.6'.
Adding 'MvvmCross.PortableSupport 3.0.6' to PortableClassLibrary1.
Uninstalling 'MvvmCross.PortableSupport 3.0.6'.
Successfully uninstalled 'MvvmCross.PortableSupport 3.0.6'.
Install failed. Rolling back...
Could not install package 'MvvmCross.PortableSupport 3.0.6'.
You are trying to install this package into a project that targets
'portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp', but the
package does not contain any assembly references or content files that
are compatible with that framework. For more information, contact the
package author.
I have selected following option when creating a new PCL Library project
Following are the content for the xml files from C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.0\Profile\Profile104\SupportedFrameworks folder
.NET for Windows Store apps.xml
<?xml version="1.0" encoding="utf-8"?>
<Framework
Identifier=".NETCore"
Profile="*"
MinimumVersion="4.5"
DisplayName=".NET for Windows Store apps"
MinimumVersionDisplayName="" />
.NET Framework 4.5
<?xml version="1.0" encoding="utf-8"?>
<Framework
Identifier=".NETFramework"
Profile="*"
MinimumVersion="4.5"
DisplayName=".NET Framework"
MinimumVersionDisplayName="4.5" />
MonoAndroid.xml
<?xml version="1.0" encoding="utf-8"?>
<Framework DisplayName="Mono for Android"
Identifier="MonoAndroid"
Profile="*"
MinimumVersion="1.6"
MaximumVersion="*" />
MonoTouch.xml
<?xml version="1.0" encoding="utf-8"?>
<Framework
DisplayName="MonoTouch"
Identifier="MonoTouch"
Profile="*"
MaximumVersion="*"
MinimumVersion="4.0" />
Silverlight 4.xml
<?xml version="1.0" encoding="utf-8"?>
<Framework
Identifier="Silverlight"
Profile=""
MinimumVersion="4.0"
DisplayName="Silverlight"
MinimumVersionDisplayName="4" />
VSMonoTouch.xml
<?xml version="1.0" encoding="utf-8"?>
<Framework DisplayName="VS MonoTouch"
Identifier=".NETFramework"
Profile="*"
MinimumVersion="1.0"
MaximumVersion="1.0" />
Windows Phone 7.5.xml
<?xml version="1.0" encoding="utf-8"?>
<Framework
Identifier="Silverlight"
Profile="WindowsPhone7*"
MinimumVersion="4.0"
DisplayName="Windows Phone"
MinimumVersionDisplayName="7.5" />
I am using Visual Studio 2012 Ultimate Update 2 on Windows Server 2012 64 bit edition. Can someone point me in right direction.
It looks like you are targeting Windows Phone 7.0 in your Portable Class Library. Try switching to Windows Phone 7.5 and see if that helps. If not, try posting a screenshot of the PCL "choose targets" screen, as well as the contents of all the XML files you've added to the "SupportedFrameworks" folder.
EDIT: Try deleting VSMonoTouch.xml (and restarting Visual Studio afterwards).
The workaround mentioned on a comment on Stuart's blog (at http://slodge.blogspot.co.uk/2013/04/n0-first-mvvmcross-application-n1-days.html) worked for me:
Remove Mono for Android, MonoTouch, VS MonoTouch and Windows Phone from the Target Frameworks in the Core project properties. Install MvvmCross NuGet package. Add the Target Frameworks back in.
I just got an update to the NuGet.
It looks like it's working now.
Here are the steps to have MVVM Cross on a new project:
Create a new project Xamarin Android
Create a new project PCL library (select Mono Android, MonoTouch, and Windows Phone 7.5 and higher).
Add MVVMCross NuGet on both the app and PCL
Add the library as reference to the app
Without adding the MVVMCross also to the app, I get an error on compilation.
I have the same issue
Could not install package 'MvvmCross.PortableSupport 3.0.6'. You are
trying to install this package into a project that targets
'portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp71', but the
package does not contain any assembly references or content files that
are compatible with that framework. For more information, contact the
package author.
Per http://slodge.blogspot.co.uk/2013/04/my-current-pcl-setup-in-visual-studio.html, I do not have VSMonoTouch, just the two files (MonoAndroid,Version=v1.6+.xml and MonoTouch,Version=v1.0+.xml)
I also tried to
"Remove Mono for Android, MonoTouch, VS MonoTouch and Windows Phone from the Target Frameworks in the Core project properties. Install MvvmCross NuGet package. Add the Target Frameworks back in."
But when I try to compile, I get this error:
Error 1 Exception while loading assemblies:
System.IO.FileNotFoundException: Could not load assembly
'System.Windows, Version=2.0.5.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e'. Perhaps it doesn't exist in the Mono
for Android profile? File name: 'System.Windows.dll' at
Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(AssemblyNameReference
reference, ReaderParameters parameters) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List1
assemblies, AssemblyDefinition assembly) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List1
assemblies, AssemblyDefinition assembly) at
Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(List`1
assemblies, AssemblyDefinition assembly) at
Xamarin.Android.Tasks.ResolveAssemblies.Execute() MyProject
I face this issue too. After googling to find solution I found that I use Nuget version 2.4
I upgrade my nuget to 2.6 and it run smoothly.
You can download nuget 2.6 here: Nuget 2.6
I wrote a step by step post for creating a simple Android app from scratch using PCL
http://enginecore.blogspot.ro/2013/05/first-app-with-xamarin-android-and.html

Resources