I have a Xamarin Forms application. I'd like to use the latest C# version in platform specific projects (i.e. Xamarin.iOS and Xamarin.Android). It looks like I can add <LangVersion>latest</LangVersion> to the .csproj files. However, I'm not sure where to add it exactly. I see a lot of PropertyGroup tags in the project files (usually one for each simulator and release type). Do I need to add it to every PropertyGroup? I need the latest language version to be available when debugging and in production.
James Montamagno posted a tutorial on his Blog here: https://montemagno.com/use-csharp-8-everywehre/
You just have to change the <LangVersion /> value of your .csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.3.0.947036" />
<PackageReference Include="Xamarin.Essentials" Version="1.3.1" />
</ItemGroup>
</Project>
if you want to change the language of your platform specific code just add:
<PropertyGroup>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
to your ProjectName.iOS.csproj or ProjectName.Android.csproj.
Generally, if you use the latest version of Target framework, the version of C# will be the latest. Then you will not need to set the version of C# manually.
Right click the solution of Xamarin Forms, then click Properties, then can set the Target framework as follow.

You will refer to this official document to know its explains.

And also can set C# version manually in .csproj as follow:
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Here is the C# language version reference.

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With