Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a self contained .Net core application?

I created an asp.net core on .Net core and planned to publish it on a Windows server. I don't want to install anything on the server so I want the application be self contained.

I selected the menu "Build-> Publish MyApp" and then created File system based method. It generated the following files in the folder and I copied it to the server. However, how to run it on the server which doesn't have .Net core installed?

Name                                                                                                                   
----                                                                                                                   
refs                                                                                                                   
runtimes                                                                                                               
appsettings.json                                                                                                       
MyService.deps.json                                                                                        
MyService.dll                                                                                              
MyService.pdb                                                                                              
MyService.runtimeconfig.json                                                                               
Microsoft.ApplicationInsights.AspNetCore.dll                                                                           
Microsoft.ApplicationInsights.dll                                                                                      
Microsoft.AspNetCore.Antiforgery.dll                                                                                   
Microsoft.AspNetCore.Authorization.dll                                                                                 
Microsoft.AspNetCore.Cors.dll                                                                                          
Microsoft.AspNetCore.Cryptography.Internal.dll                                                                         
Microsoft.AspNetCore.DataProtection.Abstractions.dll                                                                   
Microsoft.AspNetCore.DataProtection.dll                                                                                
Microsoft.AspNetCore.Diagnostics.Abstractions.dll                                                                      
Microsoft.AspNetCore.Hosting.Abstractions.dll                                                                          
Microsoft.AspNetCore.Hosting.dll                                                                                       
Microsoft.AspNetCore.Hosting.Server.Abstractions.dll                                                                   
Microsoft.AspNetCore.Html.Abstractions.dll                                                                             
Microsoft.AspNetCore.Http.Abstractions.dll                                                                             
Microsoft.AspNetCore.Http.dll                                                                                          
Microsoft.AspNetCore.Http.Extensions.dll                                                                               
Microsoft.AspNetCore.Http.Features.dll                                                                                 
Microsoft.AspNetCore.HttpOverrides.dll                                                                                 
Microsoft.AspNetCore.JsonPatch.dll                                                                                     
Microsoft.AspNetCore.Localization.dll                                                                                  
Microsoft.AspNetCore.Mvc.Abstractions.dll                                                                              
Microsoft.AspNetCore.Mvc.ApiExplorer.dll                                                                               
Microsoft.AspNetCore.Mvc.Core.dll                                                                                      
Microsoft.AspNetCore.Mvc.Cors.dll                                                                                      
Microsoft.AspNetCore.Mvc.DataAnnotations.dll                                                                           
Microsoft.AspNetCore.Mvc.dll                                                                                           
Microsoft.AspNetCore.Mvc.Formatters.Json.dll                                                                           
Microsoft.AspNetCore.Mvc.Localization.dll                                                                              
Microsoft.AspNetCore.Mvc.Razor.dll                                                                                     
Microsoft.AspNetCore.Mvc.Razor.Host.dll                                                                                
Microsoft.AspNetCore.Mvc.TagHelpers.dll                                                                                
Microsoft.AspNetCore.Mvc.ViewFeatures.dll                                                                              
Microsoft.AspNetCore.Razor.dll                                                                                         
Microsoft.AspNetCore.Razor.Runtime.dll                                                                                 
Microsoft.AspNetCore.Routing.Abstractions.dll                                                                          
Microsoft.AspNetCore.Routing.dll                                                                                       
Microsoft.AspNetCore.Server.IISIntegration.dll                                                                         
Microsoft.AspNetCore.Server.Kestrel.dll                                                                                
Microsoft.AspNetCore.WebUtilities.dll                                                                                  
Microsoft.DotNet.InternalAbstractions.dll                                                                              
Microsoft.EntityFrameworkCore.dll                                                                                      
Microsoft.EntityFrameworkCore.Relational.dll                                                                           
Microsoft.EntityFrameworkCore.SqlServer.dll                                                                            
Microsoft.Extensions.Caching.Abstractions.dll                                                                          
Microsoft.Extensions.Caching.Memory.dll                                                                                
Microsoft.Extensions.Configuration.Abstractions.dll                                                                    
Microsoft.Extensions.Configuration.Binder.dll                                                                          
Microsoft.Extensions.Configuration.dll                                                                                 
Microsoft.Extensions.Configuration.EnvironmentVariables.dll                                                            
Microsoft.Extensions.Configuration.FileExtensions.dll                                                                  
Microsoft.Extensions.Configuration.Json.dll                                                                            
Microsoft.Extensions.DependencyInjection.Abstractions.dll                                                              
Microsoft.Extensions.DependencyInjection.dll                                                                           
Microsoft.Extensions.DependencyModel.dll                                                                               
Microsoft.Extensions.DiagnosticAdapter.dll                                                                             
Microsoft.Extensions.FileProviders.Abstractions.dll                                                                    
Microsoft.Extensions.FileProviders.Composite.dll                                                                       
Microsoft.Extensions.FileProviders.Physical.dll                                                                        
Microsoft.Extensions.FileSystemGlobbing.dll                                                                            
Microsoft.Extensions.Globalization.CultureInfoCache.dll                                                                
Microsoft.Extensions.Localization.Abstractions.dll                                                                     
Microsoft.Extensions.Localization.dll                                                                                  
Microsoft.Extensions.Logging.Abstractions.dll                                                                          
Microsoft.Extensions.Logging.Console.dll                                                                               
Microsoft.Extensions.Logging.Debug.dll                                                                                 
Microsoft.Extensions.Logging.dll                                                                                       
Microsoft.Extensions.Logging.Filter.dll                                                                                
Microsoft.Extensions.Logging.TraceSource.dll                                                                           
Microsoft.Extensions.ObjectPool.dll                                                                                    
Microsoft.Extensions.Options.ConfigurationExtensions.dll                                                               
Microsoft.Extensions.Options.dll                                                                                       
Microsoft.Extensions.PlatformAbstractions.dll                                                                          
Microsoft.Extensions.Primitives.dll                                                                                    
Microsoft.Extensions.WebEncoders.dll                                                                                   
Microsoft.Net.Http.Headers.dll                                                                                         
Newtonsoft.Json.dll                                                                                                    
NLog.config                                                                                                            
NLog.dll                                                                                                               
NLog.Extensions.Logging.dll                                                                                            
Remotion.Linq.dll                                                                                                      
System.Collections.NonGeneric.dll                                                                                      
System.Collections.Specialized.dll                                                                                     
System.ComponentModel.Primitives.dll                                                                                   
System.ComponentModel.TypeConverter.dll                                                                                
System.Data.Common.dll                                                                                                 
System.Diagnostics.Contracts.dll                                                                                       
System.Interactive.Async.dll                                                                                           
System.Net.WebSockets.dll                                                                                              
System.Runtime.Serialization.Primitives.dll                                                                            
System.Text.Encodings.Web.dll                                                                                          
web.config                                                                                                             
like image 207
ca9163d9 Avatar asked Aug 02 '16 20:08

ca9163d9


People also ask

What is a self contained app in .NET Core?

Self-contained Application Self-contained applications are applications which include . NET Core runtime when we publish it. It can run on a machine which does not have . NET Core runtime installed.

What is a self contained application?

A self-contained application consists of a single, installable bundle that contains your application and a copy of the JRE needed to run the application. When the application is installed, it behaves the in the same way as any native application.


1 Answers

.NET Core 1.0-wise solution:

1) Open the project.json file and remove type = "platform" from dependency of netcoreapp1.0:

"frameworks": {
  "netcoreapp1.0": {
    "dependencies": {
      "Microsoft.NETCore.App": {
        "version": "1.0.1"
      }
    }
  } 
}

2) Specify runtimes which you want to target (.NET Core Runtime IDentifier catalog):

"runtimes": {
     "win7-x64": {},
     "osx.10.10-x64": {},
     "ubuntu.14.04-x64": {}
}

3) Run dotnet restore in Command Prompt at the project or solution folder level.

4) Build:

dotnet build -r win7-x64
dotnet build -r osx.10.10-x64
dotnet build -r ubuntu.14.04-x64

5) Publish:

dotnet publish -c release -r win7-x64
dotnet publish -c release -r osx.10.10-x64
dotnet publish -c release -r ubuntu.14.04-x64

In folder %ProjectFolder%\bin\Release\netcoreapp1.0\ will be a folder for each runtime you published for.

Credit goes to Scott Hanselman.

It's worth also reading the official article about Application Deployment

like image 137
Deilan Avatar answered Oct 12 '22 01:10

Deilan