ExcludeVersion for existing NuGet references - nuget

I have seen that NuGet.exe contains an ExcludeVersion flag when installing packages. We have a solutions which already contains a large number of references. For example:
<Reference Include="Microsoft.SqlServer.Smo, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.SqlServer.Scripting.11.0.2100.61\lib\Microsoft.SqlServer.Smo.dll</HintPath>
</Reference>
Is there an easy way to update all of these existing references to not include the version number (11.0.2100.61 above) in the folder path? Originally these references were all added using the package manager in Visual Studio, but I don't see any way of specifying to not include the version number.

Short answer.
No, there is not.
See this:
https://nuget.codeplex.com/workitem/1522
I think you have to:
Run the VS Tool : Uninstall-Package Microsoft.SqlServer.Smo
Run the NuGet command line.....with the ExcludeVersion flag.
C:\WhereeverYouPutThis\NuGet.exe install Microsoft.SqlServer.Smo -ConfigFile "..nuget\nuget.config" -ExcludeVersion
Re-do your references.
Yeah, that stinks.
My nuget.config file looks like this, FYI.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="..\MyPackages" />
</config>
</configuration>

Related

Unable to find version '4.2.1.188' of package 'Glass.Mapper'

I am new to Sitecore and Glass.Mapper tools. I am working with Visual Studio 2013 and Sitecore 8.1 for a solution I have begun working on (not the author).
Due to other questions I have observed, I will try to demonstrate what my solution now has in it to remove build errors.
My packages.config includes the following:
<package id="Glass.Mapper" version="4.2.1.188" targetFramework="net45" />
<package id="Glass.Mapper.Sc" version="4.2.1.188" targetFramework="net45" />
My nuget.config includes the following:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSources>
<add key="nuget v2" value="https://www.nuget.org/api/v2" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
I have added these as project references to each of these Dlls from our Packages directory, which also includes the following in a few of the projects:
<package id="Glass.Mapper.Sc.CastleWindsor" version="3.3.0.25" targetFramework="net45" />
<package id="Glass.Mapper.Sc.Core" version="4.2.1.188" targetFramework="net45" />
<package id="Glass.Mapper.Sc.Mvc-5" version="3.3.0.45" targetFramework="net45" />
Solution errors have been reduced from several hundred to ~20, mostly due to this issue, and the Metadata file "..." could not be found errors which appear since dependent projects fail to generate their project Dlls.
We cannot upgrade Nuget in place, and we cannot perform upgrades using Manage Nuget Packages for Solution due to code in place which references deprecated methods in key packages.
If you browse packages on nuget.org with your web browser, you can guess the pattern for viewing a specific version of a package. So, version 4.2.1.188 of GlassMapper will use the URL https://www.nuget.org/packages/Glass.Mapper/4.2.1.188
There, I see a message saying
The owner has unlisted this package. This could mean that the package is deprecated or shouldn't be used anymore.
So the package exists, so existing packages should be able to restore it, but the owner has delisted it to reduce the probability that new projects will start using it. Interestingly the package owner has delisted all versions of the package, suggesting the package is deprecated.
Anyway, as I mentioned, normally the package can still be restored (that's the point of unlisting vs deleting). So my best guess is that the version of NuGet that works with Visual Studio 2013 doesn't support unlisted packages as it's really, really old.
You could download nuget.exe from nuget.org/downloads, restore from the command line and then use Visual Studio. Otherwise you'll probably need to upgrade to a newer version of Visual Studio.

NuGet.Config packageSources appears to ignore <clear /> since 2.6

Summary: We have a script that runs nuget.exe from the command line within our solutions repository. How can we configure NuGet to only use a specific package source (and not anything listed in the machine-wide or users configuration)?
From the NuGet documentation, one can read the following concerning chaining multiple config files:
NuGet first loads NuGet.config from the default location, then loads
any file named NuGet.config starting from the root of the current
drive and ending in the current directory. (...) When <clear /> is
present for a given node, previously defined configuration items for
this node are ignored.
At the root of our repository, we have added the following NuGet.Config file to make sure we only fetch NuGet packages from out own internal NuGet repository:
<!-- C:\repository_root_path\NuGet.Config -->
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<clear /> <!-- ensure only the sources defined below are used -->
<add key="Internal package source" value="\\network_fileshare\nuget_packages\" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="Internal package source" value="\\network_fileshare\nuget_packages\" />
</activePackageSource>
</configuration>
The problem we're experiencing now, is that this yields different results depending on which version of NuGet.exe we're running. To debug, I've downloaded three separate versions of NuGet.exe and put them all in the .nuget-folder in our solution. The result is as follows:
C:\repository_root_path>Source\.nuget\nuget_2.5.40416.exe sources
Registered Sources:
1. Internal package source [Enabled]
\\network_fileshare\nuget_packages\
C:\repository_root_path>Source\.nuget\NuGet_2.6.40619.exe sources
Registered Sources:
1. NuGet official package source [Enabled]
https://nuget.org/api/v2/
2. Internal package source [Enabled]
\\network_fileshare\nuget_packages\
C:\repository_root_path>Source\.nuget\nuget_2.7.40808.exe sources
Registered Sources:
1. NuGet official package source [Enabled]
https://nuget.org/api/v2/
2. Internal package source [Enabled]
\\network_fileshare\nuget_packages\
3. https://www.nuget.org/api/v2/ [Disabled]
https://www.nuget.org/api/v2/
So the question is: has there been introduced a bug in NuGet between version 2.5 and 2.6 so that the <clear /> element is ignored, or is there something wrong in the NuGet.Config file we have in our solution root?
This has been confirmed as a bug in NuGet. The fix is assigned to release 2.7.2.

Build project - Nuget Error

The error occurs only on one machine.
Attempts
Wrong paths
I thought the path of any source may be wrong, so I opened the NuGet.Config to check and the 3 paths are correct and there!
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<add key="Nightly ASP.NET Web Stack" value="http://www.myget.org/F/aspnetwebstacknightly/" />
<add key="Bind Solution" value="W:\Cloud\Dropbox\Bind Defaults\Nuget Repository" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
</activePackageSource>
</configuration>
Nuget.exe not exist
Checked on .nuget folder and .exe is in the directory!
Checked in Path of windows and there is!
I tried to run the command manually and it run successfully!
nuget install packages.config -source "" -NonInteractive -RequireConsent -solutionDir "W:\C
lients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\ "
Full error:
Error 1 The system cannot find the path specified. CreditoImobiliarioBB.Domain
Error 2 The command ""W:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB.nuget\NuGet.exe" install "W:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\CreditoImobiliarioBB.Model\packages.config" -source "" -NonInteractive -RequireConsent -solutionDir "W:\Clients\creditoimobiliariobb\sistema\src\CreditoImobiliarioBB\ " " exited with code -1. CreditoImobiliarioBB.Domain
Considerations
Only projects that have local packages (Source is key="Bind Solution" value="W:\Cloud\Dropbox\Bind Defaults\Nuget Repository") is that they are in trouble. And recently the location of packages moved to another directory (in this case to W:\Cloud\Dropbox\Bind Defaults\Nuget Repository).
I had a similar problem recently, I fixed it by doing this:
Update Visual Studio to the latest version. (Extensions and Updates - Product Updates)
Update Nugget to the latest version. (Extensions and Updates - Visual Studio Gallery)
Clear the Package Cache. (Options - Package Manager)
Rebuild the solution.
Hope it helps.
I ran into a similar problem with NuGet.exe and WG.exe for WebGrease. I realized that with my Virus Protection turned on, it wasn't allowing the .exe files to come down properly. Once I disabled my Virus Protection, I was able to get everything I need (company is using McAfee).

How to get the myget package source?

I am using myget for my Nuget packages. Because i am using a private feed with credentials, i followed this blog: http://www.xavierdecoster.com/deploying-to-azure-web-sites-using-nuget-package-restore-from-a-secured-feed
My local (project) nuget.config (located in the .nuget folder in the solution) looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSource>
<clear />
<add key="EcareMyGet" value="https://www.myget.org/F/rai69/"></add>
</packageSource>
<activePackageSource>
<add key="EcareMyGet" value="https://www.myget.org/F/rai69/"></add>
</activePackageSource>
<packageSourceCredentials>
<EcareMyGet>
<add key="Username" value="www.myget.org/raimond" />
<add key="ClearTextPassword" value="wachtwoord" />
</EcareMyGet>
</packageSourceCredentials>
</configuration>
In my nuget.targets i've changed the restore command according to the blog:
<RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -NonInteractive $(RequireConsentSwitch) -solutionDir "$(SolutionDir)\" -Verbosity detailed </RestoreCommand>
Despite this, the buildserver is still using nuget.org as source:
NuGet.exe sources
Registered Sources:
1. https://nuget.org/api/v2/ [Enabled]
https://nuget.org/api/v2/
Who knows a solution?
Answer: replace <packageSource> by <packageSources> in the nuget.config file
Below is the conversation that lead to the answer...
Just to be sure, did you also read the part where you disable the -RequireConsent switch?
<RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">
false
</RequireRestoreConsent>
Also, make sure you didn't configure it in the MSBuild PackageSources element, which by default looks as shown below (no package source configured):
<ItemGroup Condition=" '$(PackageSources)' == '' ">
<!-- Package sources used to restore packages.
By default, registered sources under %APPDATA%\NuGet\NuGet.Config
will be used -->
<!-- The official NuGet package source (https://nuget.org/api/v2/) will be
excluded if package sources are specified and it does not appear
in the list -->
<!--
<PackageSource Include="https://nuget.org/api/v2/" />
<PackageSource Include="https://my-nuget-source/nuget/" />
-->
</ItemGroup>
If you did and that's not the issue, can you please share a little more detail about the output logs so I can determine when the issue is caused and by what command?
You write that you use "My local (project) nuget.config", which makes me believe that you have the nuget.config file located in your project folder.
You can read about the NuGet Config File here. There you'll see that "NuGet first loads NuGet.config from the default location, then loads any file named NuGet.config starting from the root of the current drive and ending in the current directory.".
What this means, it that NuGet will look for the configuration in the folder hierarchy all the way from the root and to the location of nuget.exe, which usually is under the .nuget folder in the solution root. This means that it will never look inside the project folders in your solution. So you can try to move your nuget.config to the solution folder, and see it it gets read properly then.

how to specify location of nuget packages when package restore is enabled?

I am working on a .net solution and use nuget for my package management. I have selected the option to "Enable Nuget Package Restore" so that the nuget packages not checked in to source control.
Prior to this I had a nuget.config file at the same level as the solution where I included to following enabling me to specify the location of the nuget packages.
<settings>
<repositoryPath>..\Build\NuGetPackages\</repositoryPath>
</settings>
Since I enabled the nuget package restore, this is no longer working. I tried to update the config file within the .nuget generated folder but that does not work either.
So where I am going wrong and how can I specify the location of the packages folder?
When you enable nuget package restore, there is a NuGet.Config file in the .nuget folder.
Here is a copy showing the path to my libs folder. You can modify yours to match your path. I think its a little cleaner than the already selected answer.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<config>
<add key="repositoryPath" value="../../libs/packages" />
</config>
</configuration>
You can change the next property in your-solution\.nuget\NuGet.targets file:
<PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
Or the same property, but in group below if you are using Mono.
You should also look at the nuget 2.1 release notes here http://docs.nuget.org/docs/release-notes/nuget-2.1, where there is a new setting added to nuget.config to specify package folder location
<configuration>
<config>
<add key=" repositoryPath" value=" C:\myteam\teampackages" />
</config>
...
</configuration>