Self Contained Deployment of .Net core Console Application on Ubuntu
Off late i am involved in migrating my organization applications from .net to .net core , so that our application can be deployed in cross platform scenarios and offcourse focus is on towards migration to cloud infrastructure.
Just in case if you have not got chance to read about .net core, this is the best place to get a quick idea about same.
Now area where i am going to focus in this article is how to use self contained deployment feature from .net core to run your dot net core application in Linux.
Self contained deployment is a model where you do not need dot net core platfrom or runtime to be installed in target OS you can just copy your application in OS and start using it. Isnt that cool ☺
If you want to learn more about .net core deployment please refer this article.
Some Prerequisites -
1. Create a dot net core application with visual studio or dotnet cli
2. obviously have an Ubuntu system ☺.
1. Most of articles refer to csproj structure but i had a hindrance to use vs2015 and project.json structure.
2. How to get linux executables?
3. How to run these executables in ubuntu?
I will focus on above points in this article -
after following prerequisite 1 your project.json may look like below-
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
1. Addition of runtime identifier , this can vary based on your target OS , please select right RID from here
2. Comment out "type": "platform", from project.json.
so now after above changes project.json should look like this for ubuntu -
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
//"type": "platform",
"version": "1.0.1"
},
"Newtonsoft.Json": "10.0.3"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
},
"runtimes": {
"win10-x64": {},
"ubuntu.16.04-x64": {},
"ubuntu.14.04-x64": {}
}
}
1. go to directory where project.json exists.
2. open cmd prompt there.
3. run dotnet restore command
4. run dotnet publish -c release -r "ubuntu.14.04-x64"
note here that -r contains RID for which you want to generate executable.
And done executable are generated .
1. even though it is a self contained deployment , you need to have some Prerequisites in OS ,follow this for respective OS where you want to deploy application.
2. Copy executable files from \bin\Release\netcoreapp1.0\ubuntu.14.04-x64 to ubuntu file system.
3. open terminal and to path where you copied executable.
4. cd Publish
5. chmod +x YourApplicationName
6. ./YourApplicationName
Now your console app should be up and running in UBUNTU.
Just in case if you have not got chance to read about .net core, this is the best place to get a quick idea about same.
Now area where i am going to focus in this article is how to use self contained deployment feature from .net core to run your dot net core application in Linux.
Self contained deployment is a model where you do not need dot net core platfrom or runtime to be installed in target OS you can just copy your application in OS and start using it. Isnt that cool ☺
If you want to learn more about .net core deployment please refer this article.
Some Prerequisites -
1. Create a dot net core application with visual studio or dotnet cli
2. obviously have an Ubuntu system ☺.
Till now all good but problem, where i got stuck was -
1. Most of articles refer to csproj structure but i had a hindrance to use vs2015 and project.json structure.
2. How to get linux executables?
3. How to run these executables in ubuntu?
I will focus on above points in this article -
So how do you do this with Project.json -
after following prerequisite 1 your project.json may look like below-
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
Now to make your package self contained deployment following changes will be needed-
1. Addition of runtime identifier , this can vary based on your target OS , please select right RID from here
2. Comment out "type": "platform", from project.json.
so now after above changes project.json should look like this for ubuntu -
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
//"type": "platform",
"version": "1.0.1"
},
"Newtonsoft.Json": "10.0.3"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
},
"runtimes": {
"win10-x64": {},
"ubuntu.16.04-x64": {},
"ubuntu.14.04-x64": {}
}
}
BUT why "win10-x64": {}" ?
it is needed when you run dotnet publish command, else you get this error.How to get linux executables?
following are steps-1. go to directory where project.json exists.
2. open cmd prompt there.
3. run dotnet restore command
4. run dotnet publish -c release -r "ubuntu.14.04-x64"
note here that -r contains RID for which you want to generate executable.
And done executable are generated .
How to run these executable in Ubuntu?
Now once you have executable following steps need to be followed-1. even though it is a self contained deployment , you need to have some Prerequisites in OS ,follow this for respective OS where you want to deploy application.
2. Copy executable files from \bin\Release\netcoreapp1.0\ubuntu.14.04-x64 to ubuntu file system.
3. open terminal and to path where you copied executable.
4. cd Publish
5. chmod +x YourApplicationName
6. ./YourApplicationName
Now your console app should be up and running in UBUNTU.
Comments
Post a Comment