Repository: conan-io/conan

Issue:
Use MSVC preview versions
To help us debug your issue please explain:

- [x] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.

I've tried to use MSVC 2017 Preview, but conan could not detect it successfully. According to [win.py file](https://github.com/conan-io/conan/blob/cf2c3bd2081f4915ee7992e5f85100ee14afe403/conans/client/tools/win.py#L124), vswhere needs prerelease variable True in order to give find preview versions.


Discussion:
Could I ask why you need the pre-release?  2017 is more than released, right?

Resolving patch:
diff --git a/conans/client/build/cmake_flags.py b/conans/client/build/cmake_flags.py
--- a/conans/client/build/cmake_flags.py
+++ b/conans/client/build/cmake_flags.py
@@ -47,7 +47,8 @@ def get_generator(settings):
                     '11': '11 2012',
                     '12': '12 2013',
                     '14': '14 2015',
-                    '15': '15 2017'}
+                    '15': '15 2017',
+                    '16': '16 2019'}
         base = "Visual Studio %s" % _visuals.get(compiler_version,
                                                  "UnknownVersion %s" % compiler_version)
         if arch == "x86_64":
diff --git a/conans/client/conf/__init__.py b/conans/client/conf/__init__.py
--- a/conans/client/conf/__init__.py
+++ b/conans/client/conf/__init__.py
@@ -60,11 +60,11 @@
         exception: [None, dwarf2, sjlj, seh] # Windows MinGW
     Visual Studio:
         runtime: [MD, MT, MTd, MDd]
-        version: ["8", "9", "10", "11", "12", "14", "15"]
+        version: ["8", "9", "10", "11", "12", "14", "15", "16"]
         toolset: [None, v90, v100, v110, v110_xp, v120, v120_xp,
                   v140, v140_xp, v140_clang_c2, LLVM-vs2012, LLVM-vs2012_xp,
                   LLVM-vs2013, LLVM-vs2013_xp, LLVM-vs2014, LLVM-vs2014_xp,
-                  LLVM-vs2017, LLVM-vs2017_xp, v141, v141_xp, v141_clang_c2]
+                  LLVM-vs2017, LLVM-vs2017_xp, v141, v141_xp, v141_clang_c2, v142]
     clang:
         version: ["3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9", "4.0",
                   "5.0", "6.0", "7.0",
diff --git a/conans/client/tools/win.py b/conans/client/tools/win.py
--- a/conans/client/tools/win.py
+++ b/conans/client/tools/win.py
@@ -59,13 +59,13 @@ def _visual_compiler(output, version):
     if platform.system().startswith("CYGWIN"):
         return _visual_compiler_cygwin(output, version)
 
-    if version == "15":
-        vs_path = os.getenv('vs150comntools')
-        path = vs_path or vs_installation_path("15")
+    if Version(version) >= "15":
+        vs_path = os.getenv('vs%s0comntools' % version)
+        path = vs_path or vs_installation_path(version)
         if path:
             compiler = "Visual Studio"
-            output.success("Found %s %s" % (compiler, "15"))
-            return compiler, "15"
+            output.success("Found %s %s" % (compiler, version))
+            return compiler, version
         return None
 
     version = "%s.0" % version
@@ -93,7 +93,8 @@ def latest_vs_version_installed(output):
     return latest_visual_studio_version_installed(output=output)
 
 
-MSVS_DEFAULT_TOOLSETS = {"15": "v141",
+MSVS_DEFAULT_TOOLSETS = {"16": "v142",
+                         "15": "v141",
                          "14": "v140",
                          "12": "v120",
                          "11": "v110",
@@ -102,7 +103,8 @@ def latest_vs_version_installed(output):
                          "8": "v80"}
 
 # inverse version of the above MSVS_DEFAULT_TOOLSETS (keys and values are swapped)
-MSVS_DEFAULT_TOOLSETS_INVERSE = {"v141": "15",
+MSVS_DEFAULT_TOOLSETS_INVERSE = {"v142": "16",
+                                 "v141": "15",
                                  "v140": "14",
                                  "v120": "12",
                                  "v110": "11",


Test patch:
diff --git a/conans/test/unittests/client/build/msbuild_test.py b/conans/test/unittests/client/build/msbuild_test.py
--- a/conans/test/unittests/client/build/msbuild_test.py
+++ b/conans/test/unittests/client/build/msbuild_test.py
@@ -132,7 +132,8 @@ def get_version_test(self):
         self.assertRegexpMatches(version, "(\d+\.){2,3}\d+")
         self.assertGreater(version, "15.1")
 
-    @parameterized.expand([("15", "v141"),
+    @parameterized.expand([("16", "v142"),
+                           ("15", "v141"),
                            ("14", "v140"),
                            ("12", "v120"),
                            ("11", "v110"),
@@ -149,7 +150,8 @@ def default_toolset_test(self, compiler_version, expected_toolset):
         command = msbuild.get_command("project_should_flags_test_file.sln")
         self.assertIn('/p:PlatformToolset="%s"' % expected_toolset, command)
 
-    @parameterized.expand([("v141",),
+    @parameterized.expand([("v142",),
+                           ("v141",),
                            ("v140",),
                            ("v120",),
                            ("v110",),
diff --git a/conans/test/unittests/model/info/vs_toolset_compatible_test.py b/conans/test/unittests/model/info/vs_toolset_compatible_test.py
--- a/conans/test/unittests/model/info/vs_toolset_compatible_test.py
+++ b/conans/test/unittests/model/info/vs_toolset_compatible_test.py
@@ -11,7 +11,8 @@
 
 
 class VSToolsetCompatibleTest(unittest.TestCase):
-    @parameterized.expand([("14", "v141", "15"),
+    @parameterized.expand([("15", "v142", "16"),
+                           ("14", "v141", "15"),
                            ("15", "v140", "14"),
                            ("11", "v120", "12"),
                            ("12", "v110", "11"),
@@ -29,7 +30,8 @@ def test_compatible(self, initial_version, toolset, expected_version):
         self.assertEqual(info.settings.compiler.version, expected_version)
         self.assertIsNone(info.settings.get_safe("compiler.toolset"))
 
-    @parameterized.expand([("14", "v141_xp"),
+    @parameterized.expand([("16", "v141_xp"),
+                           ("14", "v141_xp"),
                            ("15", "v140_xp"),
                            ("11", "v120_xp"),
                            ("12", "v110_xp"),
diff --git a/conans/test/unittests/util/msvs_toolset_test.py b/conans/test/unittests/util/msvs_toolset_test.py
--- a/conans/test/unittests/util/msvs_toolset_test.py
+++ b/conans/test/unittests/util/msvs_toolset_test.py
@@ -15,7 +15,8 @@
 @unittest.skipUnless(platform.system() == "Windows", "Requires Windows")
 class MSVCToolsetTest(unittest.TestCase):
 
-    @parameterized.expand([("15", "v141"),
+    @parameterized.expand([("16", "v142"),
+                           ("15", "v141"),
                            ("14", "v140"),
                            ("12", "v120"),
                            ("11", "v110"),
@@ -27,7 +28,8 @@ def test_default(self, compiler_version, expected_toolset):
                                  "compiler.version": compiler_version})
         self.assertEqual(expected_toolset, tools.msvs_toolset(settings))
 
-    @parameterized.expand([("15", "v141_xp"),
+    @parameterized.expand([("16", "v141_xp"),
+                           ("15", "v141_xp"),
                            ("14", "v140_xp"),
                            ("12", "v120_xp"),
                            ("11", "v110_xp")])