C# 6.0 功能不适用于 Visual Studio 2015 [英] C# 6.0 Features Not Working with Visual Studio 2015

查看:28
本文介绍了C# 6.0 功能不适用于 Visual Studio 2015的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 C# 6.0 测试 Visual Studio 2015,但语言功能不起作用.在 MVC Web 应用程序中,以下代码确实可以编译:

I am testing Visual Studio 2015 with C# 6.0 but the language features are not working. In an MVC web application, the following code does compile:

if (!string.IsNullOrWhiteSpace(Model.Profile?.TypeName))
{
    // More logic here...
}

但是,当我通过 Debug 和 IIS Express 运行应用程序时,出现以下错误:

However, when I run the application via Debug and IIS Express, I get the following error:

CS1525:无效的表达式术语."

CS1525: Invalid expression term '.'

如何启用这些功能?

推荐答案

这个在MVC 5中有效(测试5.2.3),你只需要添加roslyn代码dom Nuget包

This works in MVC 5 (tested 5.2.3), you just need to add the roslyn code dom Nuget package

使用新的 .NET 编译器平台(Roslyn")编译器作为服务 API 的替换 CodeDOM 提供程序.这为使用 CodeDOM 的系统(例如 ASP.NET 运行时编译)中的新语言功能提供支持,并提高这些系统的编译性能.

Replacement CodeDOM providers that use the new .NET Compiler Platform ("Roslyn") compiler as a service APIs. This provides support for new language features in systems using CodeDOM (e.g. ASP.NET runtime compilation) as well as improving the compilation performance of these systems.

PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform

https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/

这篇关于C# 6.0 功能不适用于 Visual Studio 2015的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆