philippgille / hello-netcoreapp

Basic .NET Core console application with additional scripts and files for building the app and creating release artifacts for a framework-dependent deployment, self-contained deployment, Docker image, Chocolatey package and AppImage
GNU General Public License v3.0
6 stars 5 forks source link
appimage appveyor bash bash-script build build-automation chocolatey continuous-deployment continuous-integration csharp docker docker-image dockerfile dotnet dotnet-core hello-world myget portable powershell powershell-script
Windows build Linux build Docker Code quality Test coverage
AppVeyor build status Travis CI build Status Docker Hub automated build Codacy code quality
Better Code Hub code quality
Boilerplate
Nothing to test
Binaries Chocolatey package
GitHub Releases MyGet

hello-netcoreapp

hello-netcoreapp is a basic .NET Core console application that prints "Hello World!". This repository contains additional scripts and files for building the app and creating release artifacts for a framework-dependent deployment (FDD), self-contained deployment (SCD), Docker image, Chocolatey package and AppImage.

This repository is meant to be a starting point for any new .NET Core console application. You can fork it and base your project upon it. If you improve anything in your fork, please create a PR ☺ . PRs Welcome

The basic app was created using dotnet new console with the .NET Core SDK 2.0 and then extended for our purposes.

Contents

Terminology

For more info about FDD and SCD see: https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/

Directory structure

Build

Via cloud service

AppVeyor

This repository contains .appveyor.yml, which is a configuration file for the CI / CD cloud service AppVeyor.

It's configured to do the following:

  1. Run the build script build.ps1, which produces *.zip archives for FDD and SCD, as well as a Chocolatey package
  2. If a Git tag was pushed:

    • Deploy all artifacts to this repository's GitHub Releases

      Note: If the release already exists, existing files get overwritten (not all, only those where a new file was built, keeping files from the Travis CI build in case it finished first)

    • Deploy the Chocolatey package to this app's MyGet feed

Travis CI

This repository contains .travis.yml, which is a configuration file for the CI / CD cloud service Travis CI.

It's configured to do the following:

  1. Run the build script build.sh, which produces *.tar.gz archives for FDD and SCD, as well as an AppImage
  2. If a Git tag was pushed:
    • Deploy all artifacts to this repository's GitHub Releases

      Note: If the release already exists, existing files get overwritten (not all, only those where a new file was built, keeping files from the AppVeyor build in case it finished first)

Docker Cloud

The Docker image for Linux containers gets automatically build by Docker Cloud and pushed to the Docker Hub repository. This is because Docker Hub itself doesn't support multi-stage builds as of now (2017-07-08).

Locally

You can create the FDD, SCD, Docker image, Chocolatey package and AppImage locally as well.

FDD + SCD + Chocolatey package + AppImage

Build all artifacts

Depending on your OS and installed software, run the following scripts:

System Installed Run Artifacts
Windows .NET Core SDK build.ps1
  • FDDs, e.g. hello-netcoreapp_v0.1.0_netcoreapp2.0.zip
  • SCDs, e.g. hello-netcoreapp_v0.1.0_linux-x64.zip
  • Chocolatey packages (if installed), e.g.: hello-netcoreapp.0.1.0.nupkg
Windows Docker build-with-docker.ps1
  • FDD: hello-netcoreapp_v0.1.0_netcoreapp2.0.tar.gz
  • SCDs, e.g. hello-netcoreapp_v0.1.0_linux-x64.tar.gz
  • Chocolatey packages, e.g.: hello-netcoreapp.0.1.0.nupkg
  • AppImage: hello-netcoreapp_v0.1.0_linux-x64.AppImage
Linux .NET Core SDK build.sh
  • FDD: hello-netcoreapp_v0.1.0_netcoreapp2.0.tar.gz
  • SCDs, e.g. hello-netcoreapp_v0.1.0_linux-x64.tar.gz
  • AppImage: hello-netcoreapp_v0.1.0_linux-x64.AppImage
Linux Docker build-with-docker.sh
  • FDD: hello-netcoreapp_v0.1.0_netcoreapp2.0.tar.gz
  • SCDs, e.g. hello-netcoreapp_v0.1.0_linux-x64.tar.gz
  • Chocolatey packages, e.g.: hello-netcoreapp.0.1.0.nupkg
  • AppImage: hello-netcoreapp_v0.1.0_linux-x64.AppImage

The SCDs that are built depend on the runtime identifiers in the *.csproj. To add or remove SCDs, just edit that file accordingly (see available runtime identifiers).

Note: When running the build-with-docker.ps1 script, the build.sh script will be executed inside of a Docker container. This script requires some files to have LF as line ending instead of CRLF. Commiting files with CRLF endings won't help - check your Git configuration core.autocrlf instead.

Build one artifact

To build just one artifact, you can pass the necessary arguments to the script, like so:

The same restrictions apply as when building all artifacts with calling the build script without arguments, so the AppImage and Chocolatey packages aren't built in all cases.

Docker image

Note: When building the Linux container image in Windows, the build.sh script will be executed inside of the Docker builder container. This script requires some files to have LF as line ending instead of CRLF. Commiting files with CRLF endings won't help - check your Git configuration core.autocrlf instead.

In the root directory of the repository, depending on which container host system you want to target:

Note: You don't need to create a Windows container image for using Docker in Windows. Linux containers work just fine on Windows. Creating a Windows container image is specifically for actual Windows containers, see https://docs.microsoft.com/en-us/virtualization/windowscontainers/about/.

Run

You can run the console app either as FDD, SCD, Docker container, Chocolatey package or AppImage.

All artifacts are available for download from this repository's GitHub Releases. The Chocolatey package is also available on this app's MyGet feed.

Alternatively you can build the artifacts on your own (see the Build section in this README).

FDD

Depending on the operating system you use when building, there are multiple FDDs:

Note: For running hello-netcoreapp_v0.1.0_netcoreapp2.0 you need to have the .NET Core runtime installed. The other FDDs are for Windows only and do not require any runtime being installed. Windows already comes with the full .NET Framework, so those FDDs work out of the box. Use the net461 version for up-to-date Windows systems and the net451 one for Windows 8.1 and Windows Server 2008 R2.

You can copy the archive (hello-netcoreapp_v0.1.0_netcoreapp2.0.zip or hello-netcoreapp_v0.1.0_netcoreapp2.0.tar.gz) to wherever you want to run the app, extract the archive and run:

SCD

Note: Depending on your system you might need to install the dependencies listed here:

  • Windows
  • Linux (For example for Ubuntu that's: apt-get install -y --no-install-recommends libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev libcurl4-openssl-dev libssl-dev uuid-dev unzip)
  • macOS

Copy the archive (for example hello-netcoreapp_v0.1.0_linux-x64.zip or hello-netcoreapp_v0.1.0_linux-x64.tar.gz) to wherever you want to run the app (only the OS has to match), extract the archive and run:

Docker container

Chocolatey package

Note 1: You can only install and run Chocolatey packages on Windows!

Note 2: Depending on your system you might need to install Microsoft Visual C++ 2015 Redistributable Update 3, as mentioned in the documentation about the .NET Core prerequisites for Windows

First you need to install the package with one of the following ways:

Then run: hello-netcoreapp

Note: The package is installed in %ChocolateyInstall%/lib (e.g. C:\ProgramData\Chocolatey\lib)

AppImage

Note 1: You can only use AppImages on Linux and you must either have fuse installed or mount or extract the AppImage, see AppImage/AppImageKit/wiki/FUSE

Note 2: Depending on your system you might need to install the dependencies listed in the documentation about the .NET Core prerequisites for Linux. For example for Ubuntu that's:

  • apt-get install -y --no-install-recommends libunwind8 libunwind8-dev gettext libicu-dev liblttng-ust-dev libcurl4-openssl-dev libssl-dev uuid-dev unzip

After downloading the AppImage, you have to make it executable: chmod u+x hello-netcoreapp_v0.1.0_linux-x64.AppImage

Then run: hello-netcoreapp_v0.1.0_linux-x64.AppImage

For integrating the AppImage into your OS (MIME type registration, start menu), you can run the optional AppImage daemon. Read more about it here: https://github.com/AppImage/AppImageKit/blob/appimagetool/master/README.md#appimaged-usage

Simplify running the app

Note: This is not necessary if you installed the app with Chocolatey.

The app is portable, meaning the FDD or SCD can reside anywhere on your system (for example in $env:USERPROFILE\MyPortableApps\hello-netcoreapp on Windows or $HOME/myPortableApps/hello-netcoreapp on Linux), and Docker containers can be run anywhere anyway.

Now you should do the following, so you don't have to enter the full path of the executable (for FDD / SCD) or full docker command when you want to run the app:

Now you can run the following command on any OS and from any directory (and also pass arguments):

Note: You shouldn't add the whole app directory to the PATH, because the directory contains many files and in some cases this leads to tab auto-completion for files like hello-netcoreapp.deps.json.

Uninstall