Repository: conan-io/conan
Pull request: [Bugfix] Added mandatory fields when VS 2022 auto-detection
Changelog: Bugfix: Visual Studio 2022 auto-detected profile was incomplete.
Docs: omit

Closes: https://github.com/conan-io/conan/issues/10302

- [x] Refer to the issue that supports this Pull Request.
- [x] If the issue has missing info, explain the purpose/use case/pain/need that covers this Pull Request.
- [x] I've read the [Contributing guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [x] I've followed the PEP8 style guides for Python code.
- [ ] I've opened another PR in the Conan docs repo to the ``develop`` branch, documenting this one. 

<sup>**Note:** By default this PR will skip the slower tests and will use a limited set of python versions. Check [here](https://github.com/conan-io/conan/blob/develop/.github/PR_INCREASE_TESTING.md) how to increase the testing level by writing some tags in the current PR body text.</sup>


Problem statement:
[bug] Visual Studio 2022 auto-detected profile is incomplete
<!--
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.

  To help us debug your issue please explain:
-->

auto-detected profile for Visual Studio 2022 is incompile, and cannot be used as is, as it's missing the following fields:
- `compiler.cppstd`
- `compiler.runtime`
- `compiler.runtime_type`


### Environment Details (include every applicable attribute)
  * Operating System+version: `Microsoft Windows [Version 10.0.19043.1348]`
  * Compiler+version: `Microsoft (R) C/C++ Optimizing Compiler Version 19.30.30706 for x86`
  * Conan version: `Conan version 1.45.0-dev`
  * Python version: `Python 3.9.7`

### Steps to reproduce (Include if Applicable)

to reproduce, run something like: `conan profile new vs2022 --detect --force`, then try to use it with `conan create`, you'll get:
```
ERROR: : 'settings.compiler.cppstd' value not defined
```

### Logs (Executed commands with output) (Include/Attach if Applicable)

<!--
  Your log content should be related to the bug description, it can be:
  - Conan command output
  - Server output (Artifactory, conan_server)
-->

Hints from issue discussion:

Commit message: Added mandatory fields when VS 2022 auto-detection

Patch to review:
diff --git a/conans/client/conf/detect.py b/conans/client/conf/detect.py
index 80b89c543c1..01332987761 100644
--- a/conans/client/conf/detect.py
+++ b/conans/client/conf/detect.py
@@ -265,6 +265,11 @@ def _detect_compiler_version(result, output, profile_path):
             result.append(("compiler.base.version", "4.8"))
         else:
             result.append(("compiler.base.version", "4.4"))
+    elif compiler == "msvc":
+        # Add default mandatory fields for MSVC compiler
+        result.append(("compiler.cppstd", "14"))
+        result.append(("compiler.runtime", "static"))
+        result.append(("compiler.runtime_type", "Release"))
 
 
 def _detect_os_arch(result, output):
diff --git a/conans/test/unittests/util/detect_test.py b/conans/test/unittests/util/detect_test.py
index 1ab8fe9c326..2bc970c62b6 100644
--- a/conans/test/unittests/util/detect_test.py
+++ b/conans/test/unittests/util/detect_test.py
@@ -102,3 +102,6 @@ def test_vs2022(self):
             result = dict(result)
             self.assertEqual('msvc', result['compiler'])
             self.assertEqual('193', result['compiler.version'])
+            self.assertEqual('14', result['compiler.cppstd'])
+            self.assertEqual('static', result['compiler.runtime'])
+            self.assertEqual('Release', result['compiler.runtime_type'])


Code review comments:
diff_hunk: @@ -265,6 +265,11 @@ def _detect_compiler_version(result, output, profile_path):
             result.append(("compiler.base.version", "4.8"))
         else:
             result.append(("compiler.base.version", "4.4"))
+    elif compiler == "msvc":
+        # Add default mandatory fields for MSVC compiler
+        result.append(("compiler.cppstd", "14"))
+        result.append(("compiler.runtime", "static"))
path: conans/client/conf/detect.py
text: @user1:
```suggestion
        result.append(("compiler.runtime", "dynamic"))
```

I personally would put `dynamic` as a default for a few reasons:
- in Visual Studio itself, `MultiThreadedDll` is a default setting
- for the old "Visual Studio" compiler we detect MD as a default runtime
- I think dynamic CRT is recommended choice by Microsoft for security reasons