Skip to content

[bug] MSBuildDeps is adding .lib extension to libraries regardless of linker #18220

@arnaudmathias

Description

@arnaudmathias

Describe the bug

conan 2.16.1
Windows 11

Description:
The MSBuildDeps generator is adding the .lib extension to libraries regardless of the actual linker in use.
As MSBuild support Android/Linux workflows, the generated .props are not usable for cross-platform development.

For example with Android Arm64:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Label="ConanVariables">
    ...
    <Conanfmt__fmtLibraries>fmt.lib;</Conanfmt__fmtLibraries>
    ...
  </PropertyGroup>
</Project>

Expected behavior:
Only add the .lib extension when the linker require it (msvc link.exe, clang-cl link.exe?)

I investigated a bit on my side and it seems like this part of the code is at fault.
As the libraries name don't have an extension at this point, the else case is always triggered but I'm unsure of the best way to fix it (is there a way to get the linker, do we even know what linker will be used?)

How to reproduce it

It can be reproduced by using the MSBuildDeps generator with a profile that is targeting another platform than Windows.
For example with an Android profile:

Android Profile

[settings]
os=Android
os.api_level=21
arch=armv8
compiler=clang
compiler.version=12
compiler.libcxx=c++_shared
compiler.cppstd=17

[tool_requires]
android-ndk/[*]

conanfile.py

from conan import ConanFile

class Recipe(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "MSBuildDeps"

    def layout(self):
        self.folders.generators = "conan"

    def requirements(self):
        self.requires("fmt/10.2.1")

install with the provided profile
conan install conanfile.py -s build_type=Release --profile android.profile

Then checking the generated props for the library name in conan/conan_fmt__fmt_vars_release_arm64.props, we can see the extension is wrong
<Conanfmt__fmtLibraries>fmt.lib;</Conanfmt__fmtLibraries>

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions