【问题标题】:Self contained .net core web app自包含的 .net 核心网络应用程序
【发布时间】:2017-06-26 08:44:07
【问题描述】:

我有一个 .net 核心网络应用程序,我想在 Windows 或 OSX 上作为常规应用程序安装。如果我将其部署为自包含应用程序,运行 .exe 时 Web 服务器会启动吗?而且,如何配置应用程序将侦听的端口?

我的长期目标是创建一个 UI,让用户可以配置一些东西,并让应用可以从 Windows Store 和/或 Mac AppStore 分发,但我不确定这是否可能?

【问题讨论】:

标签: asp.net-core


【解决方案1】:

为了作为一个独立的应用程序部署,您需要在您的 csproj 文件中指定一个运行时。 :

<PropertyGroup>
    <RuntimeIdentifiers>win10-x64;osx.10.11-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
</PropertyGroup>

比为该运行时发布应用程序:

dotnet publish -c Release -r win10-x64

如果您想更改应用程序正在侦听的端口,您需要在 Program.cs 文件中进行设置:

    public static void Main(string[] args)
    {
        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .UseApplicationInsights()
            // Set url and port here.
            .UseUrls("http://0.0.0.0:5005")
            .Build();

        host.Run();
    }

您现在可以通过在发布目录中运行 yourapp.exe 文件来运行您的应用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 2021-07-04
    • 1970-01-01
    • 2020-11-23
    • 2019-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多