问题
I'm using Visual Studio 2019 with SDK based project, with multiple targets:
<TargetFrameworks>netstandard2.0;net45;net46</TargetFrameworks>
But when I write conditional code, I see (obviously) some code in gray and some code in regular colors :
Question:
What settings decide which section will be gray and which will not?
Because now, if I want to edit the "NETFULL
" section (because I'm multitargeting), it's all gray and I don't have intellisense.
How can I tell VS: now let's switch to NETFULL
mode?
NB Sure I can remove the condition but I want to know why is it gray and how can I switch between them ( since I'm multitargeting)
回答1:
To switch between the frameworks you are targeting use the dropdown at the top left of the code pane:
Conditional-compilation symbols are declared in the .csproj file:
<PropertyGroup Condition="'$(TargetFramework)' == 'net45' OR '$(TargetFramework)' == 'net46'">
<DefineConstants>NETFULL</DefineConstants>
</PropertyGroup>
or you can use the predefined symbols such as NETFRAMEWORK
, NETSTANDARD
or NETCOREAPP
(or the versioned predefined symbols such as NETSTANDARD2_0
).
回答2:
It is the matter of conditional compilation symblols which you define in properites of your project.
Navigate to proprties tab of your project and select Build tab. There you can define those symobls.
回答3:
Redefine TargetFrameworks. Use the same syntax, just put in the other targets.
来源:https://stackoverflow.com/questions/56505092/switching-between-compiler-directives-in-visual-studio-2019