Skip to content
Permalink
Browse files

.NET Core

  • Loading branch information...
dahlia committed Apr 23, 2019
1 parent 7154d67 commit b07d3ec251ab715a7692d495114d5d41e4a54a12
@@ -12,11 +12,13 @@ to be replaced using sed. -->
<IncludeFilters>
<FilterEntry>
<ModuleMask>Libplanet</ModuleMask>
<ModuleMask>Libplanet.Stun</ModuleMask>
</FilterEntry>
</IncludeFilters>
<ExcludeFilters>
<FilterEntry>
<ModuleMask>Libplanet.Tests</ModuleMask>
<ModuleMask>Libplanet.Stun.Tests</ModuleMask>
</FilterEntry>
</ExcludeFilters>
</Filters>
@@ -3,6 +3,8 @@ matrix:
- os: linux
dist: xenial
language: csharp
dotnet: 2.2.203
mono: none
addons:
apt:
packages:
@@ -18,6 +20,7 @@ matrix:
- os: osx
osx_image: xcode10.1
language: csharp
dotnet: 2.2.106
cache:
directories:
- $HOME/Library/Caches/Homebrew
@@ -31,9 +34,6 @@ matrix:
- $HOME/AppData/Local/NuGet/v3-cache
filter_secrets: false # https://travis-ci.community/t/current-known-issues-please-read-this-before-posting-a-new-topic/264/10

env:
- PROJECTS="Libplanet.Stun Libplanet"

solution: Libplanet.sln
install:
- |
@@ -58,17 +58,9 @@ install:
brew update
brew cask install powershell
elif [[ "$TRAVIS_OS_NAME" = "windows" ]]; then
# MSBuild
{
echo "#!/bin/bash"
echo "'/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/MSBuild.exe'" '"$@"'
} > /usr/bin/msbuild
chmod +x /usr/bin/msbuild
# NuGet
curl -o /usr/bin/nuget.exe \
https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
chmod +x /usr/bin/nuget.exe
# .NET Core SDK 2.2+
choco install dotnetcore-sdk
dotnet --info
# xmllint
mkdir /tmp/libxml2
@@ -93,7 +85,7 @@ install:
mkdir /tmp/dotcover
pushd /tmp
wget \
https://download.jetbrains.com/resharper/ReSharperUltimate.2018.3.3/JetBrains.dotCover.CommandLineTools.2018.3.3.zip
https://download.jetbrains.com/resharper/ReSharperUltimate.2018.3.4/JetBrains.dotCover.CommandLineTools.2018.3.4.zip
pushd dotcover
7z x ../JetBrains.dotCover.CommandLineTools.*.zip
popd
@@ -105,20 +97,26 @@ install:
fi
fi
set +ev
- nuget restore Libplanet.sln
# Restore NuGet packages (dependencies)
- |
for i in 1 2 3; do
# Retry up to 3 times
dotnet restore -s https://api.nuget.org/v3/index.json && break
done
script:
# Fail fast if anything in below commands fails
- set -e

# If a tag is pushed, the NuGet package version has to be the same to
# the tag name.
# the tag name, without any suffix.
- |
version="$(xmllint \
--xpath './Project/PropertyGroup/Version/text()' \
version_prefix="$(xmllint \
--xpath './Project/PropertyGroup/VersionPrefix/text()' \
Libplanet/Libplanet.csproj)"
- 'echo "NuGet package version: $version"'
- '[[ "$TRAVIS_TAG" = "" || "$version" = "$TRAVIS_TAG" ]]'
- 'echo "VersionPrefix: $version_prefix"'
- '[[ "$TRAVIS_TAG" = "" || "$version_prefix" = "$TRAVIS_TAG" ]]'

# If a tag is pushed, there has to be an entry in CHANGES.md for the version.
- |
@@ -131,24 +129,43 @@ script:
# Check coding styles
- hooks/check-bom

# Append suffix to the package version if it's not a tag push:
# - "dev.BUILDNO+DATE" (e.g., 0.1.2-dev.34+20190423)
# - "nightly.DATE" (e.g., 0.1.2-nightly.20190423)
- |
if [[ "$TRAVIS_EVENT_TYPE" = "cron" ]]; then
version_suffix="nightly.$(date +%Y%m%d)"
nupkg_version="$version_prefix-$version_suffix"
elif [[ "$TRAVIS_TAG" = "" ]]; then
version_suffix="dev.$TRAVIS_BUILD_NUMBER"
nupkg_version="$version_prefix-$version_suffix"
commit_date="$(git log -n1 --pretty=%cd --date=format:%Y%m%d)"
version_suffix="$version_suffix+$commit_date"
else
nupkg_version="$TRAVIS_TAG"
fi
# Build the whole solution
- |
for project in $PROJECTS; do
msbuild -p:Configuration=Release -r $project
done
if [[ "$TRAVIS_TAG" = "" ]]; then
dotnet build \
-c Release \
--version-suffix "$version_suffix" \
-p:NoPackageAnalysis=true
else
dotnet build \
-c Release
fi
# Run unit tests
- |
for project in $PROJECTS; do
msbuild -p:Configuration=Release -t:build,XunitTest $project.Tests
done
- dotnet test -c Release -v n

# Run unit tests with coverage report
- cat codecov.yml | curl --data-binary @- https://codecov.io/validate
- |
if [[ "$TRAVIS_OS_NAME" = "windows" && "$CODECOV_TOKEN" != "" ]]; then
msbuild -p:Configuration=Debug -p:DebugType=full -r
for assembly in Libplanet.Tests/bin/Debug/*/Libplanet.Tests.dll; do
dotnet build -c Debug
for assembly in *.Tests/bin/Debug/*/*.Tests.dll; do
echo "$assembly:"
dotCover_config="$(cat .travis.dotCover.xml)"
assembly_abspath="$(cygpath -w "$(pwd)/$assembly")"
@@ -162,33 +179,24 @@ script:
# Build Libplanet.*.nupkg
- |
rm -f "Libplanet/bin/Release/Libplanet.$version.nupkg"
msbuild_props=('Configuration=Release')
if [[ "$TRAVIS_TAG" = "" && "$version" = *-dev ]]; then
# Append "+buildno" to the package version (e.g., 0.1.2-dev+34)
# if it's not a tag push.
if [[ "$TRAVIS_EVENT_TYPE" = "cron" ]]; then
appended_version="${version/-dev/-nightly}.$(date +%Y%m%d)"
nupkg_version="$appended_version"
else
nupkg_version="$version.$TRAVIS_BUILD_NUMBER"
appended_version="$nupkg_version+$(date +%Y%m%d)"
fi
msbuild_props+=("PackageVersion=$appended_version")
msbuild_props+=('NoPackageAnalysis=true')
msbuild -r "${msbuild_props[@]/#/-p:}" Libplanet
if [[ "$TRAVIS_TAG" = "" ]]; then
echo "Version suffix: $version_suffix"
dotnet pack Libplanet \
-c Release \
--version-suffix "$version_suffix" \
-p:NoPackageAnalysis=true
else
nupkg_version="$version"
appended_version="$version"
dotnet pack Libplanet \
-c Release
fi
msbuild -t:pack "${msbuild_props[@]/#/-p:}" Libplanet
ls -al Libplanet/bin/Release/
unzip -l "Libplanet/bin/Release/Libplanet.$nupkg_version.nupkg" \
> /tmp/nupkgfiles
cat /tmp/nupkgfiles
grep -i Libplanet.dll /tmp/nupkgfiles
grep -i Libplanet.Stun.dll /tmp/nupkgfiles
if [[ "$nupkg_version" != "$version" ]]; then
rm -f "Libplanet/bin/Release/Libplanet.$version.nupkg"
if [[ "$nupkg_version" != "$version_prefix" ]]; then
rm -f "Libplanet/bin/Release/Libplanet.$version_prefix.nupkg"
fi
# Build docs using DocFX
@@ -4,11 +4,8 @@
{
"label": "Build",
"type": "shell",
"command": "msbuild",
"args": [
"-r",
"-p:GenerateFullPaths=true"
],
"command": "dotnet",
"args": ["build"],
"group": "build",
"presentation": {
"reveal": "silent"
@@ -18,14 +15,8 @@
{
"label": "Test",
"type": "shell",
"command": "msbuild",
"args": [
"-r",
"-p:GenerateFullPaths=true",
"-t:Build",
"-t:XunitTest",
"Libplanet.Tests"
],
"command": "dotnet",
"args": ["test"],
"group": "build",
"presentation": {
"reveal": "always",
@@ -25,22 +25,20 @@ for purposes:
Prerequisites
-------------

If you use Linux or macOS you need [Mono], which provides C# compiler and
.NET VM. You could install it by `sudo apt install mono-devel` command
if you use Ubuntu Linux. If you use macOS and [Homebrew], you can install
it by `brew cask install mono-mdk` command.
You need [.NET Core] SDK 2.2+ which provides the latest C# compiler and .NET VM.
Read and follow the instruction to install .NET Core SDK on
the [.NET Core downloads page][1].
FYI if you use macOS and [Homebrew] you can install it by
`brew cask install dotnet-sdk` command.

If you are on Windows you need things like C# compiler included in
[Build Tools for Visual Studio 2017][1]. Choose the following workloads
during installation:
Make sure that your .NET Core SDK is 2.2 or higher. You could show
the version you are using by `dotnet --info` command.

- <q>Windows</q> → <q>.NET desktop build tools</q>
- <q>Other Toolsets</q> → <q>.NET Core build tools</q>

These tools should bring MSBuild, the Libplanet project uses to build, as well.
Check if `msbuild` is available on the shell or Command Prompt. If it fails
to find command named `msbuild` it might be not installed correctly or its
directory might be missing in the `PATH` environment.
If it's Windows please check if the environment variable named
`MSBuildSDKsPath` refers to the proper version of .NET Core SDK.
If you use Visual Studio 2017 (not 2019) you can only use .NET Core 2.2.105
at the highest. .NET Core SDK higher than the version 2.2.105 is not
recognized Visual Studio 2017.

Although it is not necessary, you should install a proper IDE for .NET
(or an [OmniSharp] extension for your favorite editor — except it takes
@@ -52,21 +50,21 @@ Unless you already have your favorite setup, we recommend you to use
made .NET as well. So Visual Studio Code has a [first-party C# extension][2]
which works well together.

[Mono]: https://www.mono-project.com/
[.NET Core]: https://dot.net/
[Homebrew]: https://brew.sh/
[OmniSharp]: http://www.omnisharp.net/
[Visual Studio Code]: https://code.visualstudio.com/
[1]: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017
[1]: https://dotnet.microsoft.com/download
[2]: https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp


Build
-----

The following command installs dependencies (required library packages) and
builds the *Libplanet* project:
builds the entire *Libplanet* solution:

msbuild -r Libplanet
dotnet build


Tests [![Build Status](https://travis-ci.com/planetarium/libplanet.svg?branch=master)][Travis CI] [![Codecov](https://codecov.io/gh/planetarium/libplanet/branch/master/graph/badge.svg)][2]
@@ -86,10 +84,9 @@ one in *Libplanet* or *Libplanet.Stun* projects.
If there's *Libplanet.Foo.Bar* class there also should be
*Libplanet.Tests.Foo.BarTest* to test it.

To build and run unit tests at a time execute the below commands:
To build and run unit tests at a time execute the below command:

msbuild -r -t:Build,XunitTest Libplanet.Tests
msbuild -r -t:Build,XunitTest Libplanet.Stun.Tests
dotnet test

[Travis CI]: https://travis-ci.com/planetarium/libplanet
[2]: https://codecov.io/gh/planetarium/libplanet
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@@ -2,7 +2,18 @@
<PropertyGroup>
<PackageId>Libplanet</PackageId>
<Title>Libplanet</Title>
<Version>0.3.0-dev</Version>
<VersionPrefix>0.3.0</VersionPrefix>
<!-- Note: don't be confused by the word "prefix" here. It's merely a
version without suffix like "-dev.123". See the following examples:
Version: 1.2.3-dev.456
VersionPrefix: 1.2.3
VersionSuffix: dev.456
If it's a stable release the version becomes like:
Version: 1.2.3
VersionPrefix: 1.2.3
VersionSuffix: (N/A)
Note that the version suffix is filled through CLI option of dotnet command.
-->
<Summary>A .NET library for creating multiplayer online game in decentralized fashion.</Summary>
<Description>A .NET library for creating multiplayer online game in decentralized fashion.
See also the docs for details:
@@ -66,17 +66,19 @@ In the near future, we are going to submit it to [Unity Asset Store] too.
Build
-----

You could build a *Libplanet.dll* assembly from the source code.
You could build a *Libplanet.dll* and *Libplanet.Stun.dll* assemblies
from the source code.

The following command installs dependencies (required library packages) and
builds the whole Libplanet solution:

~~~~~~~~ bash
msbuild -r
dotnet build
~~~~~~~~

Note that `msbuild` is distributed together with Mono framework or
Visual Studio.
Note that `dotnet` command is distributed together with [.NET Core] SDK.

If you'd like to contribute code to the Libplanet project in earnest,
please read our [contributor guide](CONTRIBUTING.md).

[.NET Core]: https://dot.net/
@@ -16,9 +16,9 @@ fi

version="$1"

if [[ "$version" = *-dev ]]; then
if [[ "$version" = *-* ]]; then
{
echo "$0: error: the version number must not end with -dev suffix:"
echo "$0: error: the version number must not end with any suffix:"
echo " $version"
} > /dev/stderr
exit 1
@@ -27,15 +27,15 @@ fi
csproj="$root/Libplanet/Libplanet.csproj"
if command -v xmllint > /dev/null; then
csproj_version="$(xmllint \
--xpath './Project/PropertyGroup/Version/text()' \
--xpath './Project/PropertyGroup/VersionPrefix/text()' \
"$csproj")"
else
version_regex='<Version>([0-9]+\.[0-9]+\.[0-9]+)</Version>'
if [[ "$(grep '<Version>[^>]*</Version>' "$csproj")" =~ $version_regex ]]
regex='<VersionPrefix>([0-9]+\.[0-9]+\.[0-9]+)</VersionPrefix>'
if [[ "$(grep '<VersionPrefix>[^>]*</VersionPrefix>' "$csproj")" =~ $regex ]]
then
csproj_version="${BASH_REMATCH[1]}"
else
echo "$0: error: failed to find <Version> tag from $csproj file" \
echo "$0: error: failed to find <VersionPrefix> tag from $csproj file" \
> /dev/stderr
exit 1
fi
Oops, something went wrong.

0 comments on commit b07d3ec

Please sign in to comment.
You can’t perform that action at this time.