Search code examples
c#asp.net

How to use C# 6.0 or 7.0 in an old ASP.NET Website (not Website Project)


I have multiple old ASP.NET webforms websites (this is how to create one from scratch): enter image description here

They are not Website Projects.

ASP.NET Websites seem to be stuck at C# 5. When trying to use features from c# 6 or C# 7 you get an error: enter image description here Trying to use the light bulb upgrade option fails: enter image description here Trying any of the other options found at https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version fail too since there is no .csproj file. or an option in the Project Properties page to change the language version.

Here is what the Build tab looks like on an ASP.NET Website (no Advanced button): enter image description here

I installed the Microsoft.Net.Compilers NuGet package but that made no difference.

Any Ideas if this can be done at all in an ASP.NET website?


Solution

  • If you install the Microsoft.CodeDom.Providers.DotNetCompilerPlatform it will update your web.config file to use the current version - right now it's on 7.3:

      <system.codedom>
        <compilers>
          <compiler extension=".cs" language="c#;cs;csharp" warningLevel="4" 
            compilerOptions="/langversion:7.3 /nowarn:1659;1699;1701;612;618" 
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, 
                  Microsoft.CodeDom.Providers.DotNetCompilerPlatform, 
                  Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
          <compiler extension=".vb" language="vb;vbs;visualbasic;vbscript" warningLevel="4" 
            compilerOptions="/langversion:default /nowarn:41008,40000,40008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" 
            type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, 
                  Microsoft.CodeDom.Providers.DotNetCompilerPlatform, 
                  Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
        </compilers>
      </system.codedom>