I have a Delphi 11.2 project that builds fine within Delphi but fails on the command line.
In a nutshell, it appears that building via the IDE uses a different version of MSBuild than when building via the Rad Studio Command Prompt
.
This is easy to recreate. Just create a new Delphi 11.2 Windows VCL Project, with just an empty form to keep it simple. Then right click the project in the Projects View
and select Add New->Other
menu option. In the search edit for the New Items
window type Target
, drop the tree view on the left and select the MSBuild Targets File
. That will add a new MSBuild Targets file to the project. Right click this new file and select Enable
.
Now edit the new Targets file as follows:
<Project xmlns="; InitialTargets="MyNewTarget">
<Target Name="MyNewTarget" BeforeTargets="Build;Make">
<Message Text="MSBuildToolsPath: $(MSBuildToolsPath)" Importance="High"/>
<Message Text="MSBuildToolsVersion: $(MSBuildToolsVersion)" Importance="High"/>
<Message Text="MSBuildBinPath: $(MSBuildBinPath)" Importance="High"/>
<Exec Command="echo MyOutput" ConsoleToMSBuild="true" StandardOutputImportance="low">
<Output TaskParameter="ConsoleOutput" PropertyName="MyProperty"/>
</Exec>
<Message Text="MyProperty: $(MyProperty)" Importance="High"/>
</Target>
</Project>
I've added message output for various MSBuild variables so I can compare what happens in Delphi with what happens via the Rad Studio Command Prompt
.
Build the project and check the Output pane
. You should see message similar to the following:
MSBuildToolsPath: C:\Windows\Microsoft.NET\Framework\v4.0.30319
MSBuildToolsVersion: 2.0
MSBuildBinPath: C:\Windows\Microsoft.NET\Framework\v4.0.30319
Notice here it's showing the Framework as v4.0 and the project builds successfully.
Now try and build via the Rad Studio Command Prompt
. Change folder to your project folder and then just type msbuild Project1.dproj
. Obviously change the name to be your project name.
You'll notice that this will fail with the following message:
Target1.targets(7,35): error MSB4064: The "ConsoleToMSBuild" parameter is not supported by the "Exec" task. Verify the parameter exists on the task, and it is a settable public instance property.
Also if you look at the message I output from the target you will see the following:
MSBuildToolsPath: C:\Windows\Microsoft.NET\Framework\v2.0.50727
MSBuildToolsVersion: 2.0
MSBuildBinPath: C:\Windows\Microsoft.NET\Framework\v2.0.50727
Notice the MSBuildBinPath
and MSBuildToolsPath
are showing v2.0, where as the output from building within the IDE shows these as v4.0.
The reason I'm using the <Exec Command="echo MyOutput" ConsoleToMSBuild="true" StandardOutputImportance="low">
command (which is what is failing via the command line) is to obtain the GIT commit hash. Along with this particular command, my real project has all our versioning information in properties which can be easily overridden via our CI Server.
Anyone know why/how building via Delphi IDE uses v4.0 while building via the Rad Studio Command Prompt
uses v2.0?
I have figured out I can force the command prompt to use MSBuild tools version 4.0 by specifying the tools version on the command line using msbuild Project1.dproj /tv:4.0
.
However, I don't really want to do this because it means anyone checking out the code and building via the command line, including our CI Server, will have to remember to specify the tools version.
The other way I've found is I can specify the tools version in the Delphi main project file, Project1.dproj in this instance, by amending the first line as follows <Project xmlns="; ToolsVersion="4.0">
, notice the use of the explicit ToolsVersion="4.0"
.
Again, I'd really rather not explicitly specify the tools version in the Delphi project - I've seen many, many times Delphi automatically changes the dproj file hence I'd rather not modify it if I don't have to, in case my edit is automatically removed.
Any help/ideas much appreciated.
I have a Delphi 11.2 project that builds fine within Delphi but fails on the command line.
In a nutshell, it appears that building via the IDE uses a different version of MSBuild than when building via the Rad Studio Command Prompt
.
This is easy to recreate. Just create a new Delphi 11.2 Windows VCL Project, with just an empty form to keep it simple. Then right click the project in the Projects View
and select Add New->Other
menu option. In the search edit for the New Items
window type Target
, drop the tree view on the left and select the MSBuild Targets File
. That will add a new MSBuild Targets file to the project. Right click this new file and select Enable
.
Now edit the new Targets file as follows:
<Project xmlns="http://schemas.microsoft/developer/msbuild/2003" InitialTargets="MyNewTarget">
<Target Name="MyNewTarget" BeforeTargets="Build;Make">
<Message Text="MSBuildToolsPath: $(MSBuildToolsPath)" Importance="High"/>
<Message Text="MSBuildToolsVersion: $(MSBuildToolsVersion)" Importance="High"/>
<Message Text="MSBuildBinPath: $(MSBuildBinPath)" Importance="High"/>
<Exec Command="echo MyOutput" ConsoleToMSBuild="true" StandardOutputImportance="low">
<Output TaskParameter="ConsoleOutput" PropertyName="MyProperty"/>
</Exec>
<Message Text="MyProperty: $(MyProperty)" Importance="High"/>
</Target>
</Project>
I've added message output for various MSBuild variables so I can compare what happens in Delphi with what happens via the Rad Studio Command Prompt
.
Build the project and check the Output pane
. You should see message similar to the following:
MSBuildToolsPath: C:\Windows\Microsoft.NET\Framework\v4.0.30319
MSBuildToolsVersion: 2.0
MSBuildBinPath: C:\Windows\Microsoft.NET\Framework\v4.0.30319
Notice here it's showing the Framework as v4.0 and the project builds successfully.
Now try and build via the Rad Studio Command Prompt
. Change folder to your project folder and then just type msbuild Project1.dproj
. Obviously change the name to be your project name.
You'll notice that this will fail with the following message:
Target1.targets(7,35): error MSB4064: The "ConsoleToMSBuild" parameter is not supported by the "Exec" task. Verify the parameter exists on the task, and it is a settable public instance property.
Also if you look at the message I output from the target you will see the following:
MSBuildToolsPath: C:\Windows\Microsoft.NET\Framework\v2.0.50727
MSBuildToolsVersion: 2.0
MSBuildBinPath: C:\Windows\Microsoft.NET\Framework\v2.0.50727
Notice the MSBuildBinPath
and MSBuildToolsPath
are showing v2.0, where as the output from building within the IDE shows these as v4.0.
The reason I'm using the <Exec Command="echo MyOutput" ConsoleToMSBuild="true" StandardOutputImportance="low">
command (which is what is failing via the command line) is to obtain the GIT commit hash. Along with this particular command, my real project has all our versioning information in properties which can be easily overridden via our CI Server.
Anyone know why/how building via Delphi IDE uses v4.0 while building via the Rad Studio Command Prompt
uses v2.0?
I have figured out I can force the command prompt to use MSBuild tools version 4.0 by specifying the tools version on the command line using msbuild Project1.dproj /tv:4.0
.
However, I don't really want to do this because it means anyone checking out the code and building via the command line, including our CI Server, will have to remember to specify the tools version.
The other way I've found is I can specify the tools version in the Delphi main project file, Project1.dproj in this instance, by amending the first line as follows <Project xmlns="http://schemas.microsoft/developer/msbuild/2003" ToolsVersion="4.0">
, notice the use of the explicit ToolsVersion="4.0"
.
Again, I'd really rather not explicitly specify the tools version in the Delphi project - I've seen many, many times Delphi automatically changes the dproj file hence I'd rather not modify it if I don't have to, in case my edit is automatically removed.
Any help/ideas much appreciated.
Share Improve this question asked Nov 20, 2024 at 11:23 jqbdjqbd 714 bronze badges 1- As you noted, you can specify a toolset version in the MSBuild project file. MSBuild is designed to support both user customizations (by directly editing the project file) and modifications by the IDE. Visual Studio supports this. I can't address Delphi but if Delphi 'loses' this attribute and user customizations in general, that's an issue. – Jonathan Dodds Commented Nov 20, 2024 at 17:50
1 Answer
Reset to default 0I don't use the RAD Studio Command Prompt or tweak the parameters in the .dproj file. However, when I did try building from the command prompt (Delphi 11.3) just now, it works as expected and I get the proper MSBuild version. I'm not sure why yours doesn't.
According to the documentation, Delphi uses some environment variables. I create a simple build script that calls rsvars.bat and sets these before calling MSBuild. For example:
@echo off
setlocal
call "C:\Program Files (x86)\Embarcadero\Studio\22.0\bin\rsvars.bat"
msbuild "MyProject.dproj" /target:Build /p:Config=Debug /p:Platform=Win64
endlocal
echo.
pause
Edit: Apparently the RAD Studio Command Prompt just launches a console window that runs this same rsvars.bat. I wonder if yours from 11.2 is different than mine from 11.3. Here is what I have:
@SET BDS=C:\Program Files (x86)\Embarcadero\Studio\22.0
@SET BDSINCLUDE=C:\Program Files (x86)\Embarcadero\Studio\22.0\include
@SET BDSCOMMONDIR=C:\Users\Public\Documents\Embarcadero\Studio\22.0
@SET FrameworkDir=C:\Windows\Microsoft.NET\Framework\v4.0.30319
@SET FrameworkVersion=v4.5
@SET FrameworkSDKDir=
@SET PATH=%FrameworkDir%;%FrameworkSDKDir%;C:\Program Files (x86)\Embarcadero\Studio\22.0\bin;C:\Program Files (x86)\Embarcadero\Studio\22.0\bin64;C:\Program Files (x86)\Embarcadero\Studio\22.0\cmake;%PATH%
@SET LANGDIR=EN
@SET PLATFORM=
@SET PlatformSDK=