conan
conan copied to clipboard
[bug] Unable to run Msbuild.exe when using AutotoolsToolchain
Environment details
- Operating System+version: Windows 11 22H2
- Compiler+version: msvc16 (VS2019)
- Conan version: 2.0.17
- Python version: integrated in Conan release
Steps to reproduce
When using the AutotoolsToolchain then later calls to MSBuild build helper will fail, because command 'msbuild' is not found.
E.g. in a recipe one could do:
def generate(self):
tc = AutotoolsToolchain(self)
...
tc.generate()
def build(self):
autotools = Autotools(self)
autotools.configure(...)
autotools.make()
if self.settings.os == "Windows":
if self.options.shared:
msbuild = MSBuild(self)
msbuild.build("merge_module.sln")
The msbuild command line will be executed in MSYS2 environment. But inside MSYS2 you cannot call 'msbuild' - that does not exist. You have to call 'msbuild.exe'. That one will be found. I verified this by manually starting MSYS2 bash and executing all generated conanbuild.bat and conanbuild.sh. In source code of revision 2.0.17 one can find the assembly of msbuild command in msbuild.py line 58.
On the other hand I think it is not necessary to execute Msbuild inside of MSYS2 environment. Is it possible to set another toolchain for Msbuild build helper?
Logs
No response
Hi @chr-thien
Thanks for your report.
Quick question: I assume that the recipe has win_bash = True defined? Maybe also has msys2/cci.latest ConanCenter package as tool_requires?
If that is the case, this would probably be the first issue of running msbuild into the msys2 environment.
Maybe it is worth trying to explicitly deactivating it before calling it? Like:
self.win_bash = False
msbuild = MSBuild(self)
msbuild.....
Your proposed workaround does not solve the problem.
Adding
self.win_bash = False
msbuild = MSBuild(self)
msbuild.build(os.path.join(self.build_folder, "..", "msbuild_wix", "icu.sln"))
self.win_bash = True
Now there is an exception.
ConanException: Cannot wrap command with different envs,['C:\\Users...
Background:
I want to build famous ICU component. I started with recipe from Conan-Center. Yes, that recipe sets
self.win_bash = True
and
self.tool_requires("msys2/cci.latest")
After regular build with autotools, I additionally want to build the MSI merge module using Windows Installer XML - which is in fact a VS solution and a VS project. In our build environment MSI merge modules are part of the package.
There is no problem with other recipes which use CMakeToolchain or MSBuildToolchain. Standard shell 'cmd.exe' finds all variations of 'msbuild', 'msbuild.exe', ... - but in unix-based environments we need to be a bit more exact.
Thanks for the feedback.
So for your case, basically this patch could work?
diff --git a/conan/tools/microsoft/msbuild.py b/conan/tools/microsoft/msbuild.py
index a2ec898ca..9531457c6 100644
--- a/conan/tools/microsoft/msbuild.py
+++ b/conan/tools/microsoft/msbuild.py
@@ -55,7 +55,7 @@ class MSBuild(object):
:return: ``str`` msbuild command line.
"""
# TODO: Enable output_binary_log via config
- cmd = ('msbuild "%s" /p:Configuration="%s" /p:Platform=%s'
+ cmd = ('msbuild.exe "%s" /p:Configuration="%s" /p:Platform=%s'
% (sln, self.build_type, self.platform))
verbosity = msbuild_verbosity_cmd_line_arg(self._conanfile)
Maybe you can try it? Do you know how to run Conan from source?
If that fixes the issue, I think this might be doable, there shouldn't be a high risk in always expliciting .exe extension. Unless there would be someone out there wrapping msbuild with their own script or something, we might need to evaluate that...
I changed that line of code and tried and it solves the problem. Msbuild gets executed inside of MSYS2 bash. Unfortunately there is another problem: the slashes from the second and third argument got stripped by MSYS2 bash.
Microsoft (R)-Build-Engine, Version 16.11.2+f32259642 für .NET Framework Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
MSBUILD : error MSB1008: Es darf nur ein Projekt angegeben werden. Schalter: p:Configuration=Debug
Luckily Msbuild accepts '/' and '-' and '--' as switch prefixes. I changed slashes to '-' and it worked.
Here is the code snippet:
# TODO: Enable output_binary_log via config
cmd = ('msbuild.exe "%s" -p:Configuration="%s" -p:Platform=%s'
% (sln, self.build_type, self.platform))
Msbuild is also available on unix/linux systems. On those platforms the command maybe 'msbuild' and not 'msbuild.exe'. I did not verify this. Hence I suggest to keep 'msbuild' on non-windows systems. Use 'msbuild.exe' on Windows only. In all cases use '-' rather than slashes as switch prefix.