How can Resharper be made aware of the framework version?
Asked Answered
R

2

20

I am coding in VS2008 with Resharper 4.5.1, but the projects are set to target .NET Framework 2.0.

Still, Resharper is making suggestions that are relevant to the .NET 3.5 framework. For instance, it tells me that I should be using collection initializers, etc...

I've looked through the settings and can't seem to find the checkbox to tell it to give 2.0 specific advice.

Repeat answered 3/9, 2009 at 17:27 Comment(5)
Collection initializers are a language feature, not part of the .NET framework. You can use certain bits of C# 3.0 in projects targeted at .NET 2.0. Does Resharper really suggest things that cannot be compiled?Heuser
Well, no, but it does suggest stuff that'll blow up on the target system, which only has .NET 2.0.Repeat
Could you give more relevant examples then?Servomechanism
Well, the example I would think, would blow up on a .NET 2.0 only box, since the JIT compiler knows nothing about collection initializers. The answer provided by bdukes actually fixed the problem.Repeat
Collection initializers are compiled into valid .net 2.0 IL by the C# 3.0 compiler. They will run fine on a box with only .net 2.0. The only C# 3.0 features that require .net 3.5 are extensions methods and LINQ, since they require types that are defined in new .net 3.5 assemblies.Preconcert
P
43

Select your project in the Solution Explorer and open the Properties tool window (F4 in the standard keyboard layout or View > Properties Window after selecting the project). In the ReSharper section, there is a Language Level property that you can set to C# 2.0. Note that there are two separate project properties windows that manage different properties, if you see tabs for "Application", "Build" and "Debug" you are in the wrong window.

As others have said, this affects the version of C#, not the version of the framework (since most of the C# 3.0 changes can be compiled to an assembly that targets .NET 2.0).

Preconcert answered 3/9, 2009 at 17:32 Comment(8)
Can't find this option in Visual Studio 2010 with ReSharper 5.1Kestrel
@Kestrel Are you using C#? Do you have the project selected in the Solution Explorer? Are you able to see other properties for the project (e.g. "Always Start When Debugging" or "Project File")? Is there a ReSharper section in the properties? What kind of project is it?Preconcert
Ouch. I found it. Sorry for hesitation.Kestrel
Thanks for the suggestion @bdukes. Do you know if this can be set on a solution level?Beth
@Beth I'm not aware of a solution-level setting for language version, but would definitely be interested in finding one (or a machine-wide setting)Preconcert
@Beth if you look in the DotSettings file that ReSharper creates, the language level (for C# 5) looks like <s:String x:Key="/Default/CodeInspection/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp50</s:String>. You can move that from the project-level DotSettings to the solution level DotSettings and it appears to work (and, I assume, you could move it to any of the higher level files, as well)Preconcert
Please refer to https://mcmap.net/q/463418/-resharper-setting-c-language-level-for-solution/214747 for further details as to how i resolved my issueBeth
@Preconcert I can confirm it works at user level too. %APPDATA%\JetBrains\Shared\vAny\GlobalSettingsStorage.DotSettingsAlcoholometer
R
8

Those features are not .NET 3.5 framework features, but merely features of the 3.5 compiler. And since in VS2008 this is the compiler invoked for .NET 2 targets, it does handle these syntax extensions correctly.

Razo answered 3/9, 2009 at 17:31 Comment(1)
This is valid answer - OP is not using features he could used based on superstitions and misunderstanding of Compiler <-> Runtime separation.Pontiff

© 2022 - 2024 — McMap. All rights reserved.