Repository: conan-io/conan

Issue:
MSBuild helper useEnv option causes missing include paths in some casess
In using MSBuild helper for the first time, I received a number of errors about headers that could not be found. After spending significant time validating that the project works normally when running msbuild manually, I determined that the breaking flag was `/useEnv:True`.  

I briefly looked at the implementation and it was not immediately obvious to me where the problem might be.  I have worked around it by using the `get_command` method from the MSBuild helper, which returns a command where the default of `useEnv` is  `False`. 

It's mysterious why it causes this problem, but if everything is correct, then the requested change would be to simply expose `useEnv` as a parameter in the `build` method of the `MSBuild` helper rather than forcing it to `True`.

I will try to provide a way to reproduce the error, but it's a private project and I don't know if I have time to isolate the problem any time soon. I spent to much time just identifying it. 

- [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.
- [] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.




Discussion:

Resolving patch:
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
@@ -24,7 +24,7 @@ def __init__(self, conanfile):
             self.build_env = None
 
     def build(self, project_file, targets=None, upgrade_project=True, build_type=None, arch=None,
-              parallel=True, force_vcvars=False, toolset=None, platforms=None):
+              parallel=True, force_vcvars=False, toolset=None, platforms=None, use_env=True):
         with tools.environment_append(self.build_env.vars):
             # Path for custom properties file
             props_file_contents = self._get_props_file_contents()
@@ -34,7 +34,7 @@ def build(self, project_file, targets=None, upgrade_project=True, build_type=Non
                                            targets=targets, upgrade_project=upgrade_project,
                                            build_type=build_type, arch=arch, parallel=parallel,
                                            toolset=toolset, platforms=platforms,
-                                           use_env=True)
+                                           use_env=use_env)
                 command = "%s && %s" % (vcvars, command)
                 return self._conanfile.run(command)
 
@@ -43,10 +43,10 @@ def get_command(self, project_file, props_file_path=None, targets=None, upgrade_
                     use_env=False):
 
         targets = targets or []
-        command = ""
+        command = []
 
         if upgrade_project and not get_env("CONAN_SKIP_VS_PROJECTS_UPGRADE", False):
-            command += "devenv %s /upgrade && " % project_file
+            command.append("devenv %s /upgrade &&" % project_file)
         else:
             self._output.info("Skipped sln project upgrade")
 
@@ -57,9 +57,7 @@ def get_command(self, project_file, props_file_path=None, targets=None, upgrade_
         if not arch:
             raise ConanException("Cannot build_sln_command, arch not defined")
 
-
-
-        command += "msbuild %s /p:Configuration=%s" % (project_file, build_type)
+        command.append("msbuild %s /p:Configuration=%s" % (project_file, build_type))
         msvc_arch = {'x86': 'x86',
                      'x86_64': 'x64',
                      'armv7': 'ARM',
@@ -83,24 +81,24 @@ def get_command(self, project_file, props_file_path=None, targets=None, upgrade_
                 self._output.warn("Use 'platforms' argument to define your architectures")
 
         if use_env:
-            command += ' /p:UseEnv=true'
+            command.append('/p:UseEnv=true')
 
         if msvc_arch:
-            command += ' /p:Platform="%s"' % msvc_arch
+            command.append('/p:Platform="%s"' % msvc_arch)
 
         if parallel:
-            command += ' /m:%s' % cpu_count()
+            command.append('/m:%s' % cpu_count())
 
         if targets:
-            command += " /target:%s" % ";".join(targets)
+            command.append("/target:%s" % ";".join(targets))
 
         if toolset:
-            command += " /p:PlatformToolset=%s" % toolset
+            command.append("/p:PlatformToolset=%s" % toolset)
 
         if props_file_path:
-            command += ' /p:ForceImportBeforeCppTargets="%s"' % props_file_path
+            command.append('/p:ForceImportBeforeCppTargets="%s"' % props_file_path)
 
-        return command
+        return " ".join(command)
 
     def _get_props_file_contents(self):
         # how to specify runtime in command line:


Test patch: