Repository: conan-io/conan

Issue:
[feature] Add armv8 support to MSBuildDeps generator
Map `armv8` arch to MSBuild `ARM64` platform

PR to follow.

- [x] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).

Passing  `-g MSBuildDeps -s arch=armv8` to `conan install` results in errors of the form:

```log
conanfile.txt: ERROR: Traceback (most recent call last):
  File "xxx\venv\lib\site-packages\conans\client\generators\__init__.py", line 177, in write_generators
    generator.generate()
  File "xxx\venv\lib\site-packages\conan\tools\microsoft\msbuilddeps.py", line 128, in generate
    raise ConanException("MSBuildDeps.platform is None, it should have a value")
conans.errors.ConanException: MSBuildDeps.platform is None, it should have a value

ERROR: Error in generator 'MSBuildDeps': MSBuildDeps.platform is None, it should have a value
```



Discussion:

Resolving patch:
diff --git a/conan/tools/microsoft/msbuilddeps.py b/conan/tools/microsoft/msbuilddeps.py
--- a/conan/tools/microsoft/msbuilddeps.py
+++ b/conan/tools/microsoft/msbuilddeps.py
@@ -86,8 +86,12 @@ class MSBuildDeps(object):
     def __init__(self, conanfile):
         self._conanfile = conanfile
         self.configuration = conanfile.settings.build_type
+        # TODO: This platform is not exactly the same as ``msbuild_arch``, because it differs
+        # in x86=>Win32
         self.platform = {'x86': 'Win32',
-                         'x86_64': 'x64'}.get(str(conanfile.settings.arch))
+                         'x86_64': 'x64',
+                         'armv7': 'ARM',
+                         'armv8': 'ARM64'}.get(str(conanfile.settings.arch))
         ca_exclude = "tools.microsoft.msbuilddeps:exclude_code_analysis"
         self.exclude_code_analysis = self._conanfile.conf.get(ca_exclude, check_type=list)
         check_using_build_profile(self._conanfile)
diff --git a/conan/tools/microsoft/toolchain.py b/conan/tools/microsoft/toolchain.py
--- a/conan/tools/microsoft/toolchain.py
+++ b/conan/tools/microsoft/toolchain.py
@@ -55,9 +55,12 @@ def __init__(self, conanfile):
 
     def _name_condition(self, settings):
         props = [("Configuration", self.configuration),
-                 # FIXME: This probably requires mapping ARM architectures
+                 # TODO: refactor, put in common with MSBuildDeps. Beware this is != msbuild_arch
+                 #  because of Win32
                  ("Platform", {'x86': 'Win32',
-                               'x86_64': 'x64'}.get(settings.get_safe("arch")))]
+                               'x86_64': 'x64',
+                               'armv7': 'ARM',
+                               'armv8': 'ARM64'}.get(settings.get_safe("arch")))]
 
         name = "".join("_%s" % v for _, v in props if v is not None)
         condition = " And ".join("'$(%s)' == '%s'" % (k, v) for k, v in props if v is not None)


Test patch:
diff --git a/conans/test/integration/toolchains/microsoft/test_msbuilddeps.py b/conans/test/integration/toolchains/microsoft/test_msbuilddeps.py
new file mode 100644
--- /dev/null
+++ b/conans/test/integration/toolchains/microsoft/test_msbuilddeps.py
@@ -0,0 +1,23 @@
+import os
+
+import pytest
+
+from conans.test.utils.tools import TestClient
+
+
+@pytest.mark.parametrize(
+    "arch,exp_platform",
+    [
+        ("x86", "Win32"),
+        ("x86_64", "x64"),
+        ("armv7", "ARM"),
+        ("armv8", "ARM64"),
+    ],
+)
+def test_msbuilddeps_maps_architecture_to_platform(arch, exp_platform):
+    client = TestClient(path_with_spaces=False)
+    client.run("new hello/0.1 --template=msbuild_lib")
+    client.run(f"install . -g MSBuildDeps -s arch={arch} -pr:b=default -if=install")
+    toolchain = client.load(os.path.join("conan", "conantoolchain.props"))
+    expected_import = f"""<Import Condition="'$(Configuration)' == 'Release' And '$(Platform)' == '{exp_platform}'" Project="conantoolchain_release_{exp_platform.lower()}.props"/>"""
+    assert expected_import in toolchain