C#6.0功能不使用Visual Studio 2015年工作 [英] C# 6.0 Features Not Working with Visual Studio 2015

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

问题描述

我测试的Visual Studio 2015年使用C#6.0,但语言功能不工作。在一个MVC的Web应用程序,以下code编译做:

 如果(!string.IsNullOrWhiteSpace(Model.Profile?.TypeName))
{
    //这里更多的逻辑...
}

然而,当我通过运行调试和IIS防爆preSS的应用,我得到以下错误:


  

CS1525:''​​无效前pression长期


如何启用这些功能?


解决方案

这工作在MVC 5(测试5.2.3),你只需要添加罗斯林code DOM的NuGet包

codeDOM供应商对于.NET编译器......


  

这是使用新的.NET编译器平台(罗斯林)编译器作为一个服务的API更换codeDOM供应商。这提供了使用codeDOM(例如ASP.NET运行时编译)以及提高这些系统的编译性能在系统中新的语言功能的支持。


  PM>安装封装微软。codeDom.Providers.DotNetCompilerPlatform

<一个href=\"https://www.nuget.org/packages/Microsoft.$c$cDom.Providers.DotNetCompilerPlatform/\">https://www.nuget.org/packages/Microsoft.$c$cDom.Providers.DotNetCompilerPlatform/

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...
}

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

CS1525: Invalid expression term '.'

How do I enable these features?

解决方案

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

CodeDOM Providers for .NET Compiler...

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天全站免登陆