SolvedHome Add --prerelease option to dotnet add package

From @yooakim at https://github.com/dotnet/cli/issues/5752

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">                                                   
                                                                                        
  <PropertyGroup>                                                                       
    <TargetFramework>netcoreapp1.1</TargetFramework>                                    
  </PropertyGroup>                                                                      
                                                                                        
  <ItemGroup>                                                                           
    <Folder Include="wwwroot\" />                                                       
  </ItemGroup>                                                                          
                                                                                        
  <ItemGroup>                                                                           
    <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" />                  
                                                                                        
  </ItemGroup>                                                                          
                                                                                        
</Project>                                                                              

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 https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-corefxlab/nuget/v3/flatcontainer/alexa.net/index.json
info :   CACHE https://api.nuget.org/v3-flatcontainer/alexa.net/index.json
info :   GET https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-core/nuget/v3/flatcontainer/alexa.net/index.json
info :   NotFound https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-corefxlab/nuget/v3/flatcontainer/alexa.net/index.json 132ms
info :   NotFound https://dotnetmyget.blob.core.windows.net/artifacts/dotnet-core/nuget/v3/flatcontainer/alexa.net/index.json 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:

66
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...
59
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...
38
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. ...
32
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...
27
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...
27
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...
24
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...
20
Home contentFiles (cs, compile) not working in NetStandard projects.
@emgarten Thanks for your fantastic support Two suggestions Please provide docs! NuGet is essential ...
13
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...
12
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...
11
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 ...
7
Home nuget.exe does not work with msbuild 12 as of 3.5.0 [fixed in 4.0.0]
.. Before NuGet CLI version 3.5.0.1938 We were using the NuGet CLI version 3.4.4.1321 When using ver...
3
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...