是否可以发布ASP.NET 5应用程序,以便目标计算机不需要安装DNX?

时间:2015-05-08 02:04:49

标签: c# asp.net .net asp.net-core

来自wiki for the main "aspnet" GitHub repo

  

DNX是一个包含构建和运行所需的所有位的SDK   一个应用程序,包括Core CLR的CLR。有可能   bin已与您的应用程序一起部署...... “。

我对这实际意味着什么感到困惑。基于此描述以及我在Microsoft公告和博客文章中看到的其他评论,您似乎可以使用ASP.NET 5应用程序并创建一个没有外部依赖关系的自包含bundle。该捆绑包将包含您的代码,DNX运行程序,~11兆字节CoreCLR以及您可能使用的任何其他NuGet依赖项。 “运行应用程序所需的所有位”,准备放到干净的平板目标机器上。

然而,当我使用dnu publish时,情况并非如此。生成的包包含我的代码,以及我实际使用的标准库部分的DLL。然而,它并没有拉动整个CoreCLR ......而且肯定不会引入DNX。我的run文件中的project.json命令变为run.cmd批处理文件,如下所示:

@"dnx.exe" --appbase "%~dp0approot\src\ConsoleApplication" Microsoft.Framework.ApplicationHost run %*

...建议DNX预计已安装在目标系统上,不在此捆绑包中。

我错过了一些基本的东西吗?如果您需要在目标系统上安装DNX,那么我不确定这种方法有什么优势。是否可以采取额外步骤,发布具有DNX和CoreCLR完全烘焙和自包含的捆绑包?

我看到dnu publish有一个可选的--native参数,但我不确定这是否相关。该参数希望您指定运行时。当我使用“clr”时,我收到错误消息“Native image generation is only supported for .NET Core flavors”。当我使用“coreclr”时,我得到了这个丑陋的堆栈跟踪:

C:\Users\Steve\Desktop\ConsoleApplication>dnu publish --native --runtime active
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Framework.Project, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Framework.Project, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ---> System.IO.FileNotFoundException: Could not load the specified file.
File name: 'Microsoft.Framework.Project'
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)
   at Microsoft.Framework.PackageManager.Publish.NativeImageGenerator.<>c.<Create>b__4_0(String r)
   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`3.GetEnumerator()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
   at Microsoft.Framework.PackageManager.Publish.NativeImageGenerator.Create(PublishOptions options, PublishRoot root, IEnumerable`1 contexts)
   at Microsoft.Framework.PackageManager.Publish.PublishManager.Publish()
   at Microsoft.Framework.PackageManager.Program.<>c__DisplayClass3_2.<Main>b__4()
   at Microsoft.Framework.Runtime.Common.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.Framework.PackageManager.Program.Main(String[] args)
System.IO.FileNotFoundException: Could not load the specified file.
File name: 'Microsoft.Framework.Project'
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyName(AssemblyName assemblyName)
   at System.Runtime.Loader.AssemblyLoadContext.Resolve(IntPtr gchManagedAssemblyLoadContext, AssemblyName assemblyName)

1 个答案:

答案 0 :(得分:12)

理论上,您应该能够将应用程序部署到甚至没有安装.NET Framework的计算机中,但我记得听说即使dnxcore今天也有一些.NET Framework依赖,并且稍后会消失(我可能会弄错) ,值得尝试这一点。)

假设存在并且您希望实现此目的,您应该使用--runtime开关,并且如果要将active作为值传递,则需要激活coreclr。

例如:

dnvm use 1.0.0-beta4 -r coreclr -p
Active Version           Runtime Architecture Location                       Al
                                                                             ia
                                                                             s
------ -------           ------- ------------ --------                       --
       1.0.0-beta4       clr     x64          C:\Users\Tugberk\.dnx\runtimes
       1.0.0-beta4       clr     x86          C:\Users\Tugberk\.dnx\runtimes
       1.0.0-beta4       coreclr x64          C:\Users\Tugberk\.dnx\runtimes
  *    1.0.0-beta4       coreclr x86          C:\Users\Tugberk\.dnx\runtimes

这应该将运行时捆绑在应用程序旁边。