Repository: conan-io/conan

Issue:
[feature] Propagate arch argument to vcvars in MSBuild helper
Coming from https://github.com/conan-io/conan-center-index/pull/719#discussion_r390337460

There is an arch override parameter in ``MSBuild.build()`` method, however, this is not propagated to the ``vcvars_command`` inside that same method. So the override in some cases is useless.

I think the arch argument should be propagated to the vcvars as well.

Related to #6428


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
@@ -83,7 +83,7 @@ def build(self, project_file, targets=None, upgrade_project=True, build_type=Non
             props_file_contents = self._get_props_file_contents(definitions)
             property_file_name = os.path.abspath(property_file_name)
             save(property_file_name, props_file_contents)
-            vcvars = vcvars_command(self._conanfile.settings, force=force_vcvars,
+            vcvars = vcvars_command(self._conanfile.settings, arch=arch, force=force_vcvars,
                                     vcvars_ver=vcvars_ver, winsdk_version=winsdk_version,
                                     output=self._output)
             command = self.get_command(project_file, property_file_name,


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
@@ -12,7 +12,8 @@
 from conans.client.build.msbuild import MSBuild
 from conans.errors import ConanException
 from conans.model.version import Version
-from conans.test.utils.conanfile import MockConanfile, MockSettings
+from conans.test.utils.conanfile import MockConanfile, MockSettings, ConanFileMock
+from conans.test.utils.test_files import temp_folder
 
 
 class MSBuildTest(unittest.TestCase):
@@ -317,3 +318,23 @@ def windows_ce_test(self):
         msbuild = MSBuild(conanfile)
         command = msbuild.get_command("test.sln")
         self.assertIn('/p:Platform="YOUR PLATFORM SDK (ARMV4)"', command)
+
+    @unittest.skipUnless(platform.system() == "Windows", "Requires Visual Studio installation path")
+    def test_arch_override(self):
+        settings = MockSettings({"build_type": "Release",
+                                 "compiler": "Visual Studio",
+                                 "compiler.version": "15",
+                                 "compiler.runtime": "MDd",
+                                 "os": "Windows",
+                                 "arch": "x86_64"})
+        conanfile = ConanFileMock()
+        conanfile.settings = settings
+        props_file_path = os.path.join(temp_folder(), "conan_build.props")
+
+        msbuild = MSBuild(conanfile)
+        msbuild.build("project_file.sln", property_file_name=props_file_path)
+        self.assertIn("vcvarsall.bat\" amd64", conanfile.command)
+        self.assertIn("/p:Platform=\"x64\"", conanfile.command)
+        msbuild.build("project_file.sln", arch="x86", property_file_name=props_file_path)
+        self.assertIn("vcvarsall.bat\" x86", conanfile.command)
+        self.assertIn("/p:Platform=\"x86\"", conanfile.command)