ASP.NET v5 without DNX

元气小坏坏 提交于 2019-12-10 16:13:24

问题


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.


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/30939816/asp-net-v5-without-dnx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!