#!/bin/bash
-# Usages:
-# dotnet-build.sh build [Target] [Configuration]
-# dotnet-build.sh pack [NuSpec] [Version]
-
usage() {
- echo "Usage:"
- echo " $0 restore TARGET"
- echo " - TARGET : Project Directory, Solution File(.sln), Project JSON(.project.json)"
- echo " $0 build TARGET CONFIGURATION"
- echo " - TARGET : Project Directory, Solution File(.sln), Project File(.csproj)"
- echo " - CONFIGURATION : Configuration name defined in .csproj (Debug, Release)"
- echo " $0 pack NUSPEC VERSION CONFIGURATION"
- echo " - NUSPEC : .nuspec file path"
- echo " - VERSION : Version of nuget package to be created"
- echo " - CONFIGURATION : Configuration name defined in .csproj (Debug, Release)"
+ echo "usage: "
+ echo " $0 restore <project> [-s <source>] ..."
+ echo " $0 build <project> [-c <configuration>] ..."
+ echo " $0 pack <project> [-c <configuration>] [-v <version>] ..."
+ echo " $0 install <project> [-t <type>]"
}
exit_on_error() {
fi
}
-nuget_retry() {
- local RETRY=3
+retry() {
+ local CMD=$1; shift
+ local RETRY=$1; shift
local RET=0
local n=0
until [ $n -ge $RETRY ]; do
sleep 2
echo "Retry $n ....."
fi
- echo "+ nuget $@"
- nuget $@
+ echo "+ $CMD $@"
+ $CMD $@
RET=$?
if [ $RET -eq 0 ]; then
break
exit_on_error $RET
}
-cs_build() {
+run_nuget() {
+ retry nuget 3 $@
+}
+
+run_xbuild() {
echo "+ xbuild $@"
xbuild $@
exit_on_error $?
}
-restore() {
- local TARGET=$1; shift
-
- if [ -d $TARGET ]; then
- local PROJFILES=$(find $TARGET -name "*.project.json")
- for P in $PROJFILES; do
- nuget_retry restore $P $@
- done
- elif [ -f $TARGET ]; then
- nuget_retry restore $TARGET $@
- else
- echo "Invalid nuget restore target."
- exit 1
- fi
-}
-
-build_solution() {
- local TARGET=$1; shift
- local CONFIGURATION=$1; shift
-
- cs_build $TARGET /p:Configuration=$CONFIGURATION $@
+run_dotnet() {
+ echo "+ dotnet $@"
+ dotnet $@
+ exit_on_error $?
}
build_project() {
- local TARGET=$1; shift
- local CONFIGURATION=$1; shift
+ local CSPROJ=$1; shift
- local PROJECT=${TARGET%.*}
- local PROJECT_JSON=$PROJECT.project.json
+ local PROJNAME=${CSPROJ%.*}
+ local PROJECT_JSON=$PROJNAME.project.json
if [ -f $PROJECT_JSON ]; then
- restore $PROJECT_JSON
+ run_nuget restore $PROJECT_JSON
+ fi
+ run_xbuild $CSPROJ /p:Configuration=$CONFIGURATION $@
+}
+
+cmd_restore() {
+ if $USE_DOTNET_CLI; then
+ local OPTS=""
+ [ -n "$SOURCE" ] && OPTS="$OPTS -s $SOURCE"
+ run_dotnet restore $PROJECT $OPTS $@
+ else
+ if [[ $PROJECT_TYPE == "dir" ]]; then
+ local PROJFILES=$(find $PROJECT -name "*.project.json")
+ for p in $PROJFILES; do
+ run_nuget restore $p $@
+ done
+ else
+ run_nuget restore $PROJECT $@
+ fi
fi
- cs_build $TARGET /p:Configuration=$CONFIGURATION $@
}
-build() {
- local TARGET=$1; shift
- local CONFIGURATION=$1; shift
+cmd_build() {
+ if $USE_DOTNET_CLI; then
+ cmd_restore # restore first
+ local OPTS=""
+ [ -n "$CONFIGURATION" ] && OPTS="$OPTS -c $CONFIGURATION"
+ [ -n "$VERSION" ] && OPTS="$OPTS /p:Version=$VERSION"
+ run_dotnet build $PROJECT $OPTS $@
+ else
+ if [[ $PROJECT_TYPE == "dir" ]]; then
+ local PROJFILES=$(find $PROJECT -name "*.csproj")
+ for p in $PROJFILES; do
+ build_project $p $@
+ done
+ elif [[ $PROJECT_TYPE == "sln" ]]; then
+ run_xbuild $PROJECT /p:Configuration=$CONFIGURATION $@
+ elif [[ $PROJECT_TYPE == "csproj" ]]; then
+ build_project $PROJECT $@
+ fi
+ fi
+}
- if [[ $TARGET == *".sln" ]]; then
- build_solution $TARGET $CONFIGURATION $@
- elif [[ $TARGET == *".csproj" ]]; then
- build_project $TARGET $CONFIGURATION $@
+cmd_pack() {
+ if $USE_DOTNET_CLI; then
+ local OPTS=""
+ [ -n "$CONFIGURATION" ] && OPTS="$OPTS -c $CONFIGURATION"
+ [ -n "$VERSION" ] && OPTS="$OPTS /p:Version=$VERSION"
+ run_dotnet pack $PROJECT $OPTS $@
else
- local PROJFILES=$(find $TARGET -name "*.csproj")
- for P in $PROJFILES; do
- build_project $P $CONFIGURATION $@
+ local NUSPEC=($PROJECT)
+ if [ -d $PROJECT ]; then
+ NUSPEC=($(find $PROJECT -name "*.nuspec"))
+ fi
+ for x in ${NUSPEC[@]}; do
+ run_nuget pack $x -Version $VERSION -Properties Configuration=$CONFIGURATION $@
done
fi
}
-pack() {
- local NUSPEC=$1; shift
- local VERSION=$1; shift
- local CONFIGURATION=$1; shift
+cmd_install() {
+ local DEST=$1; shift
+
+ mkdir -p $DEST
- if [ -f $NUSPEC ]; then
- nuget_retry pack $NUSPEC -Version $VERSION -Properties Configuration=$CONFIGURATION $@
+ if [[ $TYPE == "assembly" ]]; then
+ find $PROJECT/bin -name $PROJECT.dll -exec install -p -m 644 {} $DEST \;
+ elif [[ $TYPE == "nupkg" ]]; then
+ find . -name "$PROJECT.[0-9]*.nupkg" -exec install -p -m 644 {} $DEST \;
fi
}
+#########################################################################
+
+# Parse arguments
+
+while getopts "s:c:v:t:" o; do
+ case "$o" in
+ s) SOURCE=${OPTARG} ;;
+ c) CONFIGURATION=${OPTARG} ;;
+ v) VERSION=${OPTARG} ;;
+ t) TYPE=${OPTARG} ;;
+ *) usage; exit 1 ;;
+ esac
+done
+shift $((OPTIND-1))
+
+if [ $# -lt 2 ]; then
+ usage; exit 1
+fi
+
CMD=$1; shift
-case $CMD in
- restore)
- if [ $# -ge 1 ]; then
- restore $@
- exit 0
- fi
- ;;
- build)
- if [ $# -ge 2 ]; then
- build $@
- exit 0
+PROJECT=$1; shift
+
+# Check whether the project can be built using dotnet-cli
+PROJECT_TYPE=""
+USE_DOTNET_CLI=false
+if [ -f $PROJECT ]; then
+ if [[ $PROJECT == *".sln" ]]; then
+ PROJECT_TYPE="sln"
+ VS_VERSION=$(grep -E "^VisualStudioVersion" $PROJECT | cut -f2 -d= | xargs)
+ if [[ $VS_VERSION == "15."* ]]; then
+ USE_DOTNET_CLI=true
fi
- ;;
- pack)
- if [ $# -ge 3 ]; then
- pack $@
- exit 0
+ elif [[ $PROJECT == *".csproj" ]]; then
+ PROJECT_TYPE="csproj"
+ RET=$(grep "Microsoft.NET.Sdk" $PROJECT | wc -l)
+ if [ $RET -gt 0 ]; then
+ USE_DOTNET_CLI=true
fi
- ;;
-esac
+ elif [[ $PROJECT == *".project.json" ]]; then
+ PROJECT_TYPE="project.json"
+ fi
+elif [ -d $PROJECT ]; then
+ PROJECT_TYPE="dir"
+ RET=$(find $PROJECT -name "*.project.json" | wc -l)
+ if [ $RET -eq 0 ]; then
+ CSPROJS=$(find $PROJECT -name "*.csproj")
+ for p in $CSPROJS; do
+ RET=$(grep "Microsoft.NET.Sdk" $p | wc -l)
+ if [ $RET -gt 0 ]; then
+ USE_DOTNET_CLI=true
+ break;
+ fi
+ done
+ fi
+fi
+
+# Disable telemetry of dotnet
+export DOTNET_CLI_TELEMETRY_OPTOUT=1
+
+# To build PCL projects ReferenceAssemblyRoot should be set.
+# dotnet-cli will find reference assemblies for PCL in this path.
+export ReferenceAssemblyRoot=/usr/lib/mono/xbuild-frameworks
+
+# Dump
+echo "----------------------------------------------"
+echo "CMD=$CMD"
+echo "PROJECT=$PROJECT"
+echo "PROJECT_TYPE=$PROJECT_TYPE"
+echo "USE_DOTNET_CLI=$USE_DOTNET_CLI"
+echo "SOURCE=$SOURCE"
+echo "CONFIGURATION=$CONFIGURATION"
+echo "VERSION=$VERSION"
+echo "TYPE=$TYPE"
+echo "REST ARGS=$@"
+echo "----------------------------------------------"
-usage; exit 1
+case $CMD in
+ restore) cmd_restore $@ ;;
+ build) cmd_build $@ ;;
+ pack) cmd_pack $@ ;;
+ install) cmd_install $@ ;;
+ *) usage; exit 1 ;;
+esac
Name: dotnet-build-tools
Summary: Tools for building C# API projects
-Version: 1.0.12
+Version: 1.2.0
Release: 1
Group: Development/Libraries
License: MIT and Apache-2.0
URL: https://www.tizen.org
Source0: %{name}-%{version}.tar.gz
Source1: macros.dotnet-build-tools
+Source2: dotnet-dev-linux-x64.latest.tar.gz
+Source3: deps.tar.gz
AutoReqProv: no
+BuildRequires: patchelf
+
Requires: corefx-managed-ref
+Requires: referenceassemblies-pcl
Requires: mono-compat
Requires: mono-devel
Requires: mono-compiler
+%define debug_package %{nil}
+
%description
Build target files (.Targets) and Tools (including NuGet.exe) for building
C# Deivce API with xbuild in GBS environment.
+%define CLI_PATH %{_datadir}/dotnet-build-tools/cli
+
%prep
%setup -q
%build
+# Prepare dotnet-cli
+mkdir -p dotnet
+tar xf %{SOURCE2} -C ./dotnet
+tar xf %{SOURCE3} -C ./dotnet
+
+for file in $( find ./dotnet -name "dotnet" -type f )
+do
+ patchelf --set-interpreter %{CLI_PATH}/deps/ld-linux-x86-64.so.2 ${file}
+ patchelf --set-rpath %{CLI_PATH}/deps/ ${file}
+done
+for file in $( find ./dotnet -type f \( -name "*.so" -or -name "*.so.*" \) -not -name "*.dbg" -not -name "ld-*.so*" )
+do
+ patchelf --set-rpath %{CLI_PATH}/deps/ ${file}
+done
%install
%define NuGetDir %{_datadir}/NuGet
%define XBuildDir /usr/lib/mono/xbuild
-%define ToolsDir %{_datadir}/DotnetBuildTools
+%define ToolsDir %{_datadir}/dotnet-build-tools
# Tizen.GBS.BuildTasks
mkdir -p %{buildroot}%{XBuildDir}/14.0/Microsoft.Common.targets/ImportAfter
# RPM Macros
install -D -p -m 0644 %{S:1} %{buildroot}%{_sysconfdir}/rpm/macros.dotnet-build-tools
+# dotnet-cli
+mkdir -p %{buildroot}%{ToolsDir}/cli
+cp -fr ./dotnet/* %{buildroot}%{ToolsDir}/cli
+ln -s %{ToolsDir}/cli/dotnet %{buildroot}%{_bindir}/dotnet
+
%files
%license LICENSE.NuGet
%config(noreplace) %{_sysconfdir}/rpm/macros.dotnet-build-tools
## Configuration ###############################################################
-%_with_corefx 1
-
%_dotnet_assembly_path /usr/share/dotnet.tizen/framework
-%_mono_assembly_path /usr/lib/assembly
-
-%_mono_subrpm 0
+%_dotnet_nuget_source /nuget
-################################################################################
+###############################################################
%dotnet_assembly_path %{_dotnet_assembly_path}
%dotnet_assembly_files %{_dotnet_assembly_path}/*.dll
+%dotnet_nuget_source %{_dotnet_nuget_source}
%_dotnet_build_conf %{lua:if tonumber(rpm.expand("0%{?tizen_build_devel_mode}")) == 1 then print "Debug" else print "Release" end}
-%dotnet_nuget_source /nuget
-
%_nuget_package \
%package nuget\
Summary: NuGet package for %{name}\
/nuget/*.nupkg\
%{nil}
-%_mono_package \
-%package mono\
-Summary: %{name} for Mono Runtime\
-Group: Development/Libraries\
-AutoReqProv: no\
-%description mono\
-%{name} for Mono Runtime\
-%files mono\
-%manifest %{name}.manifest\
-%%license LICENSE\
-%attr(644,root,root) %{_mono_assembly_path}/*.dll\
-%{nil}
-
%dotnet_import_sub_packages \
%_nuget_package \
-%if 0%{?_mono_subrpm} \
-%_mono_package \
-%endif \
%{nil}
%dotnet_restore() \
-dotnet-build restore %{1} %{?2} %{?3} %{?4} %{?5} %{?6} \
+dotnet-build -s %{_dotnet_nuget_source} restore %{1} %{?2} %{?3} %{?4} %{?5} %{?6} \
%{nil}
%dotnet_build() \
-dotnet-build build %{1} %{_dotnet_build_conf} %{?2} %{?3} %{?4} %{?5} %{?6} \
+dotnet-build -c %{_dotnet_build_conf} -s %{_dotnet_nuget_source} build %{1} %{?2} %{?3} %{?4} %{?5} %{?6} \
%{nil}
%dotnet_pack() \
-dotnet-build pack %{1} %{2} %{_dotnet_build_conf} %{?3} %{?4} %{?5} %{?6} %{?7} \
+dotnet-build -c %{_dotnet_build_conf} %{?2:-v %{2}} pack %{1} %{?3} %{?4} %{?5} %{?6} %{?7} \
%{nil}
%dotnet_install_assembly() \
-mkdir -p %{buildroot}%{_dotnet_assembly_path} \
-mkdir -p %{buildroot}%{_mono_assembly_path} \
-install -p -m 644 "%{1}/bin/%{_dotnet_build_conf}/%{1}.dll" %{buildroot}%{_dotnet_assembly_path} \
-%if 0%{?_mono_subrpm} \
-[ -f "%{1}/bin/%{_dotnet_build_conf}/Net45/%{1}.dll" ] && install -p -m 644 "%{1}/bin/%{_dotnet_build_conf}/Net45/%{1}.dll" %{buildroot}%{_mono_assembly_path} \
-%endif \
+dotnet-build -t assembly install %{1} %{buildroot}%{_dotnet_assembly_path} \
%{nil}
%dotnet_install_nuget() \
-mkdir -p %{buildroot}/nuget \
-install -p -m 644 %{1}*.nupkg %{buildroot}/nuget \
+dotnet-build -t nupkg install %{1} %{buildroot}%{_dotnet_nuget_source} \
%{nil}
%dotnet_install() \
-mkdir -p %{buildroot}%{_dotnet_assembly_path} \
-mkdir -p %{buildroot}%{_mono_assembly_path} \
-install -p -m 644 "%{1}/bin/%{_dotnet_build_conf}/%{1}.dll" %{buildroot}%{_dotnet_assembly_path} \
-%if 0%{?_mono_subrpm} \
-[ -f "%{1}/bin/%{_dotnet_build_conf}/Net45/%{1}.dll" ] && install -p -m 644 "%{1}/bin/%{_dotnet_build_conf}/Net45/%{1}.dll" %{buildroot}%{_mono_assembly_path} \
-%endif \
-mkdir -p %{buildroot}/nuget \
-install -p -m 644 %{1}*.nupkg %{buildroot}/nuget \
+dotnet-build -t assembly install %{1} %{buildroot}%{_dotnet_assembly_path} \
+dotnet-build -t nupkg install %{1} %{buildroot}%{_dotnet_nuget_source} \
%{nil}