H05 0 Posted November 27, 2022 I'm creating a tool to automate building a number of other Delphi projects and I am trying to call MSBUILD from my application. I'm running into an issue I don't get from the command line prompt directly. I have Delphi 10.4 and 11.1 installed. I'm successful from the the commandline. I call a batch file builder.bat (code below) I created with two arguments: builder "c:\Projects\Project1.dproj" "Debug" and this works to build my application using 10.4 (all the paths in the console reference C:\Program Files (x86)\Embarcadero\Studio\21.0\lib\) It fails when calling from the Delphi application I wrote where I'm capturing the console output (via CreateProcess & CaptureConsoleOutput https://stackoverflow.com/a/22326335) Quote project1.dpr(1): error F2048: Bad unit format: 'c:\program files (x86)\embarcadero\studio\22.0\lib\Win32\release\System.dcu' - Expected version: 34.0, Windows Unicode(x86) Found version: 35.0, Windows Unicode(x86) [c:\Projects\project1.dproj] Done Building Project "c:\Projects\project1.dproj" (Build target(s)) -- FAILED. I've seen the comment by @corneliusdavid and I've changed the order of my path hoping that helps. However, it seems to be picking up the Delphi 11 lib folder and that isn't in my Windows Path. Anyone run in this situation? Thanks in advance! Builder.bat REM builder.bat REM =================================================== setlocal enabledelayedexpansion REM Delphi 10 Variables SET BDS=C:\Program Files (x86)\Embarcadero\Studio\21.0 SET BDSAPPDATABASEDIR=BDS SET BDSBIN=C:\Program Files (x86)\Embarcadero\Studio\21.0\bin SET BDSINCLUDE=C:\Program Files (x86)\Embarcadero\Studio\21.0\include SET BDSCOMMONDIR=C:\Users\Public\Documents\Embarcadero\Studio\21.0 SET FrameworkDir=C:\Windows\Microsoft.NET\Framework\v4.0.30319 SET FrameworkVersion=v4.5 SET PATH=%FrameworkDir%;%FrameworkSDKDir%;C:\Program Files (x86)\Embarcadero\Studio\21.0\bin;C:\Program Files (x86)\Embarcadero\Studio\21.0\bin64;C:\Program Files (x86)\Embarcadero\Studio\21.0\cmake;C:\Users\Public\Documents\Embarcadero\InterBase\redist\InterBaseXE7\IDE_spoof;%PATH% msbuild %1 /nologo /target:Build /p:config=%2 endlocal Error Log (truncated paths): Build started 2022-11-27 6:44:40 AM. Project "c:\Projects\project1.dproj" on node 1 (Build target(s)). BuildVersionResource: C:\Program Files (x86)\Embarcadero\Studio\21.0\bin\cgrc.exe -c65001 project1.vrc -foproject1.res CodeGear Resource Compiler/Binder Version 1.2.2 Copyright (c) 2008-2012 Embarcadero Technologies Inc. Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0 Copyright (C) Microsoft Corporation. All rights reserved. Deleting file "project1.vrc". del "project1.vrc" Deleting file "project1.$manifest". del "project1.$manifest" BrccCompile: C:\Program Files (x86)\Embarcadero\Studio\21.0\bin\brcc32.exe -dmadExcept;DEBUG; -i<CUT LONG PATH> Borland Resource Compiler Version 5.40 Copyright (c) 1990, 1999 Inprise Corporation. All rights reserved. _PasCoreCompile: C:\Program Files (x86)\Embarcadero\Studio\21.0\bin\dcc32.exe -$O- -$W+ -$J+ -$C- --no-config -B -Q -TX.exe <CUT LONG PATH> -V -VN -K00400000 --description:"Project 1" -GD --drc -NBC:\Users\Public\Documents\Embarcadero\Studio\21.0\Dcp -NHC:\Users\Public\Documents\Embarcadero\Studio\21.0\hpp\Win32 -NO..\compiled -H- -W+UNSAFE_TYPE -W+UNSAFE_CODE -W +UNSAFE_CAST -$M16384,5242880 project1.dpr Embarcadero Delphi for Win32 compiler version 34.0 Copyright (c) 1983,2021 Embarcadero Technologies, Inc. project1.dpr(1): error F2048: Bad unit format: 'c:\program files (x86)\embarcadero\studio\22.0\lib\Win32\release\System.dcu' - Expected version: 34.0, Windows Unicode(x86) Found version: 35.0, Windows Unicode(x86) [c:\Projects\project1.dproj] Done Building Project "c:\Projects\project1.dproj" (Build target(s)) -- FAILED. Build FAILED. "c:\Projects\project1.dproj" (Build target) (1) -> (_PasCoreCompile target) -> project1.dpr(1): error F2048: Bad unit format: 'c:\program files (x86)\embarcadero\studio\22.0\lib\Win32\release\System.dcu' - Expected version: 34.0, Windows Unicode(x86) Found version: 35.0, Windows Unicode(x86) [c:\Projects\project1.dproj] 0 Warning(s) 1 Error(s) Time Elapsed 00:00:00.38 Share this post Link to post
SwiftExpat 65 Posted November 27, 2022 Are you running the application from the IDE, either run or debug? Close the IDE and then run your executable, it will likely work. 1 Share this post Link to post
programmerdelphi2k 237 Posted November 27, 2022 more one prove that it's not recommended "Copy/Paste" from code found on interner! use a code that you dont "domains" basic concept, it's another error! if you need learn, do it with simples samples, and with time, add more functions... at end, maybe, you domains it you question, is your answer! ...have 10.4 and 11 installed... Another, the RAD always use enviroment variables "out" and "in"; out: PATH variable from O.S. anothers in "batch" files the ordem in "PATH" variable, it's determinant when not expliciting on command-line! in: $(var-name): like $(BDS) ... all this it should be considerated when, you case, trying create a "tool" (batch) to your case. a tip: try see your IDE message when compiling, and try reproduce the commands in your batch-file. when compiling any project you can see this message on "Build" and "Output" windows on bottom screen! for end, the error message is clear: Error F2048 bad unit using wrong DCC32 in MSBUILD? or 11 is using DCUs from 10.4, or else! why? because your PATH variables is appointing to wrong place! Share this post Link to post
H05 0 Posted November 28, 2022 8 hours ago, SwiftExpat said: Are you running the application from the IDE, either run or debug? Close the IDE and then run your executable, it will likely work. Beautiful, this did the trick thank you kindly @SwiftExpat @programmerdelphi2k Since you provided me unsolicited advice, allow me to do the same. In the future perhaps reading the question and answering it as opposed to making incorrect assumptions, chastising, and then providing an answer was already tried (I even said it!) would serve you better as a programmer and mentor to others. Share this post Link to post
programmerdelphi2k 237 Posted November 28, 2022 I remove any new try, you dont merece any oneapparently the error is not only in your IDE, but also in your way of acting. I'm pulling out before this evil spreads across my screen Share this post Link to post
David Heffernan 2345 Posted November 28, 2022 31 minutes ago, H05 said: Beautiful, this did the trick thank you kindly @SwiftExpat This sounds wrong. Messing with the system path and closing an ide tells me that you aren't creating and isolating your compile environments correctly. Note that Delphi is capable of building with any path and with any other ide open. You have solved nothing yet. Share this post Link to post
H05 0 Posted November 28, 2022 24 minutes ago, David Heffernan said: This sounds wrong. Messing with the system path and closing an ide tells me that you aren't creating and isolating your compile environments correctly. Note that Delphi is capable of building with any path and with any other ide open. You have solved nothing yet. Fair -- to clarify I tried changing the system path order; It didn't have any effect and was changed back. And modifying SwiftExpat's advice slightly, I just tried executing the compiled exe through Windows Explorer manually and it does work with the IDE open. My current suspicion is that I need to set the current directory when using CreateProcess or something along those lines but that's a problem for tomorrow. Share this post Link to post
David Heffernan 2345 Posted November 28, 2022 1 hour ago, H05 said: Fair -- to clarify I tried changing the system path order; It didn't have any effect and was changed back. And modifying SwiftExpat's advice slightly, I just tried executing the compiled exe through Windows Explorer manually and it does work with the IDE open. My current suspicion is that I need to set the current directory when using CreateProcess or something along those lines but that's a problem for tomorrow. I think it's far more likely to be environment variables being inherited. 1 Share this post Link to post
SwiftExpat 65 Posted November 28, 2022 6 hours ago, H05 said: a problem for tomorrow This can be frustrating to understand, because technically your code works. 4 hours ago, David Heffernan said: I think it's far more likely to be environment variables being inherited. The comment above is right on point, your next step in isolating this should really be using SysInternals Process Explorer and use the Environment tab to examine the environment variables. Compare the run from the IDE and from Windows explorer and then you know, based on the difference, what to set and what gets set from the IDE. 1 Share this post Link to post
H05 0 Posted November 28, 2022 6 hours ago, SwiftExpat said: This can be frustrating to understand, because technically your code works. The comment above is right on point, your next step in isolating this should really be using SysInternals Process Explorer and use the Environment tab to examine the environment variables. Compare the run from the IDE and from Windows explorer and then you know, based on the difference, what to set and what gets set from the IDE. Thank you @SwiftExpat and @David Heffernan that gives me a good and focused start on getting to the root cause. I appreciate the guidance. Share this post Link to post