[CSHARP-3798] Cannot install 2.13.1 MongoDB.Driver in latest Visual Studio Code Created: 16/Aug/21  Updated: 27/Oct/23  Resolved: 16/Aug/21

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Unknown
Reporter: Torsten Spindler Assignee: James Kovacs
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to CSHARP-4608 cannot install C# driver using Window... Closed

 Description   

Hello,

I've tried to write a 'hello world' like C# application for MongoDB and I'm blocked on installing the MongoDB.Driver:

 

PS C:\Users\User\Documents\csharp> dotnet add package MongoDB.Driver --version 2.13.1
Determining projects to restore...
Writing C:\Users\User\AppData\Local\Temp\tmp8F31.tmp
info : Adding PackageReference for package 'MongoDB.Driver' into project 'C:\Users\User\Documents\csharp\csharp.csproj'.
info : Restoring packages for C:\Users\User\Documents\csharp\csharp.csproj...
error: NU1100: Unable to resolve 'MongoDB.Driver (>= 2.13.1)' for 'net5.0'.
error: Package 'MongoDB.Driver' is incompatible with 'all' frameworks in project 'C:\Users\User\Documents\csharp\csharp.csproj'.

 

The csproj file states:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="MongoDB.Driver" Version="2.13.1"/>
  </ItemGroup>
</Project>

And the only SDK installed is 5.0.400:

dotnet --list-sdks 
5.0.400 [C:\Program Files\dotnet\sdk]

 

Torsten



 Comments   
Comment by James Kovacs [ 16/Aug/21 ]

Thank you for confirming that this fixed your issue.

Comment by Torsten Spindler [ 16/Aug/21 ]

Placing the good NuGet.Config in the right place made it work.

To find the right place I used thanks to your advice
https://docs.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior 

and checked %appdata%\NuGet\NuGet.Config . This file contained:

<?xml version="1.0" encoding="utf-8"?>
<configuration />

When I put your config in, the output of nuget list source was:

dotnet nuget list source 
Registered Sources: 
1. nuget.org [Enabled]
   https://api.nuget.org/v3/index.json

Comment by James Kovacs [ 16/Aug/21 ]

Microsoft relatively recently changed the behaviour of dotnet/nuget to respect empty NuGet.Config files:

https://github.com/NuGet/NuGet.Client/pull/3907
 
Previously an empty package source list would cause dotnet/nuget to add the default nuget.org feed. Recent builds no longer do this.
 
If you haven’t customized ~/.nuget/NuGet/NuGet.Config the easiest solution is to delete this file and let dotnet/nuget recreate it the next time it is run. If you have customized it, then make sure that it looks like this with any additional customizations you might have made:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
</configuration>

Please let us know if this resolves your issue.

Generated at Wed Feb 07 21:46:20 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.