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

MSBuildSdkResolver failure when attempting to pack non-SDK project #12770

Closed
riverar opened this issue Jul 21, 2023 · 7 comments
Closed

MSBuildSdkResolver failure when attempting to pack non-SDK project #12770

riverar opened this issue Jul 21, 2023 · 7 comments
Labels
Functionality:Pack Resolution:Duplicate This issue appears to be a Duplicate of another issue Type:Bug

Comments

@riverar
Copy link

riverar commented Jul 21, 2023

NuGet Product Used

NuGet.exe

Product Version

6.6.1.2

Worked before?

No response

Impact

I'm unable to use this version

Repro Steps & Context

Microsoft Visual Studio Enterprise 2022 (64-bit) - Current
Version 17.6.4

  1. git clone https://github.com/riverar/repro-933fd2e428de
  2. cd repro-933fd2e428de
  3. nuget restore
  4. dotnet msbuild -t:Build -p:Configuration=Release -p:Platform="Any CPU"
  5. nuget pack -IncludeReferencedProjects -Properties Configuration=Release .\WindowsFormsApp1\WindowsFormsApp1.csproj
  6. Observe error:
Attempting to build package from 'WindowsFormsApp1.csproj'.
MSBuild auto-detection: using msbuild version '17.6.3.22601' from 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\bin'.
Packing files from 'C:\Sources\repro-933fd2e428de\WindowsFormsApp1\bin\Release'.
Using 'WindowsFormsApp1.nuspec' for metadata.
SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion, String userProfileDir)
   at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext context, SdkResultFactory factory)
   at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.TryResolveSdkUsingSpecifiedResolvers(IList`1 resolvers, Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio, SdkResult& sdkResult, IEnumerable`1& errors, IEnumerable`1& warnings)

Verbose Logs

NuGet Version: 6.6.1.2
Attempting to build package from 'WindowsFormsApp1.csproj'.
MSBuild auto-detection: using msbuild version '17.6.3.22601' from 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
Packing files from 'C:\Sources\repro-933fd2e428de\WindowsFormsApp1\bin\Release'.
Using 'WindowsFormsApp1.nuspec' for metadata.
Add file 'C:\Sources\repro-933fd2e428de\WindowsFormsApp1\bin\Release\WindowsFormsApp1.exe' to package as 'lib\net481\WindowsFormsApp1.exe'
SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion, String userProfileDir)
   at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext context, SdkResultFactory factory)
   at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.TryResolveSdkUsingSpecifiedResolvers(IList`1 resolvers, Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio, SdkResult& sdkResult, IEnumerable`1& errors, IEnumerable`1& warnings)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
""  C:\Sources\repro-933fd2e428de\ClassLibrary\ClassLibrary.csproj
Microsoft.Build.Exceptions.InvalidProjectFileException: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
File name: 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
   at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion, String userProfileDir)
   at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext context, SdkResultFactory factory)
   at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.TryResolveSdkUsingSpecifiedResolvers(IList`1 resolvers, Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio, SdkResult& sdkResult, IEnumerable`1& errors, IEnumerable`1& warnings)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
""  C:\Sources\repro-933fd2e428de\ClassLibrary\ClassLibrary.csproj
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, Boolean interactive)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory, Boolean interactive)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, ProjectCollection projectCollection)
@martinrrm
Copy link
Contributor

Hi! Thanks for filling this issue, I see that you are using nuget to pack, looking at the documentation there is an Important note: "Use dotnet pack or msbuild -t:pack for PackageReference based projects.". I belive you are working with a ProjectReference type project, could you please try using dotnet or msbuild and check if the error is still present? Thanks!

@martinrrm martinrrm added the WaitingForCustomer Applied when a NuGet triage person needs more info from the OP label Jul 24, 2023
@riverar

This comment was marked as outdated.

@ghost ghost added WaitingForClientTeam Customer replied, needs attention from client team. Do not apply this label manually. and removed WaitingForCustomer Applied when a NuGet triage person needs more info from the OP labels Jul 24, 2023
@riverar
Copy link
Author

riverar commented Jul 24, 2023

@martinrrm The project specified in the repro steps above is not using PackageReference and does not contain a pack target.

WindowsFormsApp1.csproj
https://raw.githubusercontent.com/riverar/repro-933fd2e428de/master/WindowsFormsApp1/WindowsFormsApp1.csproj

@jebriede jebriede added Resolution:Duplicate This issue appears to be a Duplicate of another issue and removed Triage:NeedsTriageDiscussion WaitingForClientTeam Customer replied, needs attention from client team. Do not apply this label manually. labels Jul 31, 2023
@jebriede
Copy link
Contributor

Team triage: Looks like a duplicate of #4054

Please add a 👍 reaction to upvote that issue.

@Adam-S-Daniel
Copy link

Adam-S-Daniel commented Nov 15, 2023

@jebriede This is not a duplicate of #4054. The error in that issue is The attribute "Update" in element <Compile> is unrecognized.. The error in this issue is SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'System.Collections.Immutable, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.. Please re-open.

@greg73
Copy link

greg73 commented Mar 4, 2024

I've had the same issue with Visual Studio 17.9.2 and Nuget 6.9.1.
Although the version of System.Collections.Immutable in the error is now 7.0.0.0
I was able to work around it by copying System.Collections.Immutable.dll from the .net SDK into the same folder as nuget.exe.
(C:\Program Files\dotnet\sdk\8.0.200\Sdks\Microsoft.NET.Sdk.Razor\tasks\net472 has the correct version)

@Energy0124
Copy link

I had the same issue as @greg73, and this is not an duplicate of #4054 as @Adam-S-Daniel said. Please re-open this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Pack Resolution:Duplicate This issue appears to be a Duplicate of another issue Type:Bug
Projects
None yet
Development

No branches or pull requests

7 participants