1

I have a class library that targets multiple frameworks.

i.e.

<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>

When msbuild builds my application it correctly spits out both netstandard2.0 and netstandard2.1 assemblies. I'm using precompile directives to include framework-specific code in the solution:

#if NETSTANDARD2_1

Visual Studio seems to choose to define NETSTANDARD2_0, but I can't figure out how to force it to use NETSTANDARD2_1 instead. The code within the NETSTANDARD2_1 precompile directive is always grayed out.

enter image description here

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Matt Ruwe
  • 3,386
  • 6
  • 39
  • 77
  • It depends on your client application, that determines your framework https://learn.microsoft.com/en-us/dotnet/standard/frameworks – Brian Oct 31 '19 at 18:25
  • @Brian so, whichever project I have setup as my startup project? I have a .NET Core 2.2 client app and a .NET Core 3.0 client app. – Matt Ruwe Oct 31 '19 at 19:00
  • @Matt See my answer on the question I linked to. VS will always spit out both sets of binaries unless you target only one framework, but you can switch between the frameworks in VS so that your greyed out code becomes active. – Stephen Kennedy Oct 31 '19 at 19:02
  • Yes, just read through that and it answers my questions. This is a duplicate. – Matt Ruwe Oct 31 '19 at 19:02
  • @MattRuwe yes, the client app or startup app sets the Target Framework. – Brian Oct 31 '19 at 19:03
  • @Brian FYI, I tried to change the startup project and that didn't change the framework version selected for my precompile directives. The dropdown in the upper left of the code window did the trick, though. – Matt Ruwe Oct 31 '19 at 19:10

0 Answers0