Jump to content
Sign in to follow this  
Fr0sT.Brutal

MSBuild - set library paths without touching IDE options

Recommended Posts

I want to write build scripts for my projects with zero-config, i.e. any IDE options are untouched. I managed to run MSBuild and specify subfolders for pickup but stuck at defining Library path. I have several components from which I want compiler to take DCUs not sources so UnitSearchPath doesn't fit. But when I'm setting the variable via command line, it overrides default paths:

 

msbuild /property:DelphiLibraryPath="d:\mycomp\lib" myproj.dproj

>error F1027: Unit not found: 'System.pas' or binary equivalents (.dcu)

 

Env variables should have saved the day but alas they seem not be expanded when assigned via command line

 

msbuild /property:DelphiLibraryPath="$(BDSLIB)\$(Platform)\release;d:\mycomp\lib" myproj.dproj

>error F1027: Unit not found: 'System.pas' or binary equivalents (.dcu)

 

Is there any option to add some library paths to default list?

I'm aware of \AppData\Roaming\Embarcadero\BDS\9.0\EnvOptions.proj file which is imported by all projects and contains DelphiLibraryPath definition but that's the last hope.

If there was an option to import a file from command line, that would work too but I only found files with command line arguments. The 2nd workaround is to create local file with required options and manually import it inside all project files but I still hope for a better solution.

Edited by Fr0sT.Brutal

Share this post


Link to post

hi @Fr0sT.Brutal

Sorry, I dont xpert in MSBuild ok, but you can try this way:

  • testing with a project default: 1 form main, 1 other form
    1. define your options in your project
    2. in your project, if you dont, check the option: "Use MSBuild externally to compile" [x]
    3. now, use "BUILD" to build all files dependences (the most important will be "xxxxx.CMDS" file all another you can delete after!)  not necessary at all
      1. now, you can see in your project folder a new file "<<project name>>.CMDS" in your "output directory" defined on project-options
    4. in my case, was copied the "RSVARS.bat" (from RAD \bin folder) file to the project directory to create the Delphi environment variables
      1. run it // this was important on task
    5. now, using "MSBuild.exe" appropriated, (in my case C:\Windows\Microsoft.NET\Framework\v4.0.30319>" version
      1. just executed: msbuild.exe  on project folder, and the project will be created.
  •  
  • folder opened on CMD console
    1. cd "C:\Windows\Microsoft.NET\Framework\v3.5>" or   "C:\Windows\Microsoft.NET\Framework\v4.0.30319>" --- what "MSBuild.exe" you use?
    2. cd "D:\RADStudioTests\RADRX112Tests\__TEMP"
  • command-lines on CMD console ( I'm in "d:" drive)
    1. c:msbuild.exe
  • in my project I have defined
    1. Output directory = .\ExeOutput 
    2. Unit output directory = .\DCUOutput
    3. DCP output directory = .\DCPOutput
    4. Use MSBuild externally to compile [x]

image.thumb.png.11ad3e84046ffeb907bf4b32ca2eb0c9.png

Edited by programmerdelphi2k

Share this post


Link to post

@programmerdelphi2k

thanks for the tip, I didn't know about "Use MSBuild externally to compile" option. However, this won't help to solve the issue. Library paths are defined at IDE level and saved into shared file EnvOptions.proj in APPDATA what I'm trying to avoid.

The most disappointing is that MSBuild doesn't expand $(..)-variables given to it in command line arguments

Share this post


Link to post
11 minutes ago, Fr0sT.Brutal said:

MSBuild doesn't expand $(..)-

 

This is how I compile with older versions of controls.. might help you get started.
The CMD file is in the project root and changes directory to Source:

@ECHO OFF
::
:: How to Redirect to an older Version of VCL
:: Since no IDE is required this will work for NON installed versions of any VCL controls
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::
:: Redirect DX, to compile with source we need to update all these
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM @SET DXVCL=%VCL%\DevExpress VCL\20.2.8 (26-May-2021) for PA2-R12
REM IF NOT Exist "%DXVCL%" (
        REM echo."%DXVCL%", Directory does not exist
        REM Pause )
REM CALL :SetEnvVar "DXLibs"
REM CALL :SetEnvVar "DXSources"
REM SET DX
REM pause

::
:: Redirect UNI, to compile with source we need to update all these
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM @SET UNIVCL=%VCL%\UniDAC\9.0.1 (14-Sep-2021)
REM IF NOT Exist "%UNIVCL%" (
        REM echo."%UNIVCL%", Directory does not exist
        REM Pause )
REM CALL :SetEnvVar "UNILIB"
REM CALL :SetEnvVar "UniSources"
REM SET Uni
REM pause

::
:: Environmental Vars declared in the IDE must be redeclared 
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@SET CompilerV=28
@SET ProductVersion=22.0
@SET IDEVER=11.0.2
::
:: Now expand those with rsVars.bat
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
call "C:\Program Files (x86)\Embarcadero\Studio\22.0\bin\rsvars.bat"
::
:: Reset the rsVars.bat defaults
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@SET BDSCOMMONDIR=D:\Embarcadero Studio\22.0
::
::  Add the location of cmd.exe
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@SET PATH=%WINDIR%\System32;%PATH%

cd source
:: Recomended in 10.4 Release Notes..
MSBuild APP.dproj /t:clean

REM TIMEOUT /T 10
MSBuild APP.dproj /t:build /v:q /p:Config=Release /p:platform=Win64
cd ..

::  View any output notices
pause

 :: ========== FUNCTIONS ==========
EXIT /B

:: Read a Value from Environment
:: Param 1: Name of output variable.
:: Param 2: SubKey.
:RegQueryEnv 
@ECHO OFF
SET KEY="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
:: Remove the double quotes
Set SUBKEY=%~2
FOR /F "skip=2 tokens=2,*" %%A IN ('reg.exe query %KEY% /v "%SUBKEY%"') DO (
    set %1=%%B )
EXIT /B

:: Expand any EnvVars in the Text
:: Param 1: Name of output variable.
:: Param 2: Text to Expand (%UNIVCL%\Lib\Delphi$(CompilerV))
:ExpandEnvVar
@ECHO OFF
set %1=%~2
REM echo.ExpandEnvVar=%Text% 
EXIT /B

:: Combines RegQuery and ExpandEnvVar then uses @SET
:: Param 1: SubKey.
:SetEnvVar
@ECHO OFF
CALL :RegQueryEnv Value %1
CALL :ExpandEnvVar Value "%Value%"
@SET %~1=%Value%

 

  • Thanks 1

Share this post


Link to post
3 hours ago, Fr0sT.Brutal said:

I have several components from which I want compiler to take DCUs not sources so UnitSearchPath doesn't fit.

Have you actually tried to specify DCC_UnitSearchPath on the MSBuild command?

msbuild /property:DCC_UnitSearchPath="d:\mycomp\lib" myproj.dproj

 

  • Thanks 1

Share this post


Link to post

Note: when you "build" with "Use MSBuild..." on project, you'll have a file .CMDS with all properties necessary. then, I think that it's not necessary add it on command-line. You need just have in your "output EXE/DLL" folder

  • of course, you can create this file manually! = <<project name>>.CMDS
Quote

-I"c:\radstudio\rx112\lib\Win32\debug"
-I"c:\radstudio\rx112\lib\Win32\release"
-I"C:\Users\WIn10H22\Documents\Embarcadero\Studio\22.0\Imports"
-I"C:\Users\WIn10H22\Documents\Embarcadero\Studio\22.0\Imports\Win32"
-I"c:\radstudio\rx112\Imports"
-I"C:\Users\Public\Documents\Embarcadero\Studio\22.0\Dcp"
-I"c:\radstudio\rx112\include"
-O"c:\radstudio\rx112\lib\Win32\release"
-O"C:\Users\WIn10H22\Documents\Embarcadero\Studio\22.0\Imports"
-O"C:\Users\WIn10H22\Documents\Embarcadero\Studio\22.0\Imports\Win32"
-O"c:\radstudio\rx112\Imports"
-O"C:\Users\Public\Documents\Embarcadero\Studio\22.0\Dcp"
-O"c:\radstudio\rx112\include"
-R"c:\radstudio\rx112\lib\Win32\release"
-R"C:\Users\WIn10H22\Documents\Embarcadero\Studio\22.0\Imports"
-R"C:\Users\WIn10H22\Documents\Embarcadero\Studio\22.0\Imports\Win32"
-R"c:\radstudio\rx112\Imports"
-R"C:\Users\Public\Documents\Embarcadero\Studio\22.0\Dcp"
-R"c:\radstudio\rx112\include"
-U"c:\radstudio\rx112\lib\Win32\debug"
-U"c:\radstudio\rx112\lib\Win32\release"
-U"C:\Users\WIn10H22\Documents\Embarcadero\Studio\22.0\Imports"
-U"C:\Users\WIn10H22\Documents\Embarcadero\Studio\22.0\Imports\Win32"
-U"c:\radstudio\rx112\Imports"
-U"C:\Users\Public\Documents\Embarcadero\Studio\22.0\Dcp"
-U"c:\radstudio\rx112\include"
 

 

in Project1.DPROJ is added:

Edited by programmerdelphi2k
  • Thanks 1

Share this post


Link to post

you can look the "detailed log" created by MSBuild using " /distributedFileLogger"  = create a msbuild1.log file on project folder!

Share this post


Link to post
On 1/13/2023 at 6:38 PM, Uwe Raabe said:

Have you actually tried to specify DCC_UnitSearchPath on the MSBuild command?


msbuild /property:DCC_UnitSearchPath="d:\mycomp\lib" myproj.dproj

 

Arrrr! My bad! I always considered this option as path to sources but seems it works for DCUs as well! There are still some weird errors of kind "Unit was compiled with a different version" but at least compiler actually looks for DCUs in these paths.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×