We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Bug - MSBuild helper should not force compiler flags such as `/o`
It seems that the `.props` file used to inject a few things implicitly into the build sometimes results in conflicts as seen here: 
```
     2>cl : Command line warning D9025: overriding '/O2' with '/Od' [path_to_my_project.vcxproj]
     2>cl : Command line warning D9025: overriding '/Od' with '/O2' [path_to_my_project.vcxproj]
    <..... above pair of message seen dozens of times.>
     2>cl : Command line error D8016: '/RTC1' and '/O2' command-line options are incompatible 
```
This can happen in very common circumstances, including any projects that have "Runtime checks" enabled, which I believe is the default for DLL projects. 

Eventually, would be good to validate whatever flags are being injected. 

- [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.



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `conans/client/build/visual_environment.py`
Content:
```
1 import copy
2 import os
3 
4 from conans.client.build.compiler_flags import build_type_define, build_type_flags, visual_runtime, format_defines, \
5     include_path_option, parallel_compiler_cl_flag
6 from conans.client.build.cppstd_flags import cppstd_flag
7 
8 
9 class VisualStudioBuildEnvironment(object):
10     """
11     - LIB: library paths with semicolon separator
12     - CL: /I (include paths)
13     - _LINK_: linker options and libraries
14 
15     https://msdn.microsoft.com/en-us/library/19z1t1wy.aspx
16     https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx
17     https://msdn.microsoft.com/en-us/library/9s7c9wdw.aspx
18     https://msdn.microsoft.com/en-us/library/6y6t9esh.aspx
19 
20     """
21     def __init__(self, conanfile):
22         """
23         :param conanfile: ConanFile instance
24         :param quote_paths: The path directories will be quoted. If you are using the vars together with
25                             environment_append keep it to True, for virtualbuildenv quote_paths=False is required.
26         """
27         self._settings = conanfile.settings
28         self._deps_cpp_info = conanfile.deps_cpp_info
29         self._runtime = self._settings.get_safe("compiler.runtime")
30 
31         self.include_paths = conanfile.deps_cpp_info.include_paths
32         self.lib_paths = conanfile.deps_cpp_info.lib_paths
33         self.defines = copy.copy(conanfile.deps_cpp_info.defines)
34         self.flags = self._configure_flags()
35         self.cxx_flags = copy.copy(self._deps_cpp_info.cppflags)
36         self.link_flags = self._configure_link_flags()
37         self.libs = conanfile.deps_cpp_info.libs
38         self.std = self._std_cpp()
39         self.parallel = False
40 
41     def _configure_link_flags(self):
42         ret = copy.copy(self._deps_cpp_info.exelinkflags)
43         ret.extend(self._deps_cpp_info.sharedlinkflags)
44         return ret
45 
46     def _configure_flags(self):
47         ret = copy.copy(self._deps_cpp_info.cflags)
48         ret.extend(vs_build_type_flags(self._settings))
49         return ret
50 
51     def _get_cl_list(self, quotes=True):
52         # FIXME: It should be managed with the compiler_flags module
53         # But need further investigation about the quotes and so on, so better to not break anything
54         if quotes:
55             ret = ['%s"%s"' % (include_path_option, lib) for lib in self.include_paths]
56         else:
57             ret = ['%s%s' % (include_path_option, lib) for lib in self.include_paths]
58 
59         runtime = visual_runtime(self._runtime)
60         if runtime:
61             ret.append(runtime)
62 
63         ret.extend(format_defines(self.defines))
64         ret.extend(self.flags)
65         ret.extend(self.cxx_flags)
66 
67         if self.parallel:  # Build source in parallel
68             ret.append(parallel_compiler_cl_flag())
69 
70         if self.std:
71             ret.append(self.std)
72 
73         return ret
74 
75     def _get_link_list(self):
76         def format_lib(lib):
77             return lib if lib.endswith('.lib') else '%s.lib' % lib
78 
79         ret = [flag for flag in self.link_flags]  # copy
80         ret.extend([format_lib(lib) for lib in self.libs])
81 
82         return ret
83 
84     @property
85     def vars(self):
86         """Used in conanfile with environment_append"""
87         flags = self._get_cl_list()
88         link_flags = self._get_link_list()
89 
90         cl_args = " ".join(flags) + _environ_value_prefix("CL")
91         link_args = " ".join(link_flags)
92         lib_paths = ";".join(['%s' % lib for lib in self.lib_paths]) + _environ_value_prefix("LIB", ";")
93         return {"CL": cl_args,
94                 "LIB": lib_paths,
95                 "_LINK_": link_args}
96 
97     @property
98     def vars_dict(self):
99         """Used in virtualbuildenvironment"""
100         # Here we do not quote the include paths, it's going to be used by virtual environment
101         cl = self._get_cl_list(quotes=False)
102         link = self._get_link_list()
103 
104         lib = [lib for lib in self.lib_paths]  # copy
105 
106         if os.environ.get("CL", None):
107             cl.append(os.environ.get("CL"))
108 
109         if os.environ.get("LIB", None):
110             lib.append(os.environ.get("LIB"))
111 
112         if os.environ.get("_LINK_", None):
113             link.append(os.environ.get("_LINK_"))
114 
115         ret = {"CL": cl,
116                "LIB": lib,
117                "_LINK_": link}
118         return ret
119 
120     def _std_cpp(self):
121         return vs_std_cpp(self._settings)
122 
123 
124 def vs_build_type_flags(settings):
125     build_type = settings.get_safe("build_type")
126     ret = []
127     btd = build_type_define(build_type=build_type)
128     if btd:
129         ret.extend(format_defines([btd]))
130     btfs = build_type_flags("Visual Studio", build_type=build_type,
131                             vs_toolset=settings.get_safe("compiler.toolset"))
132     if btfs:
133         ret.extend(btfs)
134 
135     return ret
136 
137 
138 def vs_std_cpp(settings):
139     if settings.get_safe("compiler") == "Visual Studio" and \
140        settings.get_safe("cppstd"):
141         flag = cppstd_flag(settings.get_safe("compiler"),
142                            settings.get_safe("compiler.version"),
143                            settings.get_safe("cppstd"))
144         return flag
145     return None
146 
147 
148 def _environ_value_prefix(var_name, prefix=" "):
149     if os.environ.get(var_name, ""):
150         return "%s%s" % (prefix, os.environ.get(var_name, ""))
151     else:
152         return ""
153
```

Path: `conans/client/build/msbuild.py`
Content:
```
1 import copy
2 import re
3 
4 from conans import tools
5 from conans.client.build.visual_environment import (VisualStudioBuildEnvironment,
6                                                     vs_build_type_flags, vs_std_cpp)
7 from conans.client.tools.oss import cpu_count
8 from conans.client.tools.win import vcvars_command
9 from conans.errors import ConanException
10 from conans.util.env_reader import get_env
11 from conans.util.files import tmp_file
12 from conans.model.conan_file import ConanFile
13 
14 
15 class MSBuild(object):
16 
17     def __init__(self, conanfile):
18         if isinstance(conanfile, ConanFile):
19             self._conanfile = conanfile
20             self._settings = self._conanfile.settings
21             self._output = self._conanfile.output
22             self.build_env = VisualStudioBuildEnvironment(self._conanfile)
23         else:  # backwards compatible with build_sln_command
24             self._settings = conanfile
25             self.build_env = None
26 
27     def build(self, project_file, targets=None, upgrade_project=True, build_type=None, arch=None,
28               parallel=True, force_vcvars=False, toolset=None, platforms=None, use_env=True,
29               vcvars_ver=None, winsdk_version=None, properties=None):
30 
31         self.build_env.parallel = parallel
32 
33         with tools.environment_append(self.build_env.vars):
34             # Path for custom properties file
35             props_file_contents = self._get_props_file_contents()
36             with tmp_file(props_file_contents) as props_file_path:
37                 vcvars = vcvars_command(self._conanfile.settings, force=force_vcvars,
38                                         vcvars_ver=vcvars_ver, winsdk_version=winsdk_version)
39                 command = self.get_command(project_file, props_file_path,
40                                            targets=targets, upgrade_project=upgrade_project,
41                                            build_type=build_type, arch=arch, parallel=parallel,
42                                            toolset=toolset, platforms=platforms,
43                                            use_env=use_env, properties=properties)
44                 command = "%s && %s" % (vcvars, command)
45                 return self._conanfile.run(command)
46 
47     def get_command(self, project_file, props_file_path=None, targets=None, upgrade_project=True,
48                     build_type=None, arch=None, parallel=True, toolset=None, platforms=None,
49                     use_env=False, properties=None):
50 
51         targets = targets or []
52         properties = properties or {}
53         command = []
54 
55         if upgrade_project and not get_env("CONAN_SKIP_VS_PROJECTS_UPGRADE", False):
56             command.append('devenv "%s" /upgrade &&' % project_file)
57         else:
58             self._output.info("Skipped sln project upgrade")
59 
60         build_type = build_type or self._settings.get_safe("build_type")
61         arch = arch or self._settings.get_safe("arch")
62         if not build_type:
63             raise ConanException("Cannot build_sln_command, build_type not defined")
64         if not arch:
65             raise ConanException("Cannot build_sln_command, arch not defined")
66 
67         command.append('msbuild "%s" /p:Configuration="%s"' % (project_file, build_type))
68         msvc_arch = {'x86': 'x86',
69                      'x86_64': 'x64',
70                      'armv7': 'ARM',
71                      'armv8': 'ARM64'}
72         if platforms:
73             msvc_arch.update(platforms)
74         msvc_arch = msvc_arch.get(str(arch))
75         try:
76             sln = tools.load(project_file)
77             pattern = re.compile(r"GlobalSection\(SolutionConfigurationPlatforms\)"
78                                  r"(.*?)EndGlobalSection", re.DOTALL)
79             solution_global = pattern.search(sln).group(1)
80             lines = solution_global.splitlines()
81             lines = [s.split("=")[0].strip() for s in lines]
82         except Exception:
83             pass
84         else:
85             config = "%s|%s" % (build_type, msvc_arch)
86             if config not in "".join(lines):
87                 self._output.warn("***** The configuration %s does not exist in this solution *****" % config)
88                 self._output.warn("Use 'platforms' argument to define your architectures")
89 
90         if use_env:
91             command.append('/p:UseEnv=true')
92 
93         if msvc_arch:
94             command.append('/p:Platform="%s"' % msvc_arch)
95 
96         if parallel:
97             command.append('/m:%s' % cpu_count())
98 
99         if targets:
100             command.append("/target:%s" % ";".join(targets))
101 
102         if toolset:
103             command.append('/p:PlatformToolset="%s"' % toolset)
104 
105         if props_file_path:
106             command.append('/p:ForceImportBeforeCppTargets="%s"' % props_file_path)
107 
108         for name, value in properties.items():
109             command.append('/p:%s="%s"' % (name, value))
110 
111         return " ".join(command)
112 
113     def _get_props_file_contents(self):
114         # how to specify runtime in command line:
115         # https://stackoverflow.com/questions/38840332/msbuild-overrides-properties-while-building-vc-project
116         runtime_library = {"MT": "MultiThreaded",
117                            "MTd": "MultiThreadedDebug",
118                            "MD": "MultiThreadedDLL",
119                            "MDd": "MultiThreadedDebugDLL"}.get(self._settings.get_safe("compiler.runtime"), "")
120 
121         if self.build_env:
122             # Take the flags from the build env, the user was able to alter them if needed
123             flags = copy.copy(self.build_env.flags)
124             flags.append(self.build_env.std)
125         else:  # To be removed when build_sln_command is deprecated
126             flags = vs_build_type_flags(self._settings)
127             flags.append(vs_std_cpp(self._settings))
128 
129         flags_str = " ".join(list(filter(None, flags))) # Removes empty and None elements
130         additional_node = "<AdditionalOptions>" \
131                           "{} %(AdditionalOptions)" \
132                           "</AdditionalOptions>".format(flags_str) if flags_str else ""
133         runtime_node = "<RuntimeLibrary>" \
134                        "{}" \
135                        "</RuntimeLibrary>".format(runtime_library) if runtime_library else ""
136         template = """<?xml version="1.0" encoding="utf-8"?>
137 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
138   <ItemDefinitionGroup>
139     <ClCompile>
140       {runtime_node}
141       {additional_node}
142     </ClCompile>
143   </ItemDefinitionGroup>
144 </Project>""".format(**{"runtime_node": runtime_node,
145                         "additional_node": additional_node})
146         return template
147
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/conans/client/build/msbuild.py b/conans/client/build/msbuild.py
--- a/conans/client/build/msbuild.py
+++ b/conans/client/build/msbuild.py
@@ -19,7 +19,8 @@
             self._conanfile = conanfile
             self._settings = self._conanfile.settings
             self._output = self._conanfile.output
-            self.build_env = VisualStudioBuildEnvironment(self._conanfile)
+            self.build_env = VisualStudioBuildEnvironment(self._conanfile,
+                                                          with_build_type_flags=False)
         else:  # backwards compatible with build_sln_command
             self._settings = conanfile
             self.build_env = None
@@ -123,7 +124,7 @@
             flags = copy.copy(self.build_env.flags)
             flags.append(self.build_env.std)
         else:  # To be removed when build_sln_command is deprecated
-            flags = vs_build_type_flags(self._settings)
+            flags = vs_build_type_flags(self._settings, with_flags=False)
             flags.append(vs_std_cpp(self._settings))
 
         flags_str = " ".join(list(filter(None, flags))) # Removes empty and None elements
diff --git a/conans/client/build/visual_environment.py b/conans/client/build/visual_environment.py
--- a/conans/client/build/visual_environment.py
+++ b/conans/client/build/visual_environment.py
@@ -18,12 +18,14 @@
     https://msdn.microsoft.com/en-us/library/6y6t9esh.aspx
 
     """
-    def __init__(self, conanfile):
+    def __init__(self, conanfile, with_build_type_flags=True):
         """
         :param conanfile: ConanFile instance
         :param quote_paths: The path directories will be quoted. If you are using the vars together with
                             environment_append keep it to True, for virtualbuildenv quote_paths=False is required.
         """
+        self._with_build_type_flags = with_build_type_flags
+
         self._settings = conanfile.settings
         self._deps_cpp_info = conanfile.deps_cpp_info
         self._runtime = self._settings.get_safe("compiler.runtime")
@@ -45,7 +47,7 @@
 
     def _configure_flags(self):
         ret = copy.copy(self._deps_cpp_info.cflags)
-        ret.extend(vs_build_type_flags(self._settings))
+        ret.extend(vs_build_type_flags(self._settings, with_flags=self._with_build_type_flags))
         return ret
 
     def _get_cl_list(self, quotes=True):
@@ -121,16 +123,18 @@
         return vs_std_cpp(self._settings)
 
 
-def vs_build_type_flags(settings):
+def vs_build_type_flags(settings, with_flags=True):
     build_type = settings.get_safe("build_type")
     ret = []
     btd = build_type_define(build_type=build_type)
     if btd:
         ret.extend(format_defines([btd]))
-    btfs = build_type_flags("Visual Studio", build_type=build_type,
-                            vs_toolset=settings.get_safe("compiler.toolset"))
-    if btfs:
-        ret.extend(btfs)
+    if with_flags:
+        # When using to build a vs project we don't want to adjust these flags
+        btfs = build_type_flags("Visual Studio", build_type=build_type,
+                                vs_toolset=settings.get_safe("compiler.toolset"))
+        if btfs:
+            ret.extend(btfs)
 
     return ret

{"golden_diff": "diff --git a/conans/client/build/msbuild.py b/conans/client/build/msbuild.py\n--- a/conans/client/build/msbuild.py\n+++ b/conans/client/build/msbuild.py\n@@ -19,7 +19,8 @@\n             self._conanfile = conanfile\n             self._settings = self._conanfile.settings\n             self._output = self._conanfile.output\n-            self.build_env = VisualStudioBuildEnvironment(self._conanfile)\n+            self.build_env = VisualStudioBuildEnvironment(self._conanfile,\n+                                                          with_build_type_flags=False)\n         else:  # backwards compatible with build_sln_command\n             self._settings = conanfile\n             self.build_env = None\n@@ -123,7 +124,7 @@\n             flags = copy.copy(self.build_env.flags)\n             flags.append(self.build_env.std)\n         else:  # To be removed when build_sln_command is deprecated\n-            flags = vs_build_type_flags(self._settings)\n+            flags = vs_build_type_flags(self._settings, with_flags=False)\n             flags.append(vs_std_cpp(self._settings))\n \n         flags_str = \" \".join(list(filter(None, flags))) # Removes empty and None elements\ndiff --git a/conans/client/build/visual_environment.py b/conans/client/build/visual_environment.py\n--- a/conans/client/build/visual_environment.py\n+++ b/conans/client/build/visual_environment.py\n@@ -18,12 +18,14 @@\n     https://msdn.microsoft.com/en-us/library/6y6t9esh.aspx\n \n     \"\"\"\n-    def __init__(self, conanfile):\n+    def __init__(self, conanfile, with_build_type_flags=True):\n         \"\"\"\n         :param conanfile: ConanFile instance\n         :param quote_paths: The path directories will be quoted. If you are using the vars together with\n                             environment_append keep it to True, for virtualbuildenv quote_paths=False is required.\n         \"\"\"\n+        self._with_build_type_flags = with_build_type_flags\n+\n         self._settings = conanfile.settings\n         self._deps_cpp_info = conanfile.deps_cpp_info\n         self._runtime = self._settings.get_safe(\"compiler.runtime\")\n@@ -45,7 +47,7 @@\n \n     def _configure_flags(self):\n         ret = copy.copy(self._deps_cpp_info.cflags)\n-        ret.extend(vs_build_type_flags(self._settings))\n+        ret.extend(vs_build_type_flags(self._settings, with_flags=self._with_build_type_flags))\n         return ret\n \n     def _get_cl_list(self, quotes=True):\n@@ -121,16 +123,18 @@\n         return vs_std_cpp(self._settings)\n \n \n-def vs_build_type_flags(settings):\n+def vs_build_type_flags(settings, with_flags=True):\n     build_type = settings.get_safe(\"build_type\")\n     ret = []\n     btd = build_type_define(build_type=build_type)\n     if btd:\n         ret.extend(format_defines([btd]))\n-    btfs = build_type_flags(\"Visual Studio\", build_type=build_type,\n-                            vs_toolset=settings.get_safe(\"compiler.toolset\"))\n-    if btfs:\n-        ret.extend(btfs)\n+    if with_flags:\n+        # When using to build a vs project we don't want to adjust these flags\n+        btfs = build_type_flags(\"Visual Studio\", build_type=build_type,\n+                                vs_toolset=settings.get_safe(\"compiler.toolset\"))\n+        if btfs:\n+            ret.extend(btfs)\n \n     return ret\n", "issue": "Bug - MSBuild helper should not force compiler flags such as `/o`\nIt seems that the `.props` file used to inject a few things implicitly into the build sometimes results in conflicts as seen here: \r\n```\r\n     2>cl : Command line warning D9025: overriding '/O2' with '/Od' [path_to_my_project.vcxproj]\r\n     2>cl : Command line warning D9025: overriding '/Od' with '/O2' [path_to_my_project.vcxproj]\r\n    <..... above pair of message seen dozens of times.>\r\n     2>cl : Command line error D8016: '/RTC1' and '/O2' command-line options are incompatible \r\n```\r\nThis can happen in very common circumstances, including any projects that have \"Runtime checks\" enabled, which I believe is the default for DLL projects. \r\n\r\nEventually, would be good to validate whatever flags are being injected. \r\n\r\n- [x] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).\r\n- [x] I've specified the Conan version, operating system version and any tool that can be relevant.\r\n- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.\r\n\r\n\n", "before_files": [{"content": "import copy\nimport os\n\nfrom conans.client.build.compiler_flags import build_type_define, build_type_flags, visual_runtime, format_defines, \\\n    include_path_option, parallel_compiler_cl_flag\nfrom conans.client.build.cppstd_flags import cppstd_flag\n\n\nclass VisualStudioBuildEnvironment(object):\n    \"\"\"\n    - LIB: library paths with semicolon separator\n    - CL: /I (include paths)\n    - _LINK_: linker options and libraries\n\n    https://msdn.microsoft.com/en-us/library/19z1t1wy.aspx\n    https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx\n    https://msdn.microsoft.com/en-us/library/9s7c9wdw.aspx\n    https://msdn.microsoft.com/en-us/library/6y6t9esh.aspx\n\n    \"\"\"\n    def __init__(self, conanfile):\n        \"\"\"\n        :param conanfile: ConanFile instance\n        :param quote_paths: The path directories will be quoted. If you are using the vars together with\n                            environment_append keep it to True, for virtualbuildenv quote_paths=False is required.\n        \"\"\"\n        self._settings = conanfile.settings\n        self._deps_cpp_info = conanfile.deps_cpp_info\n        self._runtime = self._settings.get_safe(\"compiler.runtime\")\n\n        self.include_paths = conanfile.deps_cpp_info.include_paths\n        self.lib_paths = conanfile.deps_cpp_info.lib_paths\n        self.defines = copy.copy(conanfile.deps_cpp_info.defines)\n        self.flags = self._configure_flags()\n        self.cxx_flags = copy.copy(self._deps_cpp_info.cppflags)\n        self.link_flags = self._configure_link_flags()\n        self.libs = conanfile.deps_cpp_info.libs\n        self.std = self._std_cpp()\n        self.parallel = False\n\n    def _configure_link_flags(self):\n        ret = copy.copy(self._deps_cpp_info.exelinkflags)\n        ret.extend(self._deps_cpp_info.sharedlinkflags)\n        return ret\n\n    def _configure_flags(self):\n        ret = copy.copy(self._deps_cpp_info.cflags)\n        ret.extend(vs_build_type_flags(self._settings))\n        return ret\n\n    def _get_cl_list(self, quotes=True):\n        # FIXME: It should be managed with the compiler_flags module\n        # But need further investigation about the quotes and so on, so better to not break anything\n        if quotes:\n            ret = ['%s\"%s\"' % (include_path_option, lib) for lib in self.include_paths]\n        else:\n            ret = ['%s%s' % (include_path_option, lib) for lib in self.include_paths]\n\n        runtime = visual_runtime(self._runtime)\n        if runtime:\n            ret.append(runtime)\n\n        ret.extend(format_defines(self.defines))\n        ret.extend(self.flags)\n        ret.extend(self.cxx_flags)\n\n        if self.parallel:  # Build source in parallel\n            ret.append(parallel_compiler_cl_flag())\n\n        if self.std:\n            ret.append(self.std)\n\n        return ret\n\n    def _get_link_list(self):\n        def format_lib(lib):\n            return lib if lib.endswith('.lib') else '%s.lib' % lib\n\n        ret = [flag for flag in self.link_flags]  # copy\n        ret.extend([format_lib(lib) for lib in self.libs])\n\n        return ret\n\n    @property\n    def vars(self):\n        \"\"\"Used in conanfile with environment_append\"\"\"\n        flags = self._get_cl_list()\n        link_flags = self._get_link_list()\n\n        cl_args = \" \".join(flags) + _environ_value_prefix(\"CL\")\n        link_args = \" \".join(link_flags)\n        lib_paths = \";\".join(['%s' % lib for lib in self.lib_paths]) + _environ_value_prefix(\"LIB\", \";\")\n        return {\"CL\": cl_args,\n                \"LIB\": lib_paths,\n                \"_LINK_\": link_args}\n\n    @property\n    def vars_dict(self):\n        \"\"\"Used in virtualbuildenvironment\"\"\"\n        # Here we do not quote the include paths, it's going to be used by virtual environment\n        cl = self._get_cl_list(quotes=False)\n        link = self._get_link_list()\n\n        lib = [lib for lib in self.lib_paths]  # copy\n\n        if os.environ.get(\"CL\", None):\n            cl.append(os.environ.get(\"CL\"))\n\n        if os.environ.get(\"LIB\", None):\n            lib.append(os.environ.get(\"LIB\"))\n\n        if os.environ.get(\"_LINK_\", None):\n            link.append(os.environ.get(\"_LINK_\"))\n\n        ret = {\"CL\": cl,\n               \"LIB\": lib,\n               \"_LINK_\": link}\n        return ret\n\n    def _std_cpp(self):\n        return vs_std_cpp(self._settings)\n\n\ndef vs_build_type_flags(settings):\n    build_type = settings.get_safe(\"build_type\")\n    ret = []\n    btd = build_type_define(build_type=build_type)\n    if btd:\n        ret.extend(format_defines([btd]))\n    btfs = build_type_flags(\"Visual Studio\", build_type=build_type,\n                            vs_toolset=settings.get_safe(\"compiler.toolset\"))\n    if btfs:\n        ret.extend(btfs)\n\n    return ret\n\n\ndef vs_std_cpp(settings):\n    if settings.get_safe(\"compiler\") == \"Visual Studio\" and \\\n       settings.get_safe(\"cppstd\"):\n        flag = cppstd_flag(settings.get_safe(\"compiler\"),\n                           settings.get_safe(\"compiler.version\"),\n                           settings.get_safe(\"cppstd\"))\n        return flag\n    return None\n\n\ndef _environ_value_prefix(var_name, prefix=\" \"):\n    if os.environ.get(var_name, \"\"):\n        return \"%s%s\" % (prefix, os.environ.get(var_name, \"\"))\n    else:\n        return \"\"\n", "path": "conans/client/build/visual_environment.py"}, {"content": "import copy\nimport re\n\nfrom conans import tools\nfrom conans.client.build.visual_environment import (VisualStudioBuildEnvironment,\n                                                    vs_build_type_flags, vs_std_cpp)\nfrom conans.client.tools.oss import cpu_count\nfrom conans.client.tools.win import vcvars_command\nfrom conans.errors import ConanException\nfrom conans.util.env_reader import get_env\nfrom conans.util.files import tmp_file\nfrom conans.model.conan_file import ConanFile\n\n\nclass MSBuild(object):\n\n    def __init__(self, conanfile):\n        if isinstance(conanfile, ConanFile):\n            self._conanfile = conanfile\n            self._settings = self._conanfile.settings\n            self._output = self._conanfile.output\n            self.build_env = VisualStudioBuildEnvironment(self._conanfile)\n        else:  # backwards compatible with build_sln_command\n            self._settings = conanfile\n            self.build_env = None\n\n    def build(self, project_file, targets=None, upgrade_project=True, build_type=None, arch=None,\n              parallel=True, force_vcvars=False, toolset=None, platforms=None, use_env=True,\n              vcvars_ver=None, winsdk_version=None, properties=None):\n\n        self.build_env.parallel = parallel\n\n        with tools.environment_append(self.build_env.vars):\n            # Path for custom properties file\n            props_file_contents = self._get_props_file_contents()\n            with tmp_file(props_file_contents) as props_file_path:\n                vcvars = vcvars_command(self._conanfile.settings, force=force_vcvars,\n                                        vcvars_ver=vcvars_ver, winsdk_version=winsdk_version)\n                command = self.get_command(project_file, props_file_path,\n                                           targets=targets, upgrade_project=upgrade_project,\n                                           build_type=build_type, arch=arch, parallel=parallel,\n                                           toolset=toolset, platforms=platforms,\n                                           use_env=use_env, properties=properties)\n                command = \"%s && %s\" % (vcvars, command)\n                return self._conanfile.run(command)\n\n    def get_command(self, project_file, props_file_path=None, targets=None, upgrade_project=True,\n                    build_type=None, arch=None, parallel=True, toolset=None, platforms=None,\n                    use_env=False, properties=None):\n\n        targets = targets or []\n        properties = properties or {}\n        command = []\n\n        if upgrade_project and not get_env(\"CONAN_SKIP_VS_PROJECTS_UPGRADE\", False):\n            command.append('devenv \"%s\" /upgrade &&' % project_file)\n        else:\n            self._output.info(\"Skipped sln project upgrade\")\n\n        build_type = build_type or self._settings.get_safe(\"build_type\")\n        arch = arch or self._settings.get_safe(\"arch\")\n        if not build_type:\n            raise ConanException(\"Cannot build_sln_command, build_type not defined\")\n        if not arch:\n            raise ConanException(\"Cannot build_sln_command, arch not defined\")\n\n        command.append('msbuild \"%s\" /p:Configuration=\"%s\"' % (project_file, build_type))\n        msvc_arch = {'x86': 'x86',\n                     'x86_64': 'x64',\n                     'armv7': 'ARM',\n                     'armv8': 'ARM64'}\n        if platforms:\n            msvc_arch.update(platforms)\n        msvc_arch = msvc_arch.get(str(arch))\n        try:\n            sln = tools.load(project_file)\n            pattern = re.compile(r\"GlobalSection\\(SolutionConfigurationPlatforms\\)\"\n                                 r\"(.*?)EndGlobalSection\", re.DOTALL)\n            solution_global = pattern.search(sln).group(1)\n            lines = solution_global.splitlines()\n            lines = [s.split(\"=\")[0].strip() for s in lines]\n        except Exception:\n            pass\n        else:\n            config = \"%s|%s\" % (build_type, msvc_arch)\n            if config not in \"\".join(lines):\n                self._output.warn(\"***** The configuration %s does not exist in this solution *****\" % config)\n                self._output.warn(\"Use 'platforms' argument to define your architectures\")\n\n        if use_env:\n            command.append('/p:UseEnv=true')\n\n        if msvc_arch:\n            command.append('/p:Platform=\"%s\"' % msvc_arch)\n\n        if parallel:\n            command.append('/m:%s' % cpu_count())\n\n        if targets:\n            command.append(\"/target:%s\" % \";\".join(targets))\n\n        if toolset:\n            command.append('/p:PlatformToolset=\"%s\"' % toolset)\n\n        if props_file_path:\n            command.append('/p:ForceImportBeforeCppTargets=\"%s\"' % props_file_path)\n\n        for name, value in properties.items():\n            command.append('/p:%s=\"%s\"' % (name, value))\n\n        return \" \".join(command)\n\n    def _get_props_file_contents(self):\n        # how to specify runtime in command line:\n        # https://stackoverflow.com/questions/38840332/msbuild-overrides-properties-while-building-vc-project\n        runtime_library = {\"MT\": \"MultiThreaded\",\n                           \"MTd\": \"MultiThreadedDebug\",\n                           \"MD\": \"MultiThreadedDLL\",\n                           \"MDd\": \"MultiThreadedDebugDLL\"}.get(self._settings.get_safe(\"compiler.runtime\"), \"\")\n\n        if self.build_env:\n            # Take the flags from the build env, the user was able to alter them if needed\n            flags = copy.copy(self.build_env.flags)\n            flags.append(self.build_env.std)\n        else:  # To be removed when build_sln_command is deprecated\n            flags = vs_build_type_flags(self._settings)\n            flags.append(vs_std_cpp(self._settings))\n\n        flags_str = \" \".join(list(filter(None, flags))) # Removes empty and None elements\n        additional_node = \"<AdditionalOptions>\" \\\n                          \"{} %(AdditionalOptions)\" \\\n                          \"</AdditionalOptions>\".format(flags_str) if flags_str else \"\"\n        runtime_node = \"<RuntimeLibrary>\" \\\n                       \"{}\" \\\n                       \"</RuntimeLibrary>\".format(runtime_library) if runtime_library else \"\"\n        template = \"\"\"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemDefinitionGroup>\n    <ClCompile>\n      {runtime_node}\n      {additional_node}\n    </ClCompile>\n  </ItemDefinitionGroup>\n</Project>\"\"\".format(**{\"runtime_node\": runtime_node,\n                        \"additional_node\": additional_node})\n        return template\n", "path": "conans/client/build/msbuild.py"}], "after_files": [{"content": "import copy\nimport os\n\nfrom conans.client.build.compiler_flags import build_type_define, build_type_flags, visual_runtime, format_defines, \\\n    include_path_option, parallel_compiler_cl_flag\nfrom conans.client.build.cppstd_flags import cppstd_flag\n\n\nclass VisualStudioBuildEnvironment(object):\n    \"\"\"\n    - LIB: library paths with semicolon separator\n    - CL: /I (include paths)\n    - _LINK_: linker options and libraries\n\n    https://msdn.microsoft.com/en-us/library/19z1t1wy.aspx\n    https://msdn.microsoft.com/en-us/library/fwkeyyhe.aspx\n    https://msdn.microsoft.com/en-us/library/9s7c9wdw.aspx\n    https://msdn.microsoft.com/en-us/library/6y6t9esh.aspx\n\n    \"\"\"\n    def __init__(self, conanfile, with_build_type_flags=True):\n        \"\"\"\n        :param conanfile: ConanFile instance\n        :param quote_paths: The path directories will be quoted. If you are using the vars together with\n                            environment_append keep it to True, for virtualbuildenv quote_paths=False is required.\n        \"\"\"\n        self._with_build_type_flags = with_build_type_flags\n\n        self._settings = conanfile.settings\n        self._deps_cpp_info = conanfile.deps_cpp_info\n        self._runtime = self._settings.get_safe(\"compiler.runtime\")\n\n        self.include_paths = conanfile.deps_cpp_info.include_paths\n        self.lib_paths = conanfile.deps_cpp_info.lib_paths\n        self.defines = copy.copy(conanfile.deps_cpp_info.defines)\n        self.flags = self._configure_flags()\n        self.cxx_flags = copy.copy(self._deps_cpp_info.cppflags)\n        self.link_flags = self._configure_link_flags()\n        self.libs = conanfile.deps_cpp_info.libs\n        self.std = self._std_cpp()\n        self.parallel = False\n\n    def _configure_link_flags(self):\n        ret = copy.copy(self._deps_cpp_info.exelinkflags)\n        ret.extend(self._deps_cpp_info.sharedlinkflags)\n        return ret\n\n    def _configure_flags(self):\n        ret = copy.copy(self._deps_cpp_info.cflags)\n        ret.extend(vs_build_type_flags(self._settings, with_flags=self._with_build_type_flags))\n        return ret\n\n    def _get_cl_list(self, quotes=True):\n        # FIXME: It should be managed with the compiler_flags module\n        # But need further investigation about the quotes and so on, so better to not break anything\n        if quotes:\n            ret = ['%s\"%s\"' % (include_path_option, lib) for lib in self.include_paths]\n        else:\n            ret = ['%s%s' % (include_path_option, lib) for lib in self.include_paths]\n\n        runtime = visual_runtime(self._runtime)\n        if runtime:\n            ret.append(runtime)\n\n        ret.extend(format_defines(self.defines))\n        ret.extend(self.flags)\n        ret.extend(self.cxx_flags)\n\n        if self.parallel:  # Build source in parallel\n            ret.append(parallel_compiler_cl_flag())\n\n        if self.std:\n            ret.append(self.std)\n\n        return ret\n\n    def _get_link_list(self):\n        def format_lib(lib):\n            return lib if lib.endswith('.lib') else '%s.lib' % lib\n\n        ret = [flag for flag in self.link_flags]  # copy\n        ret.extend([format_lib(lib) for lib in self.libs])\n\n        return ret\n\n    @property\n    def vars(self):\n        \"\"\"Used in conanfile with environment_append\"\"\"\n        flags = self._get_cl_list()\n        link_flags = self._get_link_list()\n\n        cl_args = \" \".join(flags) + _environ_value_prefix(\"CL\")\n        link_args = \" \".join(link_flags)\n        lib_paths = \";\".join(['%s' % lib for lib in self.lib_paths]) + _environ_value_prefix(\"LIB\", \";\")\n        return {\"CL\": cl_args,\n                \"LIB\": lib_paths,\n                \"_LINK_\": link_args}\n\n    @property\n    def vars_dict(self):\n        \"\"\"Used in virtualbuildenvironment\"\"\"\n        # Here we do not quote the include paths, it's going to be used by virtual environment\n        cl = self._get_cl_list(quotes=False)\n        link = self._get_link_list()\n\n        lib = [lib for lib in self.lib_paths]  # copy\n\n        if os.environ.get(\"CL\", None):\n            cl.append(os.environ.get(\"CL\"))\n\n        if os.environ.get(\"LIB\", None):\n            lib.append(os.environ.get(\"LIB\"))\n\n        if os.environ.get(\"_LINK_\", None):\n            link.append(os.environ.get(\"_LINK_\"))\n\n        ret = {\"CL\": cl,\n               \"LIB\": lib,\n               \"_LINK_\": link}\n        return ret\n\n    def _std_cpp(self):\n        return vs_std_cpp(self._settings)\n\n\ndef vs_build_type_flags(settings, with_flags=True):\n    build_type = settings.get_safe(\"build_type\")\n    ret = []\n    btd = build_type_define(build_type=build_type)\n    if btd:\n        ret.extend(format_defines([btd]))\n    if with_flags:\n        # When using to build a vs project we don't want to adjust these flags\n        btfs = build_type_flags(\"Visual Studio\", build_type=build_type,\n                                vs_toolset=settings.get_safe(\"compiler.toolset\"))\n        if btfs:\n            ret.extend(btfs)\n\n    return ret\n\n\ndef vs_std_cpp(settings):\n    if settings.get_safe(\"compiler\") == \"Visual Studio\" and \\\n       settings.get_safe(\"cppstd\"):\n        flag = cppstd_flag(settings.get_safe(\"compiler\"),\n                           settings.get_safe(\"compiler.version\"),\n                           settings.get_safe(\"cppstd\"))\n        return flag\n    return None\n\n\ndef _environ_value_prefix(var_name, prefix=\" \"):\n    if os.environ.get(var_name, \"\"):\n        return \"%s%s\" % (prefix, os.environ.get(var_name, \"\"))\n    else:\n        return \"\"\n", "path": "conans/client/build/visual_environment.py"}, {"content": "import copy\nimport re\n\nfrom conans import tools\nfrom conans.client.build.visual_environment import (VisualStudioBuildEnvironment,\n                                                    vs_build_type_flags, vs_std_cpp)\nfrom conans.client.tools.oss import cpu_count\nfrom conans.client.tools.win import vcvars_command\nfrom conans.errors import ConanException\nfrom conans.util.env_reader import get_env\nfrom conans.util.files import tmp_file\nfrom conans.model.conan_file import ConanFile\n\n\nclass MSBuild(object):\n\n    def __init__(self, conanfile):\n        if isinstance(conanfile, ConanFile):\n            self._conanfile = conanfile\n            self._settings = self._conanfile.settings\n            self._output = self._conanfile.output\n            self.build_env = VisualStudioBuildEnvironment(self._conanfile,\n                                                          with_build_type_flags=False)\n        else:  # backwards compatible with build_sln_command\n            self._settings = conanfile\n            self.build_env = None\n\n    def build(self, project_file, targets=None, upgrade_project=True, build_type=None, arch=None,\n              parallel=True, force_vcvars=False, toolset=None, platforms=None, use_env=True,\n              vcvars_ver=None, winsdk_version=None, properties=None):\n\n        self.build_env.parallel = parallel\n\n        with tools.environment_append(self.build_env.vars):\n            # Path for custom properties file\n            props_file_contents = self._get_props_file_contents()\n            with tmp_file(props_file_contents) as props_file_path:\n                vcvars = vcvars_command(self._conanfile.settings, force=force_vcvars,\n                                        vcvars_ver=vcvars_ver, winsdk_version=winsdk_version)\n                command = self.get_command(project_file, props_file_path,\n                                           targets=targets, upgrade_project=upgrade_project,\n                                           build_type=build_type, arch=arch, parallel=parallel,\n                                           toolset=toolset, platforms=platforms,\n                                           use_env=use_env, properties=properties)\n                command = \"%s && %s\" % (vcvars, command)\n                return self._conanfile.run(command)\n\n    def get_command(self, project_file, props_file_path=None, targets=None, upgrade_project=True,\n                    build_type=None, arch=None, parallel=True, toolset=None, platforms=None,\n                    use_env=False, properties=None):\n\n        targets = targets or []\n        properties = properties or {}\n        command = []\n\n        if upgrade_project and not get_env(\"CONAN_SKIP_VS_PROJECTS_UPGRADE\", False):\n            command.append('devenv \"%s\" /upgrade &&' % project_file)\n        else:\n            self._output.info(\"Skipped sln project upgrade\")\n\n        build_type = build_type or self._settings.get_safe(\"build_type\")\n        arch = arch or self._settings.get_safe(\"arch\")\n        if not build_type:\n            raise ConanException(\"Cannot build_sln_command, build_type not defined\")\n        if not arch:\n            raise ConanException(\"Cannot build_sln_command, arch not defined\")\n\n        command.append('msbuild \"%s\" /p:Configuration=\"%s\"' % (project_file, build_type))\n        msvc_arch = {'x86': 'x86',\n                     'x86_64': 'x64',\n                     'armv7': 'ARM',\n                     'armv8': 'ARM64'}\n        if platforms:\n            msvc_arch.update(platforms)\n        msvc_arch = msvc_arch.get(str(arch))\n        try:\n            sln = tools.load(project_file)\n            pattern = re.compile(r\"GlobalSection\\(SolutionConfigurationPlatforms\\)\"\n                                 r\"(.*?)EndGlobalSection\", re.DOTALL)\n            solution_global = pattern.search(sln).group(1)\n            lines = solution_global.splitlines()\n            lines = [s.split(\"=\")[0].strip() for s in lines]\n        except Exception:\n            pass\n        else:\n            config = \"%s|%s\" % (build_type, msvc_arch)\n            if config not in \"\".join(lines):\n                self._output.warn(\"***** The configuration %s does not exist in this solution *****\" % config)\n                self._output.warn(\"Use 'platforms' argument to define your architectures\")\n\n        if use_env:\n            command.append('/p:UseEnv=true')\n\n        if msvc_arch:\n            command.append('/p:Platform=\"%s\"' % msvc_arch)\n\n        if parallel:\n            command.append('/m:%s' % cpu_count())\n\n        if targets:\n            command.append(\"/target:%s\" % \";\".join(targets))\n\n        if toolset:\n            command.append('/p:PlatformToolset=\"%s\"' % toolset)\n\n        if props_file_path:\n            command.append('/p:ForceImportBeforeCppTargets=\"%s\"' % props_file_path)\n\n        for name, value in properties.items():\n            command.append('/p:%s=\"%s\"' % (name, value))\n\n        return \" \".join(command)\n\n    def _get_props_file_contents(self):\n        # how to specify runtime in command line:\n        # https://stackoverflow.com/questions/38840332/msbuild-overrides-properties-while-building-vc-project\n        runtime_library = {\"MT\": \"MultiThreaded\",\n                           \"MTd\": \"MultiThreadedDebug\",\n                           \"MD\": \"MultiThreadedDLL\",\n                           \"MDd\": \"MultiThreadedDebugDLL\"}.get(self._settings.get_safe(\"compiler.runtime\"), \"\")\n\n        if self.build_env:\n            # Take the flags from the build env, the user was able to alter them if needed\n            flags = copy.copy(self.build_env.flags)\n            flags.append(self.build_env.std)\n        else:  # To be removed when build_sln_command is deprecated\n            flags = vs_build_type_flags(self._settings, with_flags=False)\n            flags.append(vs_std_cpp(self._settings))\n\n        flags_str = \" \".join(list(filter(None, flags))) # Removes empty and None elements\n        additional_node = \"<AdditionalOptions>\" \\\n                          \"{} %(AdditionalOptions)\" \\\n                          \"</AdditionalOptions>\".format(flags_str) if flags_str else \"\"\n        runtime_node = \"<RuntimeLibrary>\" \\\n                       \"{}\" \\\n                       \"</RuntimeLibrary>\".format(runtime_library) if runtime_library else \"\"\n        template = \"\"\"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemDefinitionGroup>\n    <ClCompile>\n      {runtime_node}\n      {additional_node}\n    </ClCompile>\n  </ItemDefinitionGroup>\n</Project>\"\"\".format(**{\"runtime_node\": runtime_node,\n                        \"additional_node\": additional_node})\n        return template\n", "path": "conans/client/build/msbuild.py"}]}