V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Famio
V2EX  ›  程序员

.net core 1.1 项目如何编译到 exe?

  •  
  •   Famio · Feb 7, 2017 · 6857 views
    This topic created in 3366 days ago, the information mentioned may be changed or developed.
    以前 1.0 的时候都是在项目路径下修改 projects.json 里面的 runtime 参数。
    现在 1.1 MS 弃用 projects.json 了,用回 projects.csproj 了!
    懵逼,官方文档还是 1.0 时代,现在不知道怎么改才能把 dotnet 项目编译到 exe 了,有没有大神告知下。
    19 replies    2017-02-08 17:49:28 +08:00
    loqixh
        1
    loqixh  
       Feb 7, 2017
    <TargetFramework>netcoreapp1.1</TargetFramework>
    下加入一行
    <RuntimeIdentifiers>win10-x64;ubuntu.14.04-x64</RuntimeIdentifiers>
    然后用 dotnet publish -r ubuntu.14.04-x64
    但是会出错。。用 vs 带的发布功能也也会出错,应该是这个功能现在还有问题
    itfanr
        2
    itfanr  
       Feb 7, 2017 via Android
    微软总是在变…
    Famio
        3
    Famio  
    OP
       Feb 7, 2017
    @loqixh 是啊,我也看到了 RID 的字段,但是同样的,用 VS 和 VS code 都无法正确发布。
    奇了怪,按理说宇宙 IDE 不会犯这种错才对。现在跑程序只能 dotnet run 命令有点中二。
    emric
        4
    emric  
       Feb 7, 2017
    我也在关注这个问题。
    imcxy
        5
    imcxy  
       Feb 7, 2017   ❤️ 1
    @itfanr 说反了,其实是世界变太快,半年后某种东西完全没人跟了,微软只是保持跟上~
    beginor
        6
    beginor  
       Feb 7, 2017 via Android
    正准备入坑呢
    XiaoFaye
        7
    XiaoFaye  
       Feb 8, 2017
    .net core 没有 exe ,只有 dll , dll 之间的分别只是带不带入口函数而已。
    Soar360
        8
    Soar360  
       Feb 8, 2017
    need run time ..
    Famio
        9
    Famio  
    OP
       Feb 8, 2017
    @XiaoFaye 不是,很肯定是有的。以 standalone 方式打包就行,以前都 OK 的,自从玩了 vs2017 ,这配置文件改了,也没地方说明其中的字段含义。
    XiaoFaye
        10
    XiaoFaye  
       Feb 8, 2017
    @Famio RC2 的时候是有的,后来取消了。另外建议使用 LTS 的版本。
    imbushuo
        11
    imbushuo  
       Feb 8, 2017
    说来如果只需要针对 Windows 的话写 net462 的 target 就行了(JTL
    loqixh
        12
    loqixh  
       Feb 8, 2017
    @Famio 可以先用 preview2 的 1.1sdk ,用的是 projects.json 可以正常发布
    Famio
        13
    Famio  
    OP
       Feb 8, 2017
    @imbushuo 是的,没错,其实只针对 windows 的话,我直接用 C#写 console app 就好了。可是我需要跨平台才会用.net core.

    @loqixh 今天 vs2017 更新了,其中提到了 MSBuild 更新,我先跑完试试看吧,实在不想换环境,太麻烦了。
    weiceshi
        14
    weiceshi  
       Feb 8, 2017 via Android
    @itfanr 一行配置文件的事情也算改吗? vs17 打开 vs2003 写的.net 代码都能直接编译,这种级别的向下兼容
    水果呢? swift 2 2.3 3 4? os 升个小版本一大堆程序挂掉?
    loqixh
        15
    loqixh  
       Feb 8, 2017
    @Famio 刚试了下 是用法不对

    dotnet restore -r ubuntu.14.04-x64

    dotnet publish -r ubuntu.14.04-x64
    就正常发布了
    Famio
        16
    Famio  
    OP
       Feb 8, 2017
    @loqixh 我在 linux 下没有 dotnet restore -r 指令哇, help 了一下也没有相关的 runtime 参数。
    loqixh
        18
    loqixh  
       Feb 8, 2017
    <RuntimeIdentifiers>win10-x64;ubuntu.14.04-x64</RuntimeIdentifiers> 也不是必须的
    itfanr
        19
    itfanr  
       Feb 8, 2017 via Android
    @weiceshi 苹果自从有了 swift ,被骂的不行
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1853 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 79ms · UTC 16:18 · PVG 00:18 · LAX 09:18 · JFK 12:18
    ♥ Do have faith in what you're doing.