16

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?

g.pickardou
  • 32,346
  • 36
  • 123
  • 268
  • Possible dupe of http://stackoverflow.com/questions/30832659/c-sharp-6-string-interpolation-in-a-razor-view – LSU.Net Aug 14 '15 at 14:16
  • Except it has possibly incorrect answer. That's is my wording in the question about compiler version. – g.pickardou Aug 14 '15 at 14:27
  • See http://stackoverflow.com/questions/27968963/c-sharp-6-0-features-not-working-with-visual-studio-2015/31548221#31548221. Some features won't work, but most will. – Pablo Montilla Aug 31 '15 at 20:42

2 Answers2

4

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.

Community
  • 1
  • 1
LSU.Net
  • 829
  • 6
  • 17
  • Thanks. Read the link you referenced. Although I understand that Razor's intuitive switch between markup and C# does not work seamlessly with the $, I think the compiler version has nothing to do with this, that's why my wording in my question. Once Razor recognizes it's C# it goes to the generated C# class. Then it's entirely up the the configured compiler it understands or gives an error. – g.pickardou Aug 14 '15 at 14:25
  • My main concern is IIS and Azure. – g.pickardou Aug 14 '15 at 14:29
  • Updated answer with link on .Net 4.6 and Azure – LSU.Net Aug 14 '15 at 14:34
2

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

Keith Banner
  • 602
  • 1
  • 10
  • 15