Hello World with .NET Core


.NET Core is Microsoft’s new cross-platform Command Language Runtime (CLR). This post is an elementary getting started guide where I create, build and run a “Hello World!” console application with .NET Core.

Let’s begin by downloading and installing .NET Core for your platform. To create a new console applications run

dotnet new

That will create two files – project.csproj and Program.cs. Edit Program.cs using your favorite editor.

I recommend using the multi-platform VS Code. You can extend the capabilities of VS Code by downloading extensions from the VisualStudio Marketplace. VS Code should prompt you to download the C# extension when you open Program.cs.

To build the new program from the command line run

dotnet build

To execute the program run

dotnet run

You can also edit, and run or debug the program using VS Code, as shown in this screenshot

.NET CLR with VS Code

Console applications can be very powerful, but .NET CLR can also be used to build Web applications using ASP.NET Core.

Advertisements

git branch


This post lists some useful Git commands related to branching and merging. remote is used as a generic placeholder for remote name below. It may be origin. branch is used for branch name.

List all branches

git branch -v

List all remote branches

git branch -r -v

See status log with branch refs

git log --decorate=full

Pull changes in specified remote branch, merge and commit into current branch

git pull remote branch

Fetch changes from remote branch into FETCH_HEAD, but continue on current branch

git fetch remote branch

Switch to FETCH_HEAD branch

git checkout FETCH_HEAD

Create a new branch with specified name from current start point

git checkout -b branch

Switch to master branch of origin

git checkout master

Merge and commit changes in specified branch into the current branch

git merge remote/branch

Merge changes in specified branch, result available in working tree to commit (history is not preserved)

git merge --squash remote/branch

Run your favorite merge tool to resolve conflicts (I use meld, on Mac OS X)

git mergetool -t meld

Diff of file with version on HEAD (or branch name)

git diff [--cached] HEAD file

Delete a local branch

git branch -d branch

Delete remote branch in cloned repo (can restore from origin with pull)

git branch -d -r remote/branch

Permanently delete branch ref from remote (use caution)

git push remote --delete branch
## OR
git push remote :branch

Create a new branch at current start point, but continue on current branch

git branch branch

Checkout and switch to a branch, or start tracking and switch to a remote branch with same name

git checkout branch

Push branch to remote (add -f to force update)

git push [-f] remote branch

Push all branches to remote

git push --all remote

Track the specified remote branch as upstream

git branch -u remote/branch

Reset to previous commit on current branch

git reset HEAD~