ASP.NET v5 without DNX
Asked Answered
C

2

4

I understand that DNX provides the ability to invoke the various new package management features of ASP.NET v5 apps.

However, is it possible to "build" one of these apps (using DNX etc) and "precompile" them in such a way that they can be deployed to (using Octopus) and run on a unmodified IIS server using .NET framework 4.5?

I had the option to target .NET 4.5 when creating the project, and while installing DNX on our build server is unlikely to be a problem, it's too soon to push it out to our production web servers.

Croak answered 19/6, 2015 at 13:47 Comment(1)
Have you tried dnu build and/or dnu publish?Arrow
C
1

I discovered that this is indeed possible.

I published my app by running the following command in the same directory as the project.json file:

dnu publish --runtime runtimeX --no-source

Where runtimeX is an appropriate installed runtime found using:

dnvm list

This only lists the installed runtimes though so the following is needed to get the full name to use as the argument to dnu:

dnvm name default

You can check the args for dnvm's "name" command but essentially you specify the processor bitness and runtime version and you get the properly formatted name back.

Once you've done this, take the contents of bin\output and run it up in IIS or IISExpress. Worked like a charm for me, even though I copied this output to my other development VM that has no VS2015/DNX tools installed yet.

Croak answered 24/6, 2015 at 10:52 Comment(2)
You aren't running asp.net 5 without DNX. The dnu publish --runtime option includes a local copy of the DNX version specified in the publish folder. So yes you can bundled the dependency with the application but the dependency still exists. If you delete the runtime folder from the deployed location the application will fail.Measles
That's a fair point. I guess really I meant I wanted to deploy to a machine that has nothing more than a regular pre-v5 ASP.NET installation.Croak
M
1

No. You said you can target .Net 4.5 in ASP.NET but that isn't exactly accurate you can target dnx451 which is .Net Full Framework 4.5.1 + DNX.

DNX is not "installed" in the same fashion as .Net Framework. It isn't really an installation more like an xcopy. DNVM simply downloads a specific copy of the DNX and puts it into a folder under c:\Users\.dnx\runtimes. If you didn't want to use dnx you could just copy the folder. When an application references a specific version of the runtime it just calls dnx.exe within the correct folder by convention c:\Users\<User>\.dnx\runtimes\<dnx-runtimetype-os-architecture.version>\bin\dnx.exe

If you want to even avoid a separate step the --runtime option in dnu publish will include a copy within the application folder structure /approot/runtimes by taking a copy from the local dev machine. Neil's answer provides more details. It avoids the requirement of installing the dnx separately but the dnx is still used. Using --no-source is not necessary and independent of decision to bundled the runtime with the application.

In case you are wondering how does IIS "find" the dnx to begin execution, when you publish the project a project is included in /wwwroot/bin/AspNetLoader.dll. This provides an entry point for IIS. Also a small web.config is also included which provides the location to the dnx executable.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="bootstrapper-version" value="1.0.0-beta4" />
    <add key="runtime-path" value="..\approot\runtimes" />
    <add key="dnx-version" value="1.0.0-beta6-12120" />
    <add key="dnx-clr" value="coreclr" />
    <add key="dnx-app-base" value="..\approot\src\AspDotNetFiveDemo.Web" />
  </appSettings>
</configuration>

This 'bootstrap' is really only to provide backwards compatibility with IIS. It isn't used in other environment. For example if self hosting using http.sys DNX.exe is just called directly and provided the assemblies and parameters.

Measles answered 29/6, 2015 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.