如何获取ServiceStack二进制文件以用于FOSS异常?

时间:2016-01-27 23:05:33

标签: .net servicestack

我正在尝试构建ServiceStack二进制文件以用于开源项目。首先,我尝试通过使用ServiceStack存储库的lib文件夹中的DLL来遵循this SO answer中的建议。但是,其中包括ServiceStack.Logging和一些OrmLite DLL。

然后我尝试从源代码构建缺少的DLL,但OrmLite项目引用lib文件夹中已签名的ServiceStack.Interfaces DLL,而例如ServiceStack.Logging.NLog具有对ServiceStack.Interfaces项目的项目引用,然后导致一个未签名的ServiceStack.Interfaces DLL。

因此,我的项目同时使用了OrmLite和ServiceStack.Logging.NLog。

必须有一种更简单的方法。

1 个答案:

答案 0 :(得分:0)

这是一个用于构建DLL的批处理文件:

@echo off

setlocal
set SSVERSION=v4.0.54
set LIB=%~dp0lib
set SSDIR=%LIB%\src\ServiceStack
set ORMLITEDIR=%LIB%\src\ServiceStack.OrmLite
set MSBUILD=C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
path %PATH%;%dp0bin

if not exist "%SSDIR%\" (
    echo Cloning ServiceStack repo

    git clone --depth 1 https://github.com/ServiceStack/ServiceStack "%SSDIR%"
    if errorlevel 1 goto error
)

if not exist "%ORMLITEDIR%\" (
    echo Cloning ServiceStack.OrmLite repo

    git clone --depth 1 https://github.com/ServiceStack/ServiceStack.OrmLite "%ORMLITEDIR%"
    if errorlevel 1 goto error
)


echo Cleaning up
pushd %SSDIR%
git clean -df
if errorlevel 1 goto error
git checkout -- .
if errorlevel 1 goto error
git fetch
if errorlevel 1 goto error
git checkout %SSVERSION%
if errorlevel 1 goto error
popd

pushd %ORMLITEDIR%
echo Cleaning up
git clean -df
if errorlevel 1 goto error
git checkout -- .
if errorlevel 1 goto error
git fetch
if errorlevel 1 goto error
git checkout %SSVERSION%
if errorlevel 1 goto error
popd

echo Copying DLLs
if exist "%LIB%\ServiceStack\" (
    rmdir /s /q "%LIB%\ServiceStack"
    if errorlevel 1 goto error
)

mkdir "%LIB%\ServiceStack"
if errorlevel 1 goto error

xcopy "%SSDIR%\lib\*.*" "%LIB%\ServiceStack\" /s /e /y
if errorlevel 1 goto error

echo Building ServiceStack
nuget restore "%SSDIR%\src\ServiceStack.Logging.sln"
if errorlevel 1 goto error

nuget restore "%ORMLITEDIR%\src\ServiceStack.OrmLite.sln"
if errorlevel 1 goto error

%MSBUILD% "%SSDIR%\src\ServiceStack.Logging.sln" /target:Clean
if errorlevel 1 goto error

%MSBUILD% "%ORMLITEDIR%\src\ServiceStack.OrmLite.sln" /target:Clean
if errorlevel 1 goto error

%MSBUILD% "%SSDIR%\src\ServiceStack.Razor\ServiceStack.Razor.csproj" /p:Configuration=Release /p:AssemblyOriginatorKeyFile="" /p:OutputPath="%LIB%\ServiceStack"
if errorlevel 1 goto error

%MSBUILD% "%SSDIR%\src\ServiceStack.ServerV45\ServiceStack.ServerV45.csproj" /p:Configuration=Release /p:AssemblyOriginatorKeyFile="" /p:OutputPath="%LIB%\ServiceStack"
if errorlevel 1 goto error

sed -e "s|<ProjectReference Include=.*|<Reference Include=\"ServiceStack.Interfaces\">|" -e "s|<Project>{42e1c.*|<HintPath>..\\\\..\\\\lib\\\\ServiceStack.Interfaces.dll</HintPath>|" -e "s|<Name>ServiceStack\.Interfaces</Name>||" -e "s|</ProjectReference>|</Reference>|" "%SSDIR%\src\ServiceStack.Logging.NLog\ServiceStack.Logging.NLog.csproj" > "%SSDIR%\src\ServiceStack.Logging.NLog\ServiceStack.Logging.NLog-Temp.csproj"
if errorlevel 1 goto error

%MSBUILD% "%SSDIR%\src\ServiceStack.Logging.NLog\ServiceStack.Logging.NLog-Temp.csproj" /p:Configuration=Release /p:AssemblyOriginatorKeyFile="" /p:OutputPath="%LIB%\ServiceStack"
if errorlevel 1 goto error

%MSBUILD% "%ORMLITEDIR%\src\ServiceStack.OrmLite.Firebird\ServiceStack.OrmLite.Firebird.csproj" /p:Configuration=Release /p:AssemblyOriginatorKeyFile="" /p:OutputPath="%LIB%\ServiceStack"
if errorlevel 1 goto error

%MSBUILD% "%ORMLITEDIR%\src\ServiceStack.OrmLite.Oracle\ServiceStack.OrmLite.Oracle.csproj" /p:Configuration=Release /p:AssemblyOriginatorKeyFile="" /p:OutputPath="%LIB%\ServiceStack"
if errorlevel 1 goto error

%MSBUILD% "%ORMLITEDIR%\src\ServiceStack.OrmLite.VistaDB\ServiceStack.OrmLite.VistaDB.csproj" /p:Configuration=Release /p:AssemblyOriginatorKeyFile="" /p:OutputPath="%LIB%\ServiceStack"
if errorlevel 1 goto error

:end
echo Finished succesfully
exit /b 0

:error
echo An error occurred. The last command exited with the exit code %ERRORLEVEL%
exit /b 1

要构建用于.NET Core的NuGet包,可以使用以下Bash脚本:

#!/bin/bash
errorhandler() {
    # Modified verion of http://stackoverflow.com/a/4384381/352573
    errorcode=$?
    echo "Error $errorcode"
    echo "The command executing at the time of the error was"
    echo "$BASH_COMMAND"
    echo "on line ${BASH_LINENO[0]}"
    exit $errorcode
}

pack() {
    echo "Building $2"
    pushd "$1/src/$2"
    ${DOTNET} restore
    ${DOTNET} pack -o "${LIB}/packages" -c Release
    popd
}

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SSVERSION=111.0.37
LIB=${DIR}/lib
SSDIR=${LIB}/src/ServiceStack
SSAWSDIR=${LIB}/src/ServiceStack.Aws
SSTEXTDIR=${LIB}/src/ServiceStack.Text
SSREDISDIR=${LIB}/src/ServiceStack.Redis
ORMLITEDIR=${LIB}/src/ServiceStack.OrmLite

if [ "${OS}" == 'Windows_NT' ]; then
    DOTNET="${DIR}/bin/dotnet-lts/dotnet.exe"
    if [ ! -f ${DOTNET} ]; then
        echo -n "Downloading .NET Core 1.0.3 (LTS) ..."
        mkdir -p "${DIR}/bin/dotnet-lts"
        curl -o dotnet.zip -sSL https://go.microsoft.com/fwlink/?LinkID=836296
        unzip -q -o dotnet.zip -d "${DIR}/bin/dotnet-lts"
        rm dotnet.zip
        echo " done"
    fi
else
    DOTNET="${DIR}/bin/dotnet-lts/dotnet"
    if [ ! -f ${DOTNET} ]; then
        echo "You need to download the .NET Core 1.0.3 (LTS) .tar.gz for your platform and unpack it into ${DIR}/bin/dotnet-lts"
        exit 1
    fi
fi

# From now on, catch errors
trap errorhandler ERR

echo "Cleaning up"
rm -rf "${LIB}/packages"

for d in ServiceStack ServiceStack.Aws ServiceStack.OrmLite ServiceStack.Redis ServiceStack.Text
do
    if [ ! -d "${LIB}/src/${d}" ]; then
        echo "Cloning ${d} repo"
        git clone --depth 1 https://github.com/ServiceStack/${d} "${LIB}/src/${d}"
    fi

    pushd "${LIB}/src/${d}"
    git clean -df
    git checkout -- .
    git fetch
    git checkout master
    popd
done

echo "Setting version numbers to a ridiculously high value"
find "${LIB}/src" -name project.json -exec sed -i -e "s/\(^[ \t]*\"version\": \"\)1.0.0\"/\1${SSVERSION}\"/" -e "s/\(\"ServiceStack\.[^\"]*\": \"\)1.0.*\(\"\)/\1${SSVERSION}\2/" \{\} \;

for d in ServiceStack.Text
do
    pack ${SSTEXTDIR} ${d}
done

for d in ServiceStack.Aws
do
    pack ${SSAWSDIR} ${d}
done

for d in ServiceStack.OrmLite ServiceStack.OrmLite.Sqlite ServiceStack.OrmLite.SqlServer
do 
    pack ${ORMLITEDIR} ${d}
done

for d in ServiceStack.Redis
do
    pack ${SSREDISDIR} ${d}
done

for d in ServiceStack ServiceStack.Api.Swagger ServiceStack.Client ServiceStack.Common ServiceStack.Core.SelfHost ServiceStack.Core.WebApp ServiceStack.HttpClient ServiceStack.Interfaces ServiceStack.Kestrel ServiceStack.MsgPack ServiceStack.Mvc ServiceStack.ProtoBuf ServiceStack.RabbitMq ServiceStack.Server ServiceStack.Wire
do
    pack ${SSDIR} ${d}
done

echo "Finished succesfully"

然后,您可以在解决方案文件夹中添加NuGet.config文件,以使其可用:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
    <clear />
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
    <add key="Local package library" value="../lib/packages" />
</packageSources>
</configuration>