ca9163d9
ca9163d9

Reputation: 29159

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                                                                                                             

Upvotes: 15

Views: 5451

Answers (3)

Deilan
Deilan

Reputation: 4886

.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

Upvotes: 8

Dipak Sharma
Dipak Sharma

Reputation: 1

Edit the .csproj file and specify the RuntimeIdentifier under property group for windows,ubuntu,osx.

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>win10-x64;osx.10.10-x64;ubuntu.14.04-x64</RuntimeIdentifiers>
  </PropertyGroup>

Than save and publish the application for different target machine

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

For more detail please read the blog on Creating and deploying .Net Core application on Windows/Linux/Mac http://www.spicy-dotnet.com/2017/10/creating-and-deploying-net-core.html

Upvotes: 0

Tratcher
Tratcher

Reputation: 6074

See step #3 in the instructions you linked. Standalone apps depend on Microsoft.NETCore.App without the 'Platform' type. Compare https://github.com/aspnet/MusicStore/blob/dev/samples/MusicStore/project.json#L58-L61 vs https://github.com/aspnet/MusicStore/blob/dev/samples/MusicStore.Standalone/project.json#L68-L70

Also step #4: They need a list of runtimes to publish for so you get all the right naitve binaries: https://github.com/aspnet/MusicStore/blob/dev/samples/MusicStore.Standalone/project.json#L80-L89

This should let you xcopy deploy the site and run it as a console app (there should be a MyApp.exe for Windows), but you won't be able to run it in IIS without AspNetCoreModule (installed via the Hosting bundle).

Upvotes: 0

Related Questions