theraot / Theraot

Backporting .NET and more: LINQ expressions in .net 2.0 - nuget Theraot.Core available.
MIT License
160 stars 30 forks source link

Using Theraot on Framework 2.0, in Webform.aspx without codebehind not working :( #122

Closed cesarcamps closed 4 years ago

cesarcamps commented 4 years ago

I create a simple website, on vs 2019, using framework 2.0, but give error

Error CS8023 Feature 'query expression' is not available in C# 2. Please use language version 3 or greater. 7_Default.aspx C:\Temp\website\Default.aspx 13 Active

website.zip

image

cesarcamps commented 4 years ago

Sorry, using Theraot 3.1.5, on target framework 2.0.

NN--- commented 4 years ago

You mix C# language version and .NET Framework version. They don't correlate 1 to 1. You can use C# 9 even with .NET Framework 2.0 .

What you configured is using C# language 2 which doesn't support LINQ comprehension. You must change to C# language 3 or above to use this syntax.

theraot commented 4 years ago

With Theraot.Core you should be able to use newer versions of C# on older .NET Frameworks. Go ahead and change the language version, you should be able to find the option in project properties. The compiler will then look for the types needed to make Linq work, which are not in .NET Framework 2.0, yet Theraot.Core provides them instead.

cesarcamps commented 4 years ago

I there. I am using a website, where can i set language version?? I do not see it in project's option

image

cesarcamps commented 4 years ago

Beside, when i host it, in a IIS with framework 2.0 configured, this error poped out Sorry by my question, but i do not know where to ask (english is not my mother language).

image

theraot commented 4 years ago

Option 1

For the web project you have to modify Web.config.

I tried with your zip, adding the following inside Web.config configuration worked for me:

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp"
                extension=".cs"
                warningLevel="4"
                type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5" />
        <providerOption name="WarnAsError" value="false" />
      </compiler>
    </compilers>
  </system.codedom>

That should enable Linq.


Option 2

For what I read, you should also be able to use Roslyn (DotNetCompilerPlatform) instead. It seems it would require some manual deploy.

You can install DotNetCompilerPlatform version 1.0.0.0 from Nuget (I haven't tested which is the newest version you can install). Temporarily remove the problematic code (make it comments), so you can build the website, and the nuget is downloaded, afterwards, you would set the following in web.config (instead of the code above):

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
  </system.codedom>

Once you have it, Visual Studio will tell you it can't find "\bin\roslyn\csc.exe". You can get csc et.al. from the nuget Microsoft.Net.Compilers. Yet installing it did not solve the issue for me, instead I downloaded the nuget, extracted it, and got the files from the tools folder in there. That is the manual part. I guess I must be missing something. There are plenty of web search results about setting Roslyn in web.config. Hopefully you have better luck.

cesarcamps commented 4 years ago

Option 1

For the web project you have to modify Web.config.

I tried with your zip, adding the following inside Web.config configuration worked for me:

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp"
                extension=".cs"
                warningLevel="4"
                type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <providerOption name="CompilerVersion" value="v3.5" />
        <providerOption name="WarnAsError" value="false" />
      </compiler>
    </compilers>
  </system.codedom>

That should enable Linq.

Option 2

For what I read, you should also be able to use Roslyn (DotNetCompilerPlatform) instead. It seems it would require some manual deploy.

You can install DotNetCompilerPlatform version 1.0.0.0 from Nuget (I haven't tested which is the newest version you can install). Temporarily remove the problematic code (make it comments), so you can build the website, and the nuget is downloaded, afterwards, you would set the following in web.config (instead of the code above):

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
  </system.codedom>

Once you have it, Visual Studio will tell you it can't find "\bin\roslyn\csc.exe". You can get csc et.al. from the nuget Microsoft.Net.Compilers. Yet installing it did not solve the issue for me, instead I downloaded the nuget, extracted it, and got the files from the tools folder in there. That is the manual part. I guess I must be missing something. There are plenty of web search results about setting Roslyn in web.config. Hopefully you have better luck.

Yes!!! With option 1 !!! Thanx's!