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

Traversal SDK net6 support #309

Closed
leonardochaia opened this issue Nov 10, 2021 · 6 comments
Closed

Traversal SDK net6 support #309

leonardochaia opened this issue Nov 10, 2021 · 6 comments

Comments

@leonardochaia
Copy link

leonardochaia commented Nov 10, 2021

Hi!

In dotnet-affected, we create MSBuild Traversal SDK projects using this code:

var projectRootElement = @"<Project Sdk=""Microsoft.Build.Traversal/3.0.3""></Project>";
var stringReader = new StringReader(projectRootElement);
var xmlReader = new XmlTextReader(stringReader);
var root = ProjectRootElement.Create(xmlReader);

var project = new Project(root);

This code works fine in net5 but it's failing on net6. I suspect it may be because Microsoft.Build.Traversal needs to support net 6?

The stacktrace looks like this:

 Microsoft.Build.Exceptions.InvalidProjectFileException : SDK Resolver Failure: "The SDK resolver "NuGetSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.ArgumentNullException: Value cannot be null. (Parameter 'path')
   at System.IO.Directory.GetParent(String path)
   at Microsoft.Build.NuGetSdkResolver.GlobalJsonReader.GetMSBuildSdkVersions(SdkResolverContext context)
   at Microsoft.Build.NuGetSdkResolver.NuGetSdkResolver.TryGetNuGetVersionForSdk(String id, String version, SdkResolverContext context, Object& parsedVersion)
   at Microsoft.Build.NuGetSdkResolver.NuGetSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory)
   at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio)""  /home/runner/.nuget/packages/microsoft.build.traversal/3.0.3/Sdk/Sdk.props
  Stack Trace:
     at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1](IElementLocation elementLocation, String resourceName, T1 arg0)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List`1& projects, SdkResult& sdkResult, Boolean throwOnFileNotExistsError)
   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.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, 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)
   at Microsoft.Build.Evaluation.Project..ctor(ProjectRootElement xml, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
   at Microsoft.Build.Evaluation.Project..ctor(ProjectRootElement xml)
   at Affected.Cli.Formatters.TraversalProjectOutputFormatter.Format(IEnumerable`1 projects) in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected/Infrastructure/Formatters/TraversalProjectOutputFormatter.cs:line 23
   at Affected.Cli.Tests.Formatters.TraversalFormatterTests.Using_single_project_should_contain_project() in /home/runner/work/dotnet-affected/dotnet-affected/src/dotnet-affected.Tests/Formatters/TraversalFormatterTests.cs:line 25
--- End of stack trace from previous location ---

Full logs can be found here

Link to source code

dotnet info

.NET SDK (reflecting any global.json):
 Version:   6.0.100
 Commit:    9e8b04bbff

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /home/runner/work/dotnet-affected/dotnet-affected/eng/.dotnet/sdk/6.0.100/

Host (useful for support):
  Version: 6.0.0
  Commit:  4822e3c3aa

.NET SDKs installed:
  3.1.415 [/home/runner/work/dotnet-affected/dotnet-affected/eng/.dotnet/sdk]
  5.0.403 [/home/runner/work/dotnet-affected/dotnet-affected/eng/.dotnet/sdk]
  6.0.100 [/home/runner/work/dotnet-affected/dotnet-affected/eng/.dotnet/sdk]

Any guidance is appreciated!

Thanks!
Leo.

@jeffkl
Copy link
Contributor

jeffkl commented Nov 11, 2021

Looks like an MSBuild bug reported here: dotnet/msbuild#7035

@leonardochaia
Copy link
Author

Looks like the same issue.
I've tried updating MSBuild to v17 which targets net6, just in case, but same error.

@jeffkl
Copy link
Contributor

jeffkl commented Nov 11, 2021

Based on the stack trace, I suspect if you save the project to disk first it might work. It seems like the path to project is null which is causing an exception later on.

@jeffkl
Copy link
Contributor

jeffkl commented Nov 18, 2021

I'm going to close this in favor of NuGet/Home#11376

@leonardochaia
Copy link
Author

Hi @jeffkl , sorry for the dumb question, but has this been released yet?
Not sure what I need to update to get this changes, is this included in .NET 6.0.1?

@jeffkl
Copy link
Contributor

jeffkl commented Jan 10, 2022

@leonardochaia the bug was fixed in the next release which will be in Visual Studio 17.1 and .NET 6.0.200 which should be available in early February. You can also use preview versions if you need the functionality right away. https://github.com/dotnet/installer#installers-and-binaries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants