nuget,nuget-package,nuget-spec , Nuget pack does not honor number of digits on assembly version

Nuget pack does not honor number of digits on assembly version


Tag: nuget,nuget-package,nuget-spec

I need nuget pack to generate a package version with only 3 digits (we want to do semantic versioning on it) but when I call it on a csproj which has an AssemblyVersion attribute set to "1.0.0", the resulting nupkg file ends with version "" in it's metadata (and file name). Why doesn't the command line tool honor the amount of digits specified on the AssemblyVersion attribute?

I started this with a call to nuget spec against the csproj file, which generates a stub nuspec file like this (it actually includes more tags with placeholder values, but I've deleted them since we don't need them):

<?xml version="1.0"?>
<package >
    <releaseNotes>Release notes.</releaseNotes>
    <copyright>Copyright 2015</copyright>

With this nuspec file checked in TFS in the same folder as the csproj file, we can now call pack like this:

nuget pack MyProject.csproj

The project's AssemblyInfo.cs file contains a line to set the version explicitly:

[assembly: AssemblyVersion("1.0.0")]

It is all working perfectly fine, except for the fact that the tool is using 4 digits when it retrieves the assembly version. Even Windows shows the version with only 3 digits when I right click the dll on the file explorer and go to details. Why is NuGet using 4 digits? Am I perhaps missing something obvious?

Hardcoding the version in the nuspec is obviously not ideal, because then we would have to maintain the version number in two different places while they are intended to be always the same. I mean, this was supposed to be the idea behind the special placeholder value $version$ there that NuGet itself knows how to extract from the project.


In the Creating and Publishing a Package it is stated that NuGet uses AssemblyVersionAttribute attribute when the token $version$ is used.
Digging into NuGet source code, I've found that it's not as straight forward as one might think.

NuGet uses reflection to get your library's version. AssemblyName.Version to be exact. Since all components of the version must be integers greater than or equal to zero (see AssemblyName.Version), the version presented is (in your case) rather than 1.0.0 as declared in your AssemblyVersion attribute.

Possible solution
The Nuspec Reference page adds more information next to the $version$ token. It mentions AssemblyInformationalVersionAttribute attribute will get precedence over AssemblyVersionAttribute. Using it will solve your problem.

Digging deeper
You might wonder why would AssemblyInformationalVersionAttribute work and AssemblyVersionAttribute won't?

The answer to that question is that NuGet uses CustomAttributeData.GetCustomAttributes(Assembly) function to retrieve the attributes of your library, before it uses Assembly.Version. The above function will not list AssemblyVersionAttribute, yet it will list AssemblyInformationalVersionAttribute if it was used on the assembly. Only then, if AssemblyInformationalVersionAttribute wasn't found, Assembly.Version will be used.

Relevant NuGet source code:
NuGet uses the following code to get the assembly version (if AssemblyInformationalVersionAttribute wasn't found):

Assembly assembly = Assembly.ReflectionOnlyLoadFrom(path);
AssemblyName assemblyName = assembly.GetName();
version = new SemanticVersion(assemblyName.Version);

The problem starts with assembly.GetName() as it creates and initializes AssemblyName with relevant parameters, including the version.
(That code can be found in AssemblyMetadataExtractor class, under public AssemblyMetadata GetMetadata(string path) function.)


NuGet - Dependee project referencing different DLL according to selected build configuration

I'm completely new to NuGet and just researching/proof-of-concept'ing it at the moment: Is it possible to package a NuGet package in such a way that the dependee project (the one that has the dependency) references a different DLL according to the project configuration build? Example: Dependee-Debug.DLL -> References Dependency-Debug.DLL Dependee-Release.DLL...

NuGet Package Manager Console Command Fails But Search -> Install Works

I was just installing a new package thats not in my local cache. I took the command directly from the NuGet site. Executing the command in the PMC failed with the following error: The source at All [(Aggregate source)] is unreachable. Falling back to NuGet Local Cache at C:\Users\Jammer\AppData\Local\NuGet\Cache Install-Package...

Can't open namespaces in a Nuget package

I did the following: Create a new F# project in VS2013 In Package Manager Console, execute while targetting the new project: Install-Package FSharp.Azure.StorageTypeProvider In the file, type: open FSharp.Azure.StorageTypeProvider can be seen in the examples included in the Github project. But I get the error: "The namespace or module...

Proget Server Up but Feed Inaccessible in Visual Studio

We have reinstalled ProGet as we rebuilt our server after a security hole was discovered (unrelated to ProGet). The feed is visible in the browser, but inaccessible in Visual Studio. While rebuilding our server, we have ProGet running on a temporary Azure server, which is working and serving our NuGet...

NuGet on mono behind proxy not able to connect to the internet

I have a Linux machine behind a corporate proxy. For the proxy I have setup CNTLM to handle the authentication for me, so my proxy is located at http://localhost:3128. CNTLM connects to a corporate proxy that uses NTLMv2. Now when I try to run Nuget on Mono with the following...

C# sqlite Unable to load sqlite3.dll

I have used nuget to install sqlite-net and System.Data.SQLite (x86/x64). I have rebuilt and I have restarted and I still get the following error: Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E). This is the line that triggers it: db = new...

LocalPackageRepository returns IsLatestVersion=true for all packages

I've created a folder on my C:\packages. Inside I've created two packages with identical Ids but have different versions. I the use Nuget.Core to create a LocalPackageRepository pointing to this directory. When I query for the packages using respository.FindPackages("myId")both packages are correctly returned by the service. However, the IsLatestVersion is...

Nuget-deployed C# files excluded from Resharper analysis

I'm having trouble understanding a behaviour of Nuget. I've created a basic package that deploys a single Test.cs file into an "HtmlHelpers" folder in a project. I'm following the "convention based working directory" method described on the Nuget site. The issue I'm having is Resharper file analysis isn't enabled for...

Where to find Microsoft.VisualStudio.QualityTools.WebTestFramework

I am missing a reference to this .dll file and I can't find it from the add references tab, it is not there in both extensions and frameworks and neither nuget package manager lists it.

How to pass credentials when accessing a Nuget feed

I am trying to download packages from a Nuget repository which requires credentials for it to be accessed using NuGet.Core. I know that Nuget repositories with no authentication can be accessed as follows: //ID of the package to be looked up string packageID = "EntityFramework"; //Connect to the official package...

How to install Visual Studio Gallery extensions from command line

TL;DR Is there a way to access Visual Studio Gallery from command line, similar to chocolatey? I am trying to configure a Visual Studio dev environment using Vagrant. Now, team members use various extensions available from Visual Studio Gallery and it would be great if they could script their installation...

Trying to add non-.NET libraries to NuGet package

I have a .NET DLL that is using non-.NET DLLs. I'm trying to create a NuGet package out of this, but I don't seem to be penetrating the magic behind this. I read the NuGet reference about the <files> and <references> but that didn't really work out for me -...

Given two C# projects on the same base directory, how to use different packages.config for each

I have two projects (*.csproj) on the same directory (I am porting and this seems like a good workflow) however the problem is that I can only have 1 packages.config on the folder. I have tested having the project on a different folder and linking the files I need, however,...

Can I use my OctopusDeploy built-in Package Repository in Manage NuGet Packages?

I have a working Octopus Deploy server which has a library of packages I built. I have an assembly which depends on one of the assemblies which I have deployed in Octopus Deploy and which is currently in that repository. I tried adding it as a package source in NuGet...

“Unable to satisfy package dependency constraints” with Breeze.Server.WebAPI2

I am trying to add the Breeze.Server.WebAPI2 Nuget package to Visual Studio Community 2015 RC. When I click on install I get "Unable to satisfy package dependency constraints" The listed dependencies are: Microsoft.AspNet.WebApi.OData (>= 5.2.2 && < 6.0.0) Microsoft.AspNet.WebApi.WebHost (>= 5.2.2 && < 6.0.0) Breeze.Server.ContextProvider (=1.5.4) WebActivator I tried adding...

WPF 'Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.'

My application runs fine in VS 2010 but when I copy the executable from the bin folder to another location I get this error: 'Set property 'System.Windows.ResourceDictionary.DeferrableContent' threw an exception.' Line number '15' and line position '23'. Did a bit of testing and found out that if I include the...

“ExcelReaderFactory.cs not found” Error

I've downloaded ExcelDataReader from the Visual Studio Package Manager Console and followed the C# instructions on its Code Plex page, but, during run-time, I get an "ExcelReaderFactory.cs not found" message when the code fails at the ExcelReaderFactory. The entirety of my code block is below. I've tried removing and...

cURL with Visual Studio 2013

So i have came along with cURL as a very nice library and working very fine in OSX. But on windows now i have got big troubles with getting ready with this library. I googled now for about 2 days and tried over a dozen (in detail) different ways to...

How to disable automatic Nuget Package Update in Xamarin

How to disable automatic Nuget Package updates in Xamarin 5.9 (build 539) when opening a new Project?

NuGet fails to find existing package

How it's possible that NuGet's Install-Package fails with Unable to find version 'x' of package 'y' when that exact version is released as NuGet to official repository and it shown on the page. Here is specific sample with content and NuGet Install-Package command output. UPDATE. Package sources are...

NuGet Entity Framework 6.1.3 as default not 7 Beta 4

Today I updated Visual Studio 2013 from Update1 to Update4 and the last version of NuGet. Now all time when I create a new solution, as default installs the Entity Framework 7 Beta 4 and I'm forced to change it in every new solution from NuGet Package Manager. There is...

How to change CopyToOutputDirectory on project reference via powershell

I created a nuget package which contains 3rd party assemblies so that I don't have to put them in a lib folder in every repo where I want to reference them. The nature of the 3rd party libraries is that I cannot have their references set to copy to the...

Visual Studio 2015, Nuget and “same key has already been added.”

I have Visual Studio 2015 RC. When I open a console app or a Windows Phone 8 Silverlight project, everything works fine, I can use Nuget without problems. When I open a Universal App project (Windows 8.1 + Windows Phone 8.1), Nuget breaks. When I open the Nuget console, I...

NuGet restore unable to resolve host 'www.nuget'

I am trying to use the nuget restore command to restore NuGet packages on a CI server. I can run it locally without issue, but on the server I am getting a number of warnings (errors, really): WARNING: The remote name could not be resolved: 'www.nuget' WARNING: The remote name...

New Automatic NuGet package resotore and NuGet.Config

I'm migrating to new version of Automatic package restore as described in docs This documents says, that .nuget folder should be removed completely. Including NuGet.Config, that contained a property, we need: <config> <add key="repositoryPath" value="..\..\..\commonNugetPackages" /> </config> So how one should specify path where packages should be restored? Update: Updating...

How to create a powershell script that triggers a NuGet Update-Package –reinstall?

I have a nuget spec that installs both library file (dll) and two zip packages on a specific folder. Updating the packages is no issue when doing it from Visual Studio 2013 manually. However, when it is being triggered from either our CI servers TeamCity and CCNet, it is only...

Visual Studio 2013 - Setting up Nuget packages for every project

I want all of our future projects to use Bootstrap LESS and other nuget packages. Rather than supply a document to all my team members and hope they remember to set it up, am I able to create a skeleton project then template it so it appears under File ->...

How do i reset nuget and start afresh?

here's what's happening. within the last few days something happened to my solution that apparently broke nuget. when i go into package manager/installed and do a find on SignalR, nothing comes back as if SignalR wasn't installed when i know it is. when i go into manager/online and do the...

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...

Add reference to same Nuget package but for different targets

I have a solution in Visual Studio 2013 with more C# project files that have source code in common but are targeting for different platforms (.Net, WinRT, .Net Micro Framework and so on). All the csproj files are under the same directory. These projects use a Nuget package that is...

VS Online Build - Publish to local NuGet feed

I'm trying to migrate from running Team Foundation Server locally to VS Online. I need to set up a build that will publish a nuget package to our local feed. Is this possible? I assume I need to set up VPN or something. I'm not even sure where to start....

Can not download nuget packages

I'm getting the following error: WARNING: The ServicePointManager does not support proxies with the https scheme. This started happening randomly. I'm not behind a proxy, and restarting did not fix anything....

Can't build a project with Postsharp 4.1.14

I have a project which references a postsharp 4.1.14. When I build a project the error occurred. Postsharp is installed by nuget package. There is .net version 4.0 installed on computer, but Microsoft.Build.Utilities.ToolLocationHelper.GetPlatformSDKLocation method is from .net 4.5. Can I use different version of postsharp? Is there another way to...

Can't reinstall package

On a new Win8.1 reinstall, with all of my code restored from backup, I'm suddenly now getting a yellow NuGet warning when I issue the command update-package -reinstall -project ui: Skipped reinstalling package 'AeroWizard 2.0.9' in project 'Ui' because the package does not exist in the package source. I'm using...

Editing Nuget Package C# Helixtoolkit.WPF

I am using the Helixtoolkit.WPF in my C# program. I have imported the NuGet package and it is working perfectly. However, I am wanting to edit one of the files, specifically GridLinesVisual.cs. I want to change how one of the functions in that file operates, but can’t seem to get...

Tab completion for array not shows after first selection

This is a script for VS PowerShell. function global:Add-Shape { param([string]$Shape, [string[]]$Colors) Write-Host "Shape Name:$Shape" foreach ($i in $Colors) { Write-Host "Color Name:$i" } } Register-TabExpansion 'Add-Shape' @{ 'Shape' = { "Circle", "Square", "Triangle" } 'Colors' = { "Brown", "Red", "Blue" } } In Package Manager Console When I try...

How can I stop my ClickOnce install from requiring Newtonsoft.Json v4.5 in the GAC?

We have a ClickOnce deployment of a WPF desktop application, and recently installed the Newtonsoft.Json version 6.0.8 nuget package. After making this change and publishing the ClickOnce deployment, users can't run the update, because of this error message: The first thing that strikes me as odd is the dependency on...

how to create nuspec file in specific folder?

I tried to create .nuspec file in a different folder by giving path but it is giving me error Nuget.exe spec ..\MYDEMOFOLDER Nuget.exe pack ..\MYDEMOFOLDER\MYPROJECT.csproj pause want to create MYPROJECT.nuspec in ..\MYDEMOFOLDER folder location getting error to create nuspec file The package ID '..\MYDEMOFOLDER' contains invalid characters. Examples of valid...

Package Manager in VS2015 RC fails on installing/restoring some packages

I'm trying to install a nuget package - NGenerics.1.4.1 from ( into a ASP.NET 5 project (website). Package Manager fails with UriFormatException. After that a reference is added into Reference folder in the Solution Explorer but with yellow triangle ('warning'). The error added into the Error List: "Dependency NGenerics...

Unable to add any nuget dependency with ASP.NET 5

I've just downloaded Visual Studio Enterprise 2015 RC and I'm trying to create a simple ASP.NET 5 application. But each time i'm modifying the project.json to add a dependency, I always have an error. For example, when adding a dependency to Newtonsoft.Json I have : "Dependency Newtonsoft.Json >= 6.0.8 could...

Github and Nuget packages

I am attempting to contribute to a project on Github (First time). I added a new Project to the solution and added NUnit and AutoFixture (via Nuget), now when I clone that repo it's missing all of the references to NUnit and AutoFixture. Now when I did a pull request...

Forked a project but what is .pp?

Sorry if this is not the right place to post this type of question...if it's supposed to be on another site please let me know or feel free to close. I've got a simple question about github. I am very new to it and "forked" a project I wanted to...

An error occurred while configuring the solution to restore NuGet packages on build. The operation has timed out

When I right-click my solution and click "enable nuget package restore" I get the message: Configuring the solution to restore NuGet packages on build... And after that the error: An error occurred while configuring the solution to restore NuGet packages on build. The operation has timed out What can it...

nuget security - malware installed by nuget packages?

Is it possible that you can be infected with malware by installing nuget packages? This is especially interesting when you think of Microsoft Visual Studio 2016 which will be fully dependent on Nuget....

Link error: Installing boost zlib filters using NuGet in Visual Studio (2012)

I've installed these packages: boost boost-vc110 boost_iostreams_zlib zlib But the linker is unable to find the required lib: 2>LINK : fatal error LNK1104: cannot open file 'libboost_zlib-vc110-mt-1_58.lib' Is there a way to fix this problem manually by changing the file name or am I still missing a package?...