-3

Classic ASP.NET Web Forms project, originally done in DotNet 2 and upgraded throughout the years (now on DotNet 4.7 with - ostensibly - C# 7). A real mess, but something I inherited.

I had been working with C# 6 under DotNet 4.6.2 up until a while ago, and things were working well. Unfortunately in a series of DotNet version swaps that were done in an attempt to figure out why certain (other) things weren't working, VS 2015 Community suddenly lost the hint that it was working with C# > 5, and is suddenly complaining about code (string interpolation, etc.) not being valid C# 5.

It compiles just fine with C# >6 features, so it is clear that the compiling works, but VS thinks I am still using C# < 6.

I had installed the Microsoft.CodeDom.Providers.DotNetCompilerPlatform a long time ago when I moved to DotNet 4.5.2 and C# 6. I did not use the menu option (forgot about that one); I installed it directly from NuGet. Tried force-reinstalling it, no change. Tried deleting the packages folder and restoring packages, also didn't help.

I do not have an "Advanced" button on the Build section of my property pages. Please don’t that suggestion, as it is useless to me.

My version of VS: Visual Studio 2015 Community v14.0.25431.01 Update 3

My Property Pages for this Project/Solution: enter image description here

My Web.Config C# entry (nicely exploded):

<system.codedom>
  <compilers>
    <compiler
      language="c#;cs;csharp"
      extension=".cs"
      type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      warningLevel="4"
      compilerOptions="/langversion:7 /nowarn:1659;1699;1701"/>
    <compiler 
      language="vb;vbs;visualbasic;vbscript"
      extension=".vb"
      type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      warningLevel="4"
      compilerOptions="/langversion:15 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
  </compilers>
</system.codedom>
René Kåbis
  • 842
  • 2
  • 9
  • 28
  • It sounds like you might have an older version of Visual Studio (you don't have an 'Advanced' button in your Build Properties, won't recognize new codebase). What version of VS are you running? – gravity May 12 '17 at 18:57
  • Visual Studio Community 2015 Version 14.0.25431.01 Update 3 – René Kåbis May 12 '17 at 18:58
  • Next time, don't swap .NET versions. You can only *cause* problems. Anyway, VS 2015 can't use C# 7 – Panagiotis Kanavos May 15 '17 at 12:45
  • Switching back to DotNet 4.6.2 and C# 6 makes no difference. I am still getting VS Intellisense complaining about a lot of errors on C# 6 items such as null propagating operators. And running the site on C# 7 using C# 7 code works just fine (debug, local test and production), so I guess you’re talking about certain tools such as Intellisense instead of any real ability to develop in the first place. – René Kåbis May 22 '17 at 20:34
  • Correction: I am using DotNet 4.7 and C# 7 in another MVC 5 project using VS 2015, and am experiencing zero issues with it. Debug, local and production work just fine and Intellisense works like a champ even with C# 7 specific code. Looks like any > C# 5 issues I am having is with this legacy project specifically. – René Kåbis May 22 '17 at 20:39

1 Answers1

1

This is a Website project, not a Web Application project, so your code isn't actually compiled when you instruct VS to Build your project, instead compilation only at runtime (typically when the first HTTP request is made to your website).

You can use the new C# language features by configuring ASP.NET to use the new Roslyn CodeDOM provider, which is done in your web.config file - you will also need to add the binary references too. See here: How to use C# 6 with Web Site project type?

Community
  • 1
  • 1
Dai
  • 141,631
  • 28
  • 261
  • 374
  • You mean, like this: `` ? Because AFAIK that’s C# 7, not C# 5. – René Kåbis May 12 '17 at 19:31
  • And according to Microsoft, a Web Forms project is a “Web Application”: https://msdn.microsoft.com/en-us/library/aa711425(v=vs.71).aspx – René Kåbis May 12 '17 at 19:37
  • Plus, when I publish the project, all my *.cs files get compiled into DLL files and put into the `/bin/` folder. How is that not compiling? – René Kåbis May 12 '17 at 19:38
  • @RenéKåbis That's the optional Precompilation step that's part of the Web Publish process - that's not the same thing as Building your project. – Dai May 12 '17 at 19:53
  • @RenéKåbis And if you are doing Precompilation and if you have a lot of code in your `App_Code` directory you might as well upgrade away from a Website project to a full ASP.NET Web Application project. – Dai May 12 '17 at 19:54
  • @RenéKåbis The MSDN article you linked to it from Visual Studio **2003** which was before Website projects were introduced (in VS 2005). – Dai May 12 '17 at 19:55
  • All these details do not help solve my problem. I have the correct XML in my Web.Config. Why is my VS derping? – René Kåbis May 12 '17 at 20:56
  • @RenéKåbis the project page you posted is *not* a Web Application page. It's a Web Site page. Web Application project properties are similar to dll, console, desktop projects. – Panagiotis Kanavos May 15 '17 at 12:46
  • All these details - which are now completely off-topic - do not help solve my problem. I have the correct XML in my Web.Config. Why is my VS derping? – René Kåbis May 15 '17 at 17:01