简体   繁体   中英

Is it possible to compile a self-contained ASP.NET Core Web Application

I am looking for a way to generate a self-contained EXE that will launch ASP.NET Core (.NET Core). The project will simply serve up some static files from /wwwroot.

I have found a few resources that show how to make a Console Application into a self-contained EXE. These resources involve modifying project.json which does not seem to exist (at least on the initial template).

I have not see any that would allow me to do this with an ASP.NET Core application, is this possible or am I missing something?

Yes, it is.

However, if you can't find a project.json file in the folder of your project, you did something wrong when setting it up.

After you create a new folder for your project, navigate to that folder in the console and create a new web project with this command:

dotnet new -t web

The project.json file, along with all of the web template files, should be created at this moment.

Open the project.json file and remove (or comment out) the line

"type": "platform"

You should also add the following values after the "dependencies" block

"runtimes": { 
    "win10-x64": {}
},

Please note that the "win10-x64" should be changed to match the architecture of the machine your server will be running on. For a complete list of runtime IDs (RID) supported by the .net core, visit https://docs.microsoft.com/en-us/dotnet/articles/core/rid-catalog

Save your changes to the project.json file and run the restore command:

dotnet restore

And then build

dotnet build

You can find the *.exe file inside the bin/Debug/netcoreapp[version]/[RID].

Please note that if you run this executable from this folder, your models, views and controllers will not be found by the executable and your page will be blank.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM