Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to configure Razor page language version to C# 6?

Recently I've tried to use some C# 6 new feature (interpolated strings) in my ASP.NET MVC (5) .cshtml view, but when running got an error message complaining about the $. It is clear the compiler in C# 5 compatibility mode, or worst it is a C# 5 compiler.

When in editor a popup warning warns me (I do not know it is VS or ReSharper) Feature 'Interpolated strings' is not available in C# 5. Please use language version 6 or greater.

The project itself was set to C# 6, and I can use C# 6 features in my build time compiled code like controllers etc.

Q: Where should I set page compiler version, and will this C# 6 compiler available when I deploy my web app to Azure there?

like image 508
g.pickardou Avatar asked Aug 14 '15 14:08

g.pickardou


People also ask

How do I change my version of C sharp?

Navigate to Properties -> Build -> Advanced, select “C# latest minor version(latest)” to pick latest installed minor version. The C# latest major version is the default language version set, and choosing the “C# latest minor version” it will always refer to latest C# version, in this case it will refer to C# 7.2.

Why can't I select a different C# version?

If you're using the latest version of Visual Studio 2019, C#, you may not see the option to change the C# language version of your project. This is a new change in Visual Studio 2019/. NET Core 3.0. The new C# compiler chooses the default version based on your .

What is a Razor page C#?

Razor Pages is a newer, simplified web application programming model. It removes much of the ceremony of ASP.NET MVC by adopting a file-based routing approach. Each Razor Pages file found under the Pages directory equates to an endpoint.

How do I know what version of C# I am using?

Get C# Version using Command Prompt Using Visual studio Command prompt: csc /langversion:? C# compiler determines a default language version based on your project's target framework. The target project when built gets the highest compatible language version by default as per this versioning semantics.


2 Answers

From String interpolation in a Razor view?:

This only works in MVC6. Alternatively, also from a comment on this link, you'll need to add the roslyn code dom package from ASP.Net.

<div>
    @($"Hello {this.Model.SomeProperty}")
</div>

As far as Azure is concerned, please see this link. http://azure.microsoft.com/blog/2015/08/11/update-on-net-framework-4-6-and-azure/

With great power… The tooling, framework and Azure platform teams want to ensure the powerful tools we give you to help build your dream is matched by the responsibility we recognize we have to keep it running in the cloud. At the time of the Visual Studio and Azure SDK 2.7 releases, Framework 4.6 wasn’t supported broadly throughout Azure. This is due in large part to the fact that just as many teams (or more) are responsible for the ongoing development and stability of the Azure platform.

For now, we have an update on the availability of .NET Framework 4.6 for Azure App Service and an article demonstrating how to get .NET Framework 4.6 working in your Cloud Service roles.

Azure IaaS For customers using Azure’s Infrastructure as a Service (IaaS) services, installation of .NET Framework 4.6 is manual. To install .NET Framework 4.6 on an Azure IaaS virtual machine, the process is as simple as logging into the virtual machine using Remote Desktop. Once on the machine, the .NET Framework 4.6 installer can be downloaded and installed directly onto the virtual machine. Customers using Azure Automation could also choose to automate the installation onto Azure virtual machines using PowerShell.

Azure App Service Update The Azure App Service team is nearing the end of the testing phase for .NET Framework 4.6 and planning the deployment to the environments. Currently, the plan is to roll out the updates to Azure App Service during August 2015.

Azure Cloud Services Saurabh Bhatia authored an article in the Azure documentation center outlining how to install the .NET Framework in a Cloud Service Role. The content has been recently updated to include commentary specific to .NET Framework 4.6. You can find the updated article here on the Azure documentation center.

like image 151
LSU.Net Avatar answered Oct 10 '22 06:10

LSU.Net


For me installing the Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package solved the problem.

like image 22
Keith Banner Avatar answered Oct 10 '22 04:10

Keith Banner