How to build a Delphi project in TeamCity

2019-06-13 03:23发布

问题:

I am trying to build a delphi project in TeamCity, but I can't get it to work.

I'm using MSBuild to build the project and also have added BDS parameter to the build but I keep getting the error: MSB4040 There is no target in the project.

回答1:

There are several things you need to be aware of. Firstly, the various environment variables and paths that Delphi requires need to be setup. Much of this is accomplished by the rsvars.bat batch file, but you can set up your own. Secondly, your EnvOptions.proj file needs to be set correctly to match the environment on your build machine. This file resides in %APPDATA%\Embarcadero\xx,x\ where xx.x is your Delphi version.

The following commented CMD file is one that I use to build Delphi XE7 applications in a TFS environment and should work with TeamCity and other build tools :-


@echo off
:::
::: Example for Build Delphi Project with MSBuild
:::

echo.
echo using MSBuild from VStudio 2013
echo.
SET MSBUILD_EXE=C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe

echo.
echo A copy of a Delphi installation from a developers machine is ok. MSBuild calls dcc32/dcc64, not the IDE.
echo The build targets are included in "$(DelphiInstallDir)\bin\CodeGear.Delphi.Targets".
echo DefaultTarget is "Make"
echo.

echo.
echo Set Delphi XE7 Vars
echo.

SET BDS=C:\DelphiXE7
SET BDSBIN=%BDS%\bin
SET BDSLIB=%BDS%\lib
SET BDSTMP=%BDS%\Temp

echo.
echo On a local Delphi developer machine the actual used Delphi settings are located here: 
echo "%APPDATA%\Embarcadero\BDS\15.0\EnvOptions.proj"
echo.
echo The directories and files included in "EnvOptions.proj" must exist on the build machine!!!
echo.
echo Copy the (maybe modified) Delphi settings on your build machine to %APPDATA%\Embarcadero\BDS\15.0
echo.
MKDIR "%APPDATA%\Embarcadero\BDS\15.0"
COPY /Y /B /V "%BDSTMP%\EnvOptions.proj" "%APPDATA%\Embarcadero\BDS\15.0\EnvOptions.proj"

echo.
echo Set the Delphi Project Vars
echo.
SET PROJECT_SRC=C:\MyProjectSource
SET PLATFORM=Win32
SET CONFIG=Debug

echo.
echo Build Delphi Project with MSBuild 
echo.
echo + /p = Parameters for the Delphi Project Build
echo.
echo + /t = Targets to be executed, e.g. Clean and Build 
echo.
"%MSBUILD_EXE%" "%PROJECT_SRC%\myProject\myProject1.dproj" /p:Config=%CONFIG%;Platform=%PLATFORM% /t:Clean;Build

IF NOT ERRORLEVEL 0 GOTO ERROR

GOTO END

:ERROR
echo.
echo There were errors!
echo.
pause
EXIT

:END
pause



回答2:

You could correct setup teamcity to build using MSBuild using the follow steps:

First you should define the parameter on teamcity that declares the enviroment variables that is seted by rsvars.bat, to do that in your Project access the Parameters and create a new configuration, select the type enviroment variable, set the same names and values from the rsvars.bat file aka: BDS, BDSCOMMONDIR, et all.

After that in you msbuild step edit the target option to "build".

You can see that this information is documented here http://docwiki.embarcadero.com/RADStudio/Tokyo/en/Building_a_Project_Using_an_MSBuild_Command

Here you can see my params configuration

And here is the MSBuild Project configuration