建立通过命令行的.NET应用程序的核心,因此,如果没有安装.NET的核心工作原理的机器上 [英] Building a .NET Core app via command line, so that it works on a machine without .NET Core installed

查看:278
本文介绍了建立通过命令行的.NET应用程序的核心,因此,如果没有安装.NET的核心工作原理的机器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的最终目标是建立一个跨平台(非Web)控制台应用程序,所以我探索.NET核心现在。

My end goal is to create a cross-platform (non-web) console application, so I'm exploring .NET Core right now.

在我以前的.NET项目,我做所有的开发在Visual Studio中,但我也造就了一批批/ MSBuild的文件,以便我可以建立整个项目的(包括设置,包的NuGet与二进制文件等zip文件。)的一个单一的点击。 下面是从以前的项目的一个例子。

In my previous .NET projects, I did all the development inside Visual Studio, but I also created a batch/MSBuild file so I could build the whole project (including setups, NuGet packages, zip files with binaries etc.) with one single click. Here's an example from a previous project.

在最后,我想要做类似的事情与我的.NET的核心测试项目。结果
,而现在我在第一次失败步:我不能建立它的Visual Studio之外,这样的结果工程安装另一台Windows计算机没有.NET核心结果
上(在第一步中,我忽略了跨-platform部分 - 我会很高兴得到它的工作在Windows上)

In the end, I want to do something similar with my .NET Core test project.
But right now I'm failing at the first step: I'm unable to build it outside Visual Studio, so that the result works on another Windows machine without .NET Core installed.
(in the first step, I'm ignoring the cross-platform part - I'll be happy to get it to work on Windows)

我设法得到它在Visual Studio中工作2015社区版如下:

I managed to get it to work inside Visual Studio 2015 Community Edition as follows:


  1. 建立在Visual Studio中新的项目:新建项目⇒网络⇒控制台应用程序(包)

创建新的发布配置文件在Visual Studio中(生成⇒菜单中的发布)。结果
这将创建 PowerShell脚本(和的an XML文件

create new publish profile inside Visual Studio ("Build" ⇒ "Publish" in the menu).
This will create a Powershell script (and an XML file with settings)

这里是在GitHub上我的测试项目。

在我的Build⇒菜单中的发布了时,Visual Studio显然b中的结果是略超过90再次执行先前创建的PowerShell脚本。结果$ b $ MB,包括在598文件夹825文件,如下所示:

When I do "Build" ⇒ "Publish" in the menu again, Visual Studio apparently executes the previously created PowerShell script again.
The result is slightly over 90 MB, consists of 825 files in 598 folders, and looks like this:

当我复制另一台机器上(Win 7的/ .NET 4安装/ .NET核心的不可以安装),它的工作原理。

When I copy it on another machine (Win 7 / .NET 4 installed / .NET Core not installed), it works.

这个答案并的这个答案听起来像我可以使用 DNU发布来实现通过命令行相同的结果。结果
我知道,.NET的核心部分还在移动的目标,现在,让显然 DNU 现在 DOTNET 代替

This answer and this answer sound like I can use dnu publish to achieve the same result via the command line.
I understand that parts of .NET Core are still moving targets right now, so apparently dnu is now dotnet instead.

于是,我就执行 DOTNET发布(创造的a批处理文件)吧:

So I tried to execute dotnet publish (and created a batch file) for it:

dotnet publish "%~dp0\src\CoreTestVisualStudio" -c Release -r win7-x64 -o "%~dp0\release\cli"

结果由一个 .exe文件文件,并在一堆的DLL,只有25个文件和1.5 MB的,所有的一个单一的文件夹:

The result consists of an .exe file and a bunch of DLLs, only 25 files and 1.5 MB, all in one single folder:

显然,.NET核心运行时丢失在这里,和正如所料,这个应用程序崩溃时我尝试执行它没有.NET核心安装一台机器(同上述)上。

Obviously the .NET Core runtime is missing here, and as expected, this app crashes when I try to execute it on a machine without .NET Core installed (the same one as mentioned above).

我试图执行的the PowerShell脚本(当我创建的发布配置文件这是创建)的outside的Visual Studio ,但失败了,因为剧本预计一些参数,我不知道该怎么过:

I tried to execute the Powershell script (which was created when I created the publish profile) outside Visual Studio, but it failed because the script expects some parameters and I don't know what to pass:

param($publishProperties, $packOutput, $nugetUrl)

有也是此行的脚本:

# to learn more about this file visit http://go.microsoft.com/fwlink/?LinkId=524327

...但只是链接指向的的//blogs.msdn.com/b/webdev/\">the登陆页面。

...but the link just points to the landing page of the .NET Web Development and Tools Blog.

我在做什么错

我知道? .NET核心的第一个版本主要集中在ASP.NET,但我的理解是,ASP.NET应用程序的核心只是控制台应用程序一样,所以我想一个基本的控制台应用程序现在会的工作。结果
在另一方面,大多数
控制台应用程序的入门文档仍然下落不明,所以也许它只是太早 DOTNET发布的控制台应用程序还没有完成?

I know that the first release of .NET Core mainly focuses on ASP.NET, but as I understood it, ASP.NET Core apps are just console apps as well, so I thought a basic console app would work now.
On the other hand, most of the console app "getting started" docs are still missing, so maybe it's just too early and dotnet publish for console apps is not finished yet?

之后的几个编辑天:我怀疑我没有做错什么,而且它在the.NET核心命令行工具的一个问题,所以我的它发布到命令行工具的问题跟踪

推荐答案

问题解决了!

我张贴上的.NET核心命令行工具的问题跟踪,并转身出,这是在 DOTNET发布中的错误 - 它没有捆绑C ++运行时,这是在没有.NET核心安装在计算机上运行的应用程序编译所需

Problem solved!
I posted it on the issue tracker of the .NET Core command line tools, and it turned out that it was a bug in dotnet publish - it didn't bundle the C++ runtime, which is needed to execute the compiled app on a machine without .NET Core installed.


  • 临时解决方案是安装C ++运行时。

  • The temporary solution was to install the C++ runtime.

真实的解决方案在拉申请 3天后,发前,这是包括在最新的安装程序现在。结果
在这个版本中, DOTNET发布 确实捆绑C ++运行时,这样的结果将一台机器上工作,没有.NET的核心。

The "real" solution was made in a pull request three days ago, which is included in the latest installer now.
With this version, dotnet publish does bundle the C++ runtime, so the result will work on a machine without .NET Core.

这篇关于建立通过命令行的.NET应用程序的核心,因此,如果没有安装.NET的核心工作原理的机器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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