我正在尝试编写一些 C# .NET 应用程序来在 Nano Server 上执行它。这是源代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello hello world");
}
}
}
显然,这段代码在 Windows 10 系统上运行成功。
PS C:\Users\roza\Documents\Visual Studio 2017\Projects\ConsoleApp1\ConsoleApp1\bin\Debug> .\ConsoleApp1.exe
Hello hello world
据我了解,Nano Server 上默认安装了 .NET Core,所以我想有可能以某种方式在 Nano Server 上执行此代码。
当我将编译后的 *.exe 文件复制到 Nano Server 并第一次尝试在那里执行时,我收到了以下错误:
[Nano1X]: PS C:\Users\Administrator\Documents> .\ConsoleApp1.exe
Program 'ConsoleApp1.exe' failed to run: The subsystem needed to support the image type is not present.
+ CategoryInfo : ResourceUnavailable: (:) [], ApplicationFailedException
+ FullyQualifiedErrorId : NativeCommandFailed
[Nano1X]: PS C:\Users\Administrator\Documents>
然后我意识到 Nano Server 只支持 x64 架构,所以我通过“Project->ConsoleApp1 Properties->Build->Platform Target: x64”并在 Nano Server 上再次执行了我的应用程序。
[Nano1X]: PS C:\Users\Administrator\Documents> .\ConsoleApp1.exe
[Nano1X]: PS C:\Users\Administrator\Documents>
我什么也没打印出来:没有错误,也没有任何结果。这是什么原因,如果我真的希望我的 C# .NET 应用程序能够被 Nano Server 成功执行,我应该怎么做?