Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

c# - Can an ASP.NET 5 application be published such that the target machine doesn't need DNX installed?

From the wiki for the main "aspnet" GitHub repo:

"The DNX is an SDK containing all of the bits needed to build and run an application, including the CLR in the case of Core CLR. It can be bin deployed with your application...".

I'm a bit confused on what this actually means. Based on this description, and other comments I've seen in Microsoft announcements and blog posts, it would seem that you could take an ASP.NET 5 application and create a self-contained bundle with no outside dependencies. The bundle would include your code, the DNX runner, the ~11 megabyte CoreCLR, and any other NuGet dependencies you might use. "All the bits needed to run your application", ready to be dropped onto a clean slate target machine.

However, when I use dnu publish, that's not what happens. The resulting bundle contains my code, and DLL's for the pieces of the standard library that I'm actually using. However, it's not pulling in the whole CoreCLR... and it's certainly not pulling in DNX. The run command from my project.json file gets turned into a run.cmd batch file that looks like this:

@"dnx.exe" --appbase "%~dp0approotsrcConsoleApplication" Microsoft.Framework.ApplicationHost run %*

... suggesting that DNX is expected to already be installed on the target system, outside of this bundle.

Am I missing something fundamental here? If you need DNX installed on the target system, then I'm not sure what advantages are provided by this approach at all. Is there an additional step that one can take, to publish a bundle that has DNX and CoreCLR fully baked-in and self-contained?

I see that dnu publish has an optional --native argument, but I'm not sure that this is relevant. That argument wants you to specify a runtime. When I use "clr" I get the error message, "Native image generation is only supported for .NET Core flavors". When I use "coreclr", I get this ugly stacktrace:

C:UsersSteveDesktopConsoleApplication>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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In theory, you should be able to deploy your application into a machine where even .NET Framework is not installed but I remember hearing that even the dnxcore has some .NET Framework dependencies today and will be gone later (I could be mistaken, it's worth trying this out).

Assuming this is there and you want to achieve this, you should indeed use the --runtime switch and you need to have coreclr active if you are going to pass active as value.

For example:

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

This should bundle the runtime along side your application.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...