问题
I am trying to build ServiceStack binaries for use with an open source project. First, I tried following the recommendations in this SO answer, by using the DLLs in the lib
folder of the ServiceStack repo. However, amongst others, ServiceStack.Logging and some of the OrmLite DLLs are missing there.
I then tried building the missing DLLs from the source code, but the OrmLite projects refer to a signed ServiceStack.Interfaces DLL in the lib folder, while for instance ServiceStack.Logging.NLog has a project reference to the ServiceStack.Interfaces project, which then results in an unsigned ServiceStack.Interfaces DLL.
As a result, my project that uses both OrmLite and ServiceStack.Logging.NLog doesn't build.
There must be an easier way of doing this.
回答1:
Here is a batch file to build the DLLs:
@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
To build NuGet packages for use with .NET Core, you can use the following Bash script:
#!/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"
You can then add a NuGet.config
file in your solution folder to make them available:
<?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>
来源:https://stackoverflow.com/questions/35049866/how-do-i-get-servicestack-binaries-for-use-with-the-foss-exception