在不同的框架上运行.NET Standard二进制文件 [英] Running .NET Standard binaries on different frameworks

查看:90
本文介绍了在不同的框架上运行.NET Standard二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解以.NET Standard 2为目标意味着.net核心,mono和整个.net框架之间的框架,但是我想了解这对由不同框架创建的二进制文件意味着什么。

I understand targeting .NET Standard 2 means that the frameworks between .net core, mono and the full .net framework, but I'd like to understand what that means for the binaries created by the different frameworks.

因此,如果我创建一个针对.NET Standard 2的控制台程序并使用.NET Framework进行编译,则仅完整的.NET Framework可以运行此文件吗?如果他们都可以运行文件,我将如何使用完整框架或Mono运行.NET Core .dll 可执行控制台?

So if I create a console program targeting .NET Standard 2 and compile using .NET Framework, can only the full .NET Framework run this file? If they can all run the files, how would I run the .NET Core .dll executable console using the full framework or Mono?

每个框架(针对.NET Standard)创建的二进制文件基本上可以在其他框架上运行吗?

So basically are the binaries created by each framework (targeting .NET Standard) able to run using the other frameworks?

推荐答案

我相信比较到便携式类库部分可能是最好的说法:

I believe the Comparison to Portable Class Libraries section probably says it best:


.NET Standard是便携式类库(PCL)

.NET Standard is the replacement for Portable Class Libraries (PCL).

.NET Standard本身不是运行时,它是一种针对多种不同类型的类型的转发机制运行时。因此,除了.NET Standard中的不可执行类库之外,无法创建其他任何东西,就像PCL一样。

.NET Standard is not itself a runtime it is a type forwarding mechanism for multiple different runtimes. Therefore, it is not possible to create anything but a non-executable class library in .NET Standard, just as was the case with PCLs.

这使类库可以由针对特定运行时(.NET Framework,.NET Core,Xamarin.iOS,Mono等)的可执行程序集使用。

This enables the class library to be consumed by executable assemblies that target specific runtimes (.NET Framework, .NET Core, Xamarin.iOS, Mono, etc).

它从类和接口的角度考虑这一点很有帮助。在伪代码中,.NET Standard是.NET Framework和.NET Core实现的接口。

It is helpful to think of this in terms of classes and interfaces. In pseudo-code, .NET Standard is an interface that .NET Framework and .NET Core implement.

public interface INetStandard
{
    // Only has API definitions
}

public class NetFramework : INetStandard
{
    // .NET Framework Runtime implemented here
}

public class NetCore : INetStandard
{
    // .NET Core Runtime implemented here
}

这使得可以将.NET Standard与.NET Framework或.NET Core一起使用,但是.NET Standard本身没有运行时,只有一组API可以在运行时之间共享。您可以在项目中定位这三个对象中的任何一个,但是只能执行.NET Standard实例化接口。

This makes it possible to use .NET Standard with either .NET Framework or .NET Core, but .NET Standard itself has no runtime, only a set of APIs that can be shared between runtimes. You can target any one of the three with your project, but you can't execute .NET Standard any more than you can instantiate an interface.


不幸的是,您不是第一个被问到此问题的人,除非Microsoft更清楚地说明.NET Standard实际上并未执行,否则您可能不会是最后一个。

Unfortunately, you are not the first to have asked about this and unless Microsoft makes the documentation more clear that .NET Standard does not actually execute, you likely won't be the last.

这篇关于在不同的框架上运行.NET Standard二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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