Hello, welcome to my simple project. This is my personal repository that contain several experiments on one application, including but not limited to:
- ASP.NET Core (previously known as ASP.NET 5)
- Entity Framework Core
- Single Page Application concept with AngularJS
- Responsive Design with Bootstrap
- Unit Test with XUnit
- ... etc
Table of Contents
The Main Goal
The goal i've made this repository is to make sure that i know how to develop, build and run a simple asp.net core application both on windows and linux platform.
You need to clone this repository to make sure you get the sample working source code.
$ git clone https://github.com/putuyoga/yoga-core.git yoga-core
- Install .NET Core SDK, obtain here.
- Add the database by executing
YogaCore.slnfile on Visual Studio and hit
F5key to run application.
This is not a joke. Oh yeah, .NET Core can run on linux too, not limited to windows operating system. So for every .NET developer there, start from now, you should familiarize yourself with Linux (lol).
Okay, before run the application, we need to install asp.net core to our linux machine.
1. Add the Repository
You can run the following command to subscribe to .net core repository feed :
$ sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
Obtain the server key:
$ sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893
Update the repos:
$ sudo apt-get update
2. Install .NET Core SDK
Run below command to install package of .NET Core SDK with its dependencies :
sudo apt-get install dotnet-dev-1.0.0-preview2-003121
3. Build & Run the Application
After the .NET Core SDK installed on your system, lets try build and run sample code that i have provide before. Run the following command :
$ cd ~/src/YogaCore/ $ dotnet restore $ dotnet run
the first command, make sure your working directory is the root of source code application, and the second comand is to restore the packages required by application. The last command to run the application.
Thats it ? If you look carefuly, it will be run, but can not connect to database as the database did not present yet. So you need to run
add_database.sh to properly add the database.
Quite simple ? Yes, even you did not need Visual Studio 2015 since it is only support Windows Platform. But do not worry, you can try Visual Studio Code, or maybe.... a Vim!
# Error when trying to obtain the Key Server
If your work environment are behind corporate proxy wall like me, maybe you getting that error like
connection time out or
the root of problem is we can not automatically add the signature from keyserver because that proxy, even we add the proxy configuration to command!
So the solution for that one is below :
- Run :
sudo apt-get updateand get the id of pubkey, as we do the same topic, so the key should be
- Open http://keyserver.ubuntu.com and search the key with
0x417A0893and hit the search button. You can obtain the public server key from there.
- Download the file/txt, whatever your tools, my favorit is using wget.
- And then run :
sudo apt-key add key.txtto add the key.
- Run again
sudo apt-get updateand you should get working repository.
Docker on Linux Platform
What is Docker and why it is so popular in last few years ? In a short, Docker is a leading containerization platform. In a long, see below explanation.
Instead having multiple virtual machine for each application, you just having multiple container on one host machine.
Much less resource usage comparing with virtual machine but still share same benefit, the isolation environment. See image below.
For linux platform, make sure
DOCKER are installed on your machine. For
how-to-install-that-docker, please refer to this link.
Thanks to the community, we already have an asp.net core docker image, so it will be less step required to build an image for asp.net application.
1. Modify Dockerfile
./src/YogaCore/Dockerfile as needed. If your work environment are behind proxy wall, just change the proxy configuration. If not, just delete the line that mention proxy.
$ vim ./yoga-core/src/YogaCore/Dockerfile
2. Build the Image
Change the working directory to YogaCore
$ cd ./yoga-core/src/YogaCore/
Build the container image
$ sudo docker build -t [your image name] .
Wait for a moment, after finish, make sure the image result are present.
$ docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE [your image name] latest ccb7994d2bc1 39 seconds ago 499.8 MB
3. Run the image
Try run the docker container quietly. If you love some details, just strip that
$ sudo docker run -t -d -p 5000:5000 [image name]
You can check if the containers running or not on your machine. Don't forget to note both of container id and container names (that one with fancy name lol).
$ sudo docker ps
4. Create the database
For now, your application is perfectly running. But your application currently didn't have any database. You should create one. Enter your running docker container with container id or name.
$ sudo docker exec -it [container id / container name] /bin/bash
And then move the working directory to
/app and execute migration command.
# cd /app # dotnet ef migrations add MyFirstMigration # dotnet ef database update
... to be continued