conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.14k stars 970 forks source link

[question] Visual Studio 2022: the wrong toolset is selected #16774

Open db4 opened 1 month ago

db4 commented 1 month ago

What is your question?

I have a VS 2022 setup with both MSVC 19.39 (toolset 1439) and 19.40 (toolset 14.40) installed. (I need it to be able to use both compiler.version=193 and compiler.version=194 with Conan). Version 193 works without issues but when I specify -s compiler.version=194 CMake generator still selects MSVC 19.39. I found a recommendation in https://github.com/conan-io/conan/pull/15588 to use -s compiler.update=0. It works, but effectively disables the compatibility plugin - all dependencies should then be rebuilt with compiler.version=194. Is there any less intrusive solution? Can I ask CMakeToolchain generator to add version=14.40 to CMAKE_GENERATOR_TOOLSET without breaking compatibility with older versions?

Have you read the CONTRIBUTING guide?

memsharded commented 1 month ago

Hi @db4

Thanks for your feedback. I assume you are using latest Conan 2.6?

The main issue for this seems to be outside of Conan. When installing update 17.10 with 19.40, VS uninstall 19.39. Installing it again leaves some files in the VS installation with bad configuration, so the combo CMake + VS (with VIsual Studio CMake generators) doesn't work nicely to select 19.40 or 19.39.

Interestingly, when using some other generator like Ninja, then Conan is able to define the environment via VCVars and everything works fine, it is possible to switch between 19.39 and 19.40 just by setting the compiler version, without having to set the update. You can also check that if you install some other older version like 19.38, you might be able to switch and use it from Conan.

Can you please try those to make sure?

@jcar87 was describing some of the issues in https://github.com/conan-io/conan/pull/15588#issuecomment-2096652138, and also how the upgrade to 17.10 could generate those issues, and https://developercommunity.visualstudio.com/t/MicrosoftVCToolsVersionv143defaulttx/10041951#T-N10601904 as related.

Does this help?