Bug description
On a Windows 10 PC with VS 2019 16.9.4 and .NET SDK 5.0.202 installed, I checked out the latest commit (ad578df as of 10-May-21), ran the init.ps1
script, then dotnet build
(0 warnings, 0 errors), and then dotnet test
. This produced many errors like this:
error CS0012: The type 'Object' is defined in an assembly that is not referenced.
You must add a reference to assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
(And variations of the above for System.Void
, System.Int32
, System.Type
, etc)
and:
error CS0234: The type or namespace name 'Task' does not exist in the namespace 'System.Threading.Tasks' (are you missing an assembly reference?)
DiagnosticResult.CompilerError("CS0234").WithSpan(6, 37, 6, 41).WithArguments("Task", "System.Threading.Tasks"),
Total:
Failed: 81, Passed: 1, Skipped: 0, Total: 82, Duration: 54 s
(The one test that passes is AssemblyHasNoReferenceToMpf.)
See screenshot below for more details.
To Reproduce
- Checkout latest ad578df
- Open Powershell prompt, run the
init.ps1
script
- Then run
dotnet build
- Then run
dotnet test
(or dotnet test -f net472
)
Or after step 2, open the solution in Visual Studio 2019 16.9.4 and then build, then run the tests in the Test Explorer.
Expected behavior
The tests should all pass (according to the Azure builds).
More info
I can get most of the tests to pass by explicitly adding metadata references in the Test
ctor (CSharpCodeFixVerifier`2.cs line 77), like this:
this.SolutionTransforms.Add((solution, projectId) =>
{
Project? project = solution.GetProject(projectId);
project = project?.AddMetadataReference(MetadataReference.CreateFromFile(typeof(object).Assembly.Location));
project = project?.AddMetadataReference(MetadataReference.CreateFromFile(typeof(System.ComponentModel.Design.IServiceContainer).Assembly.Location));
project = project?.AddMetadataReference(PresentationFrameworkReference);
if (project == null)
{
throw new System.NullReferenceException(nameof(project));
}
return project.Solution;
});
But some of the VSSDK006 tests still fail with this error:
error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
DiagnosticResult.CompilerError("CS0012").WithSpan(11, 17, 11, 24).WithArguments("System.Object", "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"),
It's unclear why some VSSDK006 tests pass and others don't. E.g. LocalAssigned_GetService_ThenUsedAsync
fails with that error, but LocalAssigned_GetService_ThenUsed_WithNullConditionalAsync
passes.
New total with above workaround:
Failed: 17, Passed: 65, Skipped: 0, Total: 82, Duration: 1 m 4 s
Screenshots