`Add-Type` C# 6+ 特性抛出错误 [英] `Add-Type` C# 6+ features throwing errors

查看:44
本文介绍了`Add-Type` C# 6+ 特性抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译 中的源代码,使用以下命令:>

I am trying to compile c# source code in powershell by using this command:

Add-Type -ReferencedAssemblies $assemblies -TypeDefinition $source

但是 功能不起作用,例如:

But c#-6.0 features are not working, for example:

Add-Type : c:\Users\...\AppData\Local\Temp\2\d2q5hn5b.0.cs(101) : Unexpected character '$'

对于代码:

new Problem($"... ({identifier})", node)

我正在使用

有没有办法解决这个问题?

Is there a way to fix this?

推荐答案

Powershell 使用 CodeDomProvider 来编译它们的程序集. 框架提供的版本只支持 C# 5,因此默认情况下没有新功能可用.

Powershell uses CodeDomProvider to compile their assemblies. The version provided with the framework just supports C# 5, so no new features are available by default.

但是,如果您提供另一个 CodeDomProvider,您可以编译任何语言,包括 C#6.有一个 CodeDomProvider 可用于 Roslyn(新的 .NET 编译器).您可以从 NuGet 下载 并使用 包含程序集添加类型.然后创建一个编译器实例并将其传递到 -CodeDomProvider 属性中.

However, if you provide another CodeDomProvider, you can compile any language, also C#6. There is a CodeDomProvider available for Roslyn (the new .NET compiler). You can download it from NuGet and include the assembly using Add-Type. Then create an instance of the compiler and pass that in the -CodeDomProvider attribute.

这篇关于`Add-Type` C# 6+ 特性抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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