IDE shows missing netstandard.dll while build succeeds
See original GitHub issueI’m using the latest (public) version of VS with the latest .NET Core tooling. I’m consuming a .NET Standard 2.0 library from a .NET Framework 4.6.1 project. The project builds and runs just fine, but shows errors in the IDE:
Repro steps
- Create a .NET Standard 2.0 class library
- Change the code of
Class1
as follows:using System; public class Class1 { public (string key, int value) GetData() { return ("Meaning of Life", 42); } }
- Create a .NET Framework 4.6.1 console app
- Add a reference to the class library you created earlier
- Change the code of
Program
as follows:using System; class Program { static void Main(string[] args) { var c = new Class1(); var data = c.GetData(); Console.WriteLine(data); } }
Expected Behavior
No squiggles and no items in the error list.
Actual Behavior
The error list shows the following errors:
- CS0012: The type
ValueTuple<,>
is defined in an assembly that is not referenced. You must add a reference to assemblynetstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
. - CS1503: Argument 1: cannot convert from
(string key, int value)
tobool
However, the project compiles & runs fine.
Findings
From @davkean
It’s very likely the compiler isn’t being given the netstandard.dll via the design-time build. No idea how this gets added to a .NET Framework 4.6.1 project – but whomever adds that dll should investigate. They can get the results of a design-time build: https://github.com/dotnet/project-system/blob/master/docs/design-time-builds.md#getting-visual-studio-to-output-the-results-of-a-design-time-build.
From @nguerrera
Please file a bug on dotnet/sdk as that’s where the component that adds the netstandard ref to netframework projects now lives.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
I’ve figured out what the problem is here. The issue is that we detect whether any references depend on .NET Standard using a task that looks at the metadata of the assembly to see if it has a reference to netstandard.dll. However, in this scenario, the project has not been built yet, so there is no assembly on disk for the task to examine.
Building the solution and then closing and re-opening it makes the issue go away.
A similar issue existed with the System.Runtime facades, and was resolved by adding metadata for the target platform to the item returned by the
GetTargetPath
target, which was then consumed in theImplicitlyExpandDesignTimeFacades
target.So I’d propose we fix this bug in a similar fashion:
DependsOnNETStandard
metadata to the_ResolvedProjectReferencePaths
item returned byGetTargetPath
Microsoft.NET.Build.Extensions.NETFramework.targets
, check for that metadata as an alternate way of determining whether the project depends on .NET Standard@rainersigwald @AndyGerlicher Ideally we’d add the
DependsOnNETStandard
metadata in the .NET SDK. The way the metadata is handled changed recently in https://github.com/Microsoft/msbuild/pull/2197. Is there a safe way for the SDK to add a target which runs afterGetTargetPathWithTargetPlatformMoniker
but beforeGetTargetPath
which could add additional metadata to theTargetPathWithTargetPlatformMoniker
item?No longer repros for me. Thanks!