SolvedHome Add --prerelease option to dotnet add package

From @yooakim at

I'm not sure this is a bug but it would be nice if one could add NuGet packages with the -pre version as used by NuGet.

Steps to reproduce

dotnet add package Swashbuckle --version pre

Expected behavior

<Project Sdk="Microsoft.NET.Sdk.Web">                                                   
    <Folder Include="wwwroot\" />                                                       
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />                 
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />             
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />   
    <PackageReference Include="Swashbuckle" Version="6.0.0-beta902" />                  

Actual behavior

C:\Code\Coach\src\Coach.API [master]> dotnet add package Swashbuckle --version pre
Microsoft (R) Build Engine version 15.1.545.13942
Copyright (C) Microsoft Corporation. All rights reserved.

  Writing C:\Users\Joakim\AppData\Local\Temp\tmp2F1A.tmp
error: 'pre' is not a valid version string.

## Environment data
`dotnet --info` output:
17 Answers

✔️Accepted Answer

At the very least the error message needs to change. This is the current experience:

$ dotnet add package Alexa.NET
Microsoft (R) Build Engine version 15.1.523.56541
Copyright (C) Microsoft Corporation. All rights reserved.

  Writing C:\Users\immol\AppData\Local\Temp\tmp9BFC.tmp
info : Adding PackageReference for package 'Alexa.NET' into project 'T:\Test\Test.csproj'.
log  : Restoring packages for T:\Test\Test.csproj...
info :   GET
info :   CACHE
info :   GET
info :   NotFound 132ms
info :   NotFound 135ms
error: Unable to resolve 'Alexa.NET' for '.NETCoreApp,Version=v2.0'.
error: Package 'Alexa.NET' is incompatible with 'all' frameworks in project 'T:\Test\Test.csproj'.

The message implies that the package isn't compatible, not that it cannot be found. FWIW I'm not a fan of the -v <version> number as the sole way to install pre-release packages. The whole point of using the CLI to install the package is so that I don't have to look up the version number on NuGet org. I want to be able to quickly add a package in a sensible version (latest stable).

Ideally, this is how I would like the UX to be:

$ dotnet add package Foo
There are no stable packages for Foo. Consider specifying --pre to install the latest pre-release version.
$ dotnet add package Foo --pre
Installed package Foo 1.0.0-beta-5.

/cc @timheuer @bjorg

Related Issues:

Home extern alias support for NuGet package references
After some experimentation and got it to work Design document From @fubar-coder on April 5 2017 15:5...
Home Package 'NameOfPackage' is incompatible with 'all' frameworks in project
I was surprised by this error as well Clearing NuGet cache fixed the problem. From @bsmayer on April...
Home Package Manager Error: Unable to load the service index for source (bad proxy settings)
For me removing the .nuget folder located in C:\Users\YourNameHere fixed the problem. ...
Home Unhelpful error message when incorrectly using nuspec version tag of nuget pack
This is definitely an error message which could do with some improvement It seems there are two prob...
Home Framework assemblies are no longer added to .nuspec when using the new .csproj project system
Is there any hope of getting this fixed soon? We're ready to merge in .csproj ports on several major...
Home error NU1403: The package Microsoft.CSharp.4.0.1 sha512 validation failed.
My mistake was not locking down my NuGet sources with a NuGet.Config which had this one enabled: Mic...
Home Add --prerelease option to dotnet add package
At the very least the error message needs to change This is the current experience: The message impl...
Home contentFiles (cs, compile) not working in NetStandard projects.
@emgarten Thanks for your fantastic support Two suggestions Please provide docs! NuGet is essential ...
Home dotnet.exe nuget push command now supports -skipDuplicate like nuget.exe did.
To clarify my expectation: #1630 should have included the required changes to dotnet Without that th...
Home Invoke must be called on a background thread
The error is generated by NuGet attempting to execute init.ps1 scripts for packages installed in a p...
Home dotnet restore on 2.1 preview1 throws error instead of warning when project files are "missing"
I have fixed that by changing Docker file from to From @christiansparre on March 8 ...
Home nuget.exe does not work with msbuild 12 as of 3.5.0 [fixed in 4.0.0]
.. Before NuGet CLI version We were using the NuGet CLI version When using ver...
Home Please provide a way to reference package ID and version in .target/.props files
I have the same problem I want to have way to specify package ID and version at my .targets file For...