Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[source mapping] Having a duplicate source breaks msbuild sdks restore #13471

Open
jeromelaban opened this issue May 29, 2024 · 7 comments
Open
Labels
Area:PackageSourceMapping Issues related to the package source mapping feature Functionality:Restore Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Type:Bug

Comments

@jeromelaban
Copy link

NuGet Product Used

dotnet.exe, Visual Studio Package Management UI

Product Version

8.0.300

Worked before?

unknown

Impact

Other

Repro Steps & Context

  1. Clear all caches: dotnet nuget locals all -c
  2. Create a library: dotnet new classlib -o test01
  3. Change the test01.csproj sdk to be Sdk="MSTest.Sdk/3.3.1"
  4. In %appdata%\NuGet\NuGet.Config. add the following mapping:
<packageSource key="nuget.org">
        <package pattern="System.*" />
</packageSource>
  1. In the test01 folder, create a nuget.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
    </packageSources>
</configuration>
  1. In classlib01, run dotnet restore

Notice that if the custom nuget.config file added in the project folder is removed or the duplicate nuget.org source is removed, the restore succeeds.

Verbose Logs

D:\temp\test01\test01.csproj : error : Could not resolve SDK "MSTest.Sdk". Exactly one of the probing messages below indicates why we could not resolve the SDK. Investigate and resolve that message to correctly specify the SDK.
D:\temp\test01\test01.csproj : error :   SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" returned null.
D:\temp\test01\test01.csproj : error :   Unable to resolve 'MSTest.Sdk (= 3.3.1)' for '.NETStandard,Version=v0.0'. PackageSourceMapping is enabled, the following source(s) were not considered: Microsoft Visual Studio Offline Packages, NuGet official package source.
D:\temp\test01\test01.csproj : error MSB4236: The SDK 'MSTest.Sdk' specified could not be found.
@JonDouglas
Copy link
Contributor

/cc @nkolev92 & @donnie-msft related to #13469

@nkolev92
Copy link
Member

What would you have expected to happen @jeromelaban compared to what the error message tells you today. (we have ideas ourselves, but don't want to lead you towards those :D )

@jeromelaban
Copy link
Author

In itself, the message is does not feel easily actionable. Knowing the cause, I'd intuitively say that it should fail/warn earlier because the source mapping got overridden.

Also, maybe displaying all the known sources would have told that none of the available ones were considered?

@nkolev92
Copy link
Member

Today it says:

Unable to resolve 'MSTest.Sdk (= 3.3.1)' for '.NETStandard,Version=v0.0'. PackageSourceMapping is enabled, the following source(s) were not considered: Microsoft Visual Studio Offline Packages, NuGet official package source.

A more powerful message would be to say "no sources" were considered potentially, because the package is not mapped.
Another idea is to warn the duplicate sources as well.

@jeromelaban
Copy link
Author

jeromelaban commented May 30, 2024

Both messages would help for sure.

Another problem I see here is that the user for unoplatform/uno#16758 (reply in thread) stumbled on this issue had a lot of mappings defined at the user level. It feels like an incorrect use of the source mapping feature, as it forces any new package use to be added to the the mapping list (with errors like #13469). This situation is what led to this particular issue.

@donnie-msft
Copy link
Contributor

had a lot of mappings defined at the user level

I wonder if my rough proposal in #13173 to have NuGet tooling able to create configs that <clear/> (reset) the list of package sources would have prevented creating those at the user-level.
Not the complete solution here, but perhaps a piece of the puzzle.

@jeffkl jeffkl added the Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. label Jun 10, 2024
@Arlodotexe
Copy link

Arlodotexe commented Jul 31, 2024

I was also hitting this issue, getting errors such as

         V:\Windows\components\Converters\src\CommunityToolkit.WinUI.Converters.csproj : error NU1100: Unable to resolve 'Microsoft.Windows.SDK.NET.Ref (= 10.0.22621.37-preview)' for 'net8.0-windows10.0.22621'. PackageSourceMapping i
       s enabled, the following source(s) were not considered: C:\Program Files\dotnet\library-packs, MainLatest, nuget.org.

and

PS V:\Windows> dotnet tool restore
Package Source Mapping is enabled, but no source found under the specified package ID: uno.check. See the documentation for Package Source Mapping at https://aka.ms/nuget-package-source-mapping for more details.

I managed to work around this issue by modifying my %appdata%\NuGet\NuGet.Config. Either removing the packageSourceMapping or pattern matching a wildcard does the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:PackageSourceMapping Issues related to the package source mapping feature Functionality:Restore Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Type:Bug
Projects
None yet
Development

No branches or pull requests

7 participants