针对网络标准 1.6 的 .net 核心应用程序中的动态引用?
Dynamic reference in a .net core app targeting net standard 1.6?
我正在尝试在面向 .net 标准 1.6 的 C# .net 核心应用程序中使用 dynamic
变量。 (platform?library?framework?meta-framework?)我第一次遇到这个问题是在一个真实的应用中,但是我已经把它减少到最小的复现了。
project.json
{
"version": "1.0.0-*",
"buildOptions": { "emitEntryPoint": true },
"dependencies": { "NETStandard.Library": "1.6.0" },
"frameworks": {
"netstandard1.6": { "imports": "dnxcore50" }
},
"runtimes": { "win10-x64": {} }
}
Program.cs
using System;
public class Program {
public static void Main(string[] args) {
dynamic hello = "hello world";
Console.WriteLine(hello);
}
}
当我尝试构建它时,我在 Console.WriteLine(hello);
上遇到一个构建错误。
CS0656 Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
是否可以在面向 netstandard 1.6 的应用程序中使用 dynamic
变量?怎么样?
添加 System.Dynamic.Runtime and Microsoft.CSharp 作为依赖项。
如果您正在编写一个应用程序,而不是一个库,您应该使用 Microsoft.NETCore.App
,而不是 NETStandard.Library
和 netcoreapp1.0
,而不是 netstandard1.6
。这样做可以解决您的问题。
如果要在库(或不依赖Microsoft.NETCore.App
的应用程序)中使用dynamic
,需要添加Microsoft.CSharp
作为依赖。
右键单击项目 > 管理 NuGet 包... > 添加以下两个突出显示的包:
我正在尝试在面向 .net 标准 1.6 的 C# .net 核心应用程序中使用 dynamic
变量。 (platform?library?framework?meta-framework?)我第一次遇到这个问题是在一个真实的应用中,但是我已经把它减少到最小的复现了。
project.json
{
"version": "1.0.0-*",
"buildOptions": { "emitEntryPoint": true },
"dependencies": { "NETStandard.Library": "1.6.0" },
"frameworks": {
"netstandard1.6": { "imports": "dnxcore50" }
},
"runtimes": { "win10-x64": {} }
}
Program.cs
using System;
public class Program {
public static void Main(string[] args) {
dynamic hello = "hello world";
Console.WriteLine(hello);
}
}
当我尝试构建它时,我在 Console.WriteLine(hello);
上遇到一个构建错误。
CS0656 Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
是否可以在面向 netstandard 1.6 的应用程序中使用 dynamic
变量?怎么样?
添加 System.Dynamic.Runtime and Microsoft.CSharp 作为依赖项。
如果您正在编写一个应用程序,而不是一个库,您应该使用 Microsoft.NETCore.App
,而不是 NETStandard.Library
和 netcoreapp1.0
,而不是 netstandard1.6
。这样做可以解决您的问题。
如果要在库(或不依赖Microsoft.NETCore.App
的应用程序)中使用dynamic
,需要添加Microsoft.CSharp
作为依赖。
右键单击项目 > 管理 NuGet 包... > 添加以下两个突出显示的包: