How to switch between target frameworks for .NET Core projects in Visual Studio

后端 未结 2 1690
花落未央
花落未央 2020-12-17 16:53

Say you have a .NET Core project that looks like this:

\"frameworks\": {
    \"net40\": {},
    \"dotnet5.1\": {}
}

And this is your C# cod

2条回答
  •  生来不讨喜
    2020-12-17 17:31

    Answer already provided seems mostly correct. I'd just like to highlight some issues currently present with that.

    As of today, on VS 2015 Community Ed, Version 14.0.25424.00 Update 3, global.json sdk 1.0.0-preview2-003121, the nav bar shows multiple targets only if the startup project is a multi-target "executable" one (e.g console app).

    If startup is set on a multi-target class library, no target switch is listed (and the label next to the green arrow is different as well):

    Also, when switcher can be used, it seems like "standard" conditional defines provided by build system are not correctly highlighted in editor:

    In order to see conditional define blocks correctly highlighted, one has to switch the project switcher, highlighted in green in last screenshot. It seems like different targets in same project are treated as different projects to this purpose. And that can be changed indenpendently for any file open in editor.

提交回复
热议问题