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

MSBuildWorkspace compilation errors for netcoreapp31/net5.0 'The type or namespace name 'System' could not be found' #53906

Closed
Rora opened this issue Jun 6, 2021 · 4 comments
Assignees
Labels
Area-IDE Bug IDE-MSBuildWorkspace MSBuildWorkspace Resolution-Duplicate The described behavior is tracked in another issue
Milestone

Comments

@Rora
Copy link

Rora commented Jun 6, 2021

Version Used:
3.9.0

Steps to Reproduce:

  1. Use MSBuildLocator.RegisterDefaults
  2. Create a MSBuildWorkspace
  3. Load a solution
  4. Compile a net5.0 or netcoreapp3.1 project
  5. Validate the compilation diagnostics

Expected Behavior:
No errors

Actual Behavior:
The following errors occur:

  1. error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?)
  2. error CS0518: Predefined type 'System.Object' is not defined or imported
  3. error CS1729: 'object' does not contain a constructor that takes 0 arguments

I've also tried to scan a netstandard2.1 project and that seems to work fine. I created a solution which reproduces this issue: https://github.com/Rora/msbuild-workspace-dotnetcoreapp-repro

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 6, 2021
@jinujoseph jinujoseph added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 16, 2021
@jinujoseph jinujoseph added this to the 17.0.P2 milestone Jun 16, 2021
@jinujoseph jinujoseph added the IDE-MSBuildWorkspace MSBuildWorkspace label Jun 16, 2021
@koenbeuk
Copy link

koenbeuk commented Jul 7, 2021

I'm experiencing the same issue, is there a known workaround?

@JoeRobich
Copy link
Member

JoeRobich commented Jul 7, 2021

@Rora So looking at the contents of workspace.Diagnostics after loading the solution, there are several errors of the form:

Msbuild failed when processing the file '/Users/joeyrobichaud/Source/msbuild-workspace-dotnetcoreapp-repro/RoslynScanner/RoslynScanner/RoslynScanner.csproj' with message: /usr/local/share/dotnet/sdk/5.0.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets: (63, 5): The \"ProcessFrameworkReferences\" task failed unexpectedly.
System.MissingMethodException: Method not found: 'System.String NuGet.Frameworks.NuGetFramework.get_Platform()'.
   at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.KnownFrameworkReferenceAppliesToTargetFramework(NuGetFramework knownFrameworkReferenceTargetFramework)
   at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.<ExecuteCore>b__105_1(KnownFrameworkReference kfr)
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.NET.Build.Tasks.ProcessFrameworkReferences.ExecuteCore()
   at Microsoft.NET.Build.Tasks.TaskBase.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)

This is an issue where Microsoft.NET.Test.Sdk depends on Microsoft.TestPlatform.TestHost which depends on Microsoft.TestPlatform.ObjectModel which depends on and older version of NuGet.Frameworks. To fix this in your tests you can add a PackageReference to "NuGet.Frameworks" version 5.9.0+.

@koenbeuk
Copy link

koenbeuk commented Jul 7, 2021

I can confirm that adding NuGet.Frameworks as a package reference as suggest by @JoeRobich solves this issue.

There are a triage of other issues when having .net core 6 preview installed. After uninstalling .net core 6 preview, things finally started working. I suspect that those other issues are unrelated to this issue though, will open new issues if I see the need.

@JoeRobich JoeRobich added the Resolution-Duplicate The described behavior is tracked in another issue label Jul 15, 2021
@JoeRobich
Copy link
Member

JoeRobich commented Jul 15, 2021

Closing this issue as a duplicate of #52954

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug IDE-MSBuildWorkspace MSBuildWorkspace Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

6 participants