6

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?

adinas
  • 4,150
  • 3
  • 37
  • 47

3 Answers3

7

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>
Scott Baker
  • 10,013
  • 17
  • 56
  • 102
6

Right click on the project, click on properties, select build tab, click on Advance button at right bottom, select Language Version and click on OK button.

enter image description here

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
akshayblevel
  • 324
  • 1
  • 6
  • 1
    Hi, Please see the last image I just added. You will notice there is no "Advanced..." tab. Your answer would be correct if this was a Website Project. – adinas May 14 '19 at 12:57
  • 2
    try to modify the langversion in web.config as below: – akshayblevel May 14 '19 at 13:23
  • I figured out that adding `"Microsoft.CodeDom.Providers.DotNetCompilerPlatform"` Nuget package will add your lines to the `web.config` and the needed `Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll` file to the bin folder and solve the issue. If you create an answer with this solution I will mark it as the correct answer – adinas May 15 '19 at 06:55
1

I run into a project, it is an old asp.net project without .csproj file.

If you create a new asp.net website, you will find the .csproj file, and you can use C# version above 5 happily.

So the problem become: how to generate .csproj file for the old project.

Just create a new project, and copy the code from old project inside Visual Studio. And then copy the new .csproj to the old project. And then your old asp.net project refreshed.:)

ice6
  • 1,173
  • 9
  • 9