Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 "%~dp0approot\src\ConsoleApplication" 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:\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) 
like image 389
Steve Perkins Avatar asked May 08 '15 02:05

Steve Perkins


People also ask

Which command is used to publish .NET application as a self contained app to create a Windows 64 bit executable?

Use the dotnet command to start the appdll> command to start your app. . NET Core 2.1 SDK doesn't produce platform-specific executables for apps published framework-dependent.

How do you distribute a .NET application?

The . NET Framework provides the following options for distributing applications: Use XCOPY or FTP. Because common language runtime applications are self-describing and require no registry entries, you can use XCOPY or FTP to simply copy the application to an appropriate directory.


1 Answers

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:\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 

This should bundle the runtime along side your application.

like image 137
tugberk Avatar answered Oct 13 '22 10:10

tugberk