Repository: conan-io/conan

Issue:
[feature] Tool: is_msvc helper
Our friend and great contributor SpaceIm is using a new detection which I believe could be part of the mainstream:

```python
@property
def _is_msvc(self):
    return str(self.settings.compiler) in ["Visual Studio", "msvc"]
```

This property can be largely re-used, when checking on `validate()` or any other condition.


- [ ] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).



Discussion:
Hi @uilianries 

Yes, makes sense, specially to try to have clean recipes for migrating to 2.0 (only msvc will remain there). 
Do you want to contribute this? I guess it will be a tool in ``conan.tools.build``?
@memsharded Yes, I can do it of course.

> I guess it will be a tool in conan.tools.build?

Build so far is only related to CPU, however, [visual.py](https://github.com/conan-io/conan/blob/develop/conan/tools/microsoft/visual.py) has all Visual Studio information there. I would suggest `conan.tools.visual` in this case.
> Build so far is only related to CPU, however, visual.py has all Visual Studio information there. I would suggest conan.tools.visual in this case.

``conan.tools.visual`` is not public/documented. In any case it should be ``conan.tools.microsoft``. Yes, it makes sense too. I was thinking where all the possible configuration checks would be, like we don't know if it is "microsoft" yet, we are checking, and this was a generic "check", but I agree, it will feel cleaner in ``conan.tools.microsoft``.
I think we also need a helper(s) for compiler runtime:
https://github.com/conan-io/conan-center-index/pull/8801/files#diff-d67d36ebb633f3e920a34cd24c6c92ac12ab88b1f1db0a694841133faeb10fe5R783-R791
```
    @property
    def _runtime(self):
        if self.settings.compiler == "Visual Studio":
            return self.settings.compiler.runtime
        else:
            return "M{}{}".format(
                "T" if self.settings.compiler.runtime == "static" else "D",
                "d" if self.settings.compiler.runtime_type == "Debug" else "",
            )
```
it's pretty widespread among CCI recipes already
(and one more helper could return runtime in a form of MultiThreaded[Debug][Dll], which is also frequently needed)
``msvc_runtime_flag()`` is already in ``visual.py`` and made available via ``conan.tools.microsoft``

Resolving patch:
diff --git a/conan/tools/microsoft/__init__.py b/conan/tools/microsoft/__init__.py
--- a/conan/tools/microsoft/__init__.py
+++ b/conan/tools/microsoft/__init__.py
@@ -1,5 +1,5 @@
 from conan.tools.microsoft.toolchain import MSBuildToolchain
 from conan.tools.microsoft.msbuild import MSBuild
 from conan.tools.microsoft.msbuilddeps import MSBuildDeps
-from conan.tools.microsoft.visual import msvc_runtime_flag, VCVars
+from conan.tools.microsoft.visual import msvc_runtime_flag, VCVars, is_msvc
 from conan.tools.microsoft.subsystems import subsystem_path
diff --git a/conan/tools/microsoft/visual.py b/conan/tools/microsoft/visual.py
--- a/conan/tools/microsoft/visual.py
+++ b/conan/tools/microsoft/visual.py
@@ -172,3 +172,12 @@ def _vcvars_vers(conanfile, compiler, vs_version):
         # The equivalent of compiler 192 is toolset 14.2
         vcvars_ver = "14.{}".format(compiler_version[-1])
     return vcvars_ver
+
+
+def is_msvc(conanfile):
+    """ Validate if current compiler in setttings is 'Visual Studio' or 'msvc'
+    :param conanfile: ConanFile instance
+    :return: True, if the host compiler is related to Visual Studio, otherwise, False.
+    """
+    settings = conanfile.settings
+    return settings.get_safe("compiler") in ["Visual Studio", "msvc"]


Test patch:
diff --git a/conans/test/unittests/tools/microsoft/test_msbuild.py b/conans/test/unittests/tools/microsoft/test_msbuild.py
--- a/conans/test/unittests/tools/microsoft/test_msbuild.py
+++ b/conans/test/unittests/tools/microsoft/test_msbuild.py
@@ -4,7 +4,7 @@
 import pytest
 from mock import Mock
 
-from conan.tools.microsoft import MSBuild, MSBuildToolchain
+from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc
 from conans.model.conf import ConfDefinition, Conf
 from conans.model.env_info import EnvValues
 from conans.test.utils.mocks import ConanFileMock, MockSettings
@@ -172,3 +172,20 @@ def test_msbuild_and_intel_cc_props(mode, expected_toolset):
     props_file = os.path.join(test_folder, 'conantoolchain_release_x64.props')
     msbuild.generate()
     assert '<PlatformToolset>%s</PlatformToolset>' % expected_toolset in load(props_file)
+
+
+@pytest.mark.parametrize("compiler,expected", [
+    ("Visual Studio", True),
+    ("msvc", True),
+    ("clang", False)
+])
+def test_is_msvc(compiler, expected):
+    settings = Settings({"build_type": ["Release"],
+                         "compiler": {compiler: {"version": ["2022"]}},
+                         "os": ["Windows"],
+                         "arch": ["x86_64"]})
+    conanfile = ConanFile(Mock(), None)
+    conanfile.settings = "os", "compiler", "build_type", "arch"
+    conanfile.initialize(settings, EnvValues())
+    conanfile.settings.compiler = compiler
+    assert is_msvc(conanfile) == expected