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

MSBuild SDK Resolver installing package into user-wide globalPackagesFolder, not project specific one #14003

Open
wasabii opened this issue Dec 17, 2024 · 1 comment
Labels
Product:MSBuildSDKResolver The NuGet powered SDK resolver. Owned by MSBuild team Type:Bug WaitingForCustomer Applied when a NuGet triage person needs more info from the OP

Comments

@wasabii
Copy link

wasabii commented Dec 17, 2024

NuGet Product Used

dotnet.exe

Product Version

9.0.0

Worked before?

No

Impact

It bothers me. A fix would be nice

Repro Steps & Context

I have a custom nuget.config file located in a parent directory to a number of project files. These project files reference a custom MSBuild SDK. The goal is for this project to have it's own private nuget packages directory and source directory. They get cleared on each run. This is a testing framework for a custom SDK.

The file is generated for each run and looks like this:

<configuration>
  <config>
    <add key="globalPackagesFolder" value="C:\Users\jhaltom\AppData\Local\Temp\IKVM.Clang.Sdk.Tests\cfee2923-e131-4371-b914-6f651a0c591b\nuget\packages" />
  </config>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="dev" value="D:\ikvm-clang\src\IKVM.Clang.Sdk.Tests\bin\Debug\net8.0\nuget" />
  </packageSources>
</configuration>

When MSBuild tries to restore the SDK, however, it places it in my default global package cache:

Installed IKVM.Clang.Sdk 1.0.0-dev0 from D:\ikvm-clang\src\IKVM.Clang.Sdk.Tests\bin\Debug\net8.0\nuget to D:\packages\NuGet\cache\ikvm.clang.sdk\1.0.0-dev0 with content hash xkcFGoQx+RDM/u6YbF1JsjrMzlaIyhpRIqg5e3DhthuaOIVsSVU3+Sk9zptaDe1eCmvS4/n5E3yXAJvZ/sLh7A==.

As you can see from this message, it grabbed the package from the correct source location. But it is extracting it to the wrong location.

@baronfel (on DotNetEvolution) did a check to see if the MSBuild code loaded the settings correctly. He affirms it does so and advised me to open this bug.

Verbose Logs

I do have a very large log file, but there are only a handful of messages related to SDK resolution:

TestContext Messages:
TestRoot: D:\ikvm-clang\src\IKVM.Clang.Sdk.Tests\bin\Debug\net8.0\Project
TempRoot: C:\Users\jhaltom\AppData\Local\Temp\IKVM.Clang.Sdk.Tests\cfee2923-e131-4371-b914-6f651a0c591b
WorkRoot: D:\ikvm-clang\TestResults\Deploy_JeromeHaltom 20241217T114937\IKVM.Clang.Sdk.Tests\ProjectTests
Build started.
Process = "C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Current\Bin\MSBuild.exe"
MSBuild executable path = "C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Current\Bin\MSBuild.exe"
Command line arguments = ""C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Current\Bin\MSBuild.exe"  /noconsolelogger /v:diag /target:Restore /property:ProvideCommandLineArgs="true";GenerateResourceMSBuildArchitecture="CurrentArchitecture";ResolveNuGetPackages="true";CreateHardLinksForCopyAdditionalFilesIfPossible="true";SolutionDir="D:\ikvm-clang\src\IKVM.Clang.Sdk.Tests\bin\Debug\net8.0\Project\Executable\\";CreateHardLinksForPublishFilesIfPossible="true";CreateHardLinksForAdditionalFilesIfPossible="true";CreateHardLinksForCopyFilesToOutputDirectoryIfPossible="true";ImportDirectoryBuildTargets="false";CreateHardLinksForCopyLocalIfPossible="true";ImportDirectoryBuildProps="false";Configuration="Debug";PackageVersion="1.0.0-dev0";RestorePackagesPath="C:\Users\jhaltom\AppData\Local\Temp\IKVM.Clang.Sdk.Tests\cfee2923-e131-4371-b914-6f651a0c591b\nuget\packages\\" /l:BuildalyzerLogger,"D:\ikvm-clang\src\IKVM.Clang.Sdk.Tests\bin\Debug\net8.0\Buildalyzer.Logger.dll";4696;True /noAutoResponse "D:\ikvm-clang\src\IKVM.Clang.Sdk.Tests\bin\Debug\net8.0\Project\Executable\Executable.clangproj""
Current directory = "D:\ikvm-clang\src\IKVM.Clang.Sdk.Tests\bin\Debug\net8.0\Project"
MSBuild version = "17.12.12+1cce77968"
Based on the Windows registry key LongPathsEnabled, the LongPaths feature is enabled.
Based on the Windows registry key VerifiedAndReputablePolicyState, SAC state = 0: turned off.
 The "Microsoft.DotNet.MSBuildSdkResolver" resolver attempted to resolve the SDK "IKVM.Clang.Sdk".
Warnings: null
Errors: C:\Program Files\dotnet\sdk\8.0.111\Sdks\IKVM.Clang.Sdk\Sdk not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.

It continues from the above.

 The SDK "IKVM.Clang.Sdk" was successfully resolved by the "NuGetSdkResolver" resolver to location "D:\packages\NuGet\cache\ikvm.clang.sdk\1.0.0-dev0\Sdk" and version "1.0.0-dev0".
Importing project "D:\packages\NuGet\cache\ikvm.clang.sdk\1.0.0-dev0\Sdk\Sdk.props" into project "D:\ikvm-clang\src\IKVM.Clang.Sdk.Tests\bin\Debug\net8.0\Project\Executable\Executable.clangproj" at (2,5).

Each time I clear the global directory and rerun it reextracts the nugpkg into the same incorrect location. Tried clearing it completely.

@jeffkl
Copy link
Contributor

jeffkl commented Dec 17, 2024

The NuGet SDK resolver looks for a NuGet.config next to the solution file if one is specified during the build, or the project. As long as your nuget.config is in that location or a parent folder, it should be found. I was not able to reproduce the issue.

NuGet.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value=".\.nuget\packages" />
  </config>
  <packageSources>
    <clear />
    <add key="nuget" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

Project

<Project Sdk="Microsoft.Build.NoTargets/3.7.56">
  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>
</Project>

Output:

Restoring packages for C:\Users\jeffkl\AppData\Local\Temp\NuGetScratch\bbb19f4d5a7b4e108cf78b65e30cb544\a9f5c9771482462d8db68793f34619e9.proj...
  GET https://api.nuget.org/v3-flatcontainer/microsoft.build.notargets/index.json
  OK https://api.nuget.org/v3-flatcontainer/microsoft.build.notargets/index.json 204ms
  GET https://api.nuget.org/v3-flatcontainer/microsoft.build.notargets/3.7.56/microsoft.build.notargets.3.7.56.nupkg
  OK https://api.nuget.org/v3-flatcontainer/microsoft.build.notargets/3.7.56/microsoft.build.notargets.3.7.56.nupkg 43ms
Installed Microsoft.Build.NoTargets 3.7.56 from https://api.nuget.org/v3/index.json to D:\Repros\resolver-globalpackages\.nuget\packages\microsoft.build.notargets\3.7.56 with content hash eBY34zRl5Xj9MNGpeVL9XlERh//x6J1nqVqc1hGRtUKvYsbNTJLgMlDtyrOaf8jBoboybyjoyCC0hDQ/i9ulNw==.
  GET https://api.nuget.org/v3/vulnerabilities/index.json
  OK https://api.nuget.org/v3/vulnerabilities/index.json 19ms
  GET https://api.nuget.org/v3-vulnerabilities/2024.12.13.05.09.02/vulnerability.base.json
  GET https://api.nuget.org/v3-vulnerabilities/2024.12.13.05.09.02/2024.12.17.11.09.16/vulnerability.update.json
  OK https://api.nuget.org/v3-vulnerabilities/2024.12.13.05.09.02/vulnerability.base.json 64ms
  OK https://api.nuget.org/v3-vulnerabilities/2024.12.13.05.09.02/2024.12.17.11.09.16/vulnerability.update.json 87ms

Result:

│   nuget.config
│
├───.nuget
│   └───packages
│       └───microsoft.build.notargets
│           └───3.7.56
│               │   .nupkg.metadata
│               │   .signature.p7s
│               │   microsoft.build.notargets.3.7.56.nupkg
│               │   microsoft.build.notargets.3.7.56.nupkg.sha512
│               │   microsoft.build.notargets.nuspec
│               │   MSBuild-NuGet-Icon.png
│               │
│               └───Sdk
│                       DisableCopyFilesMarkedCopyLocal.targets
│                       Sdk.props
│                       Sdk.targets
│
└───ClassLibrary1
        Class1.cs
        ClassLibrary1.csproj

ClassLibrary1.zip

Is your NuGet.config in the correct location? Are you able to provide a ZIP that we can use to reproduce the problem and investigate further?

@jeffkl jeffkl added the WaitingForCustomer Applied when a NuGet triage person needs more info from the OP label Dec 17, 2024
@nkolev92 nkolev92 added Product:MSBuildSDKResolver The NuGet powered SDK resolver. Owned by MSBuild team and removed Triage:Untriaged labels Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Product:MSBuildSDKResolver The NuGet powered SDK resolver. Owned by MSBuild team Type:Bug WaitingForCustomer Applied when a NuGet triage person needs more info from the OP
Projects
None yet
Development

No branches or pull requests

3 participants