Repository: conan-io/conan

Issue:
Regression in MSBuild helper properties injection
Unfortunately, in #4113 we have missed the fact the `ForceImportBeforeCppTargets` parameter requires an absolute path to the properties files to be injected.


Discussion:
If this is a regression and it breaks badly MSBuild projects, it should be fixed in conan 1.12.2.

I have had a look, didn't understand why the test in https://github.com/conan-io/conan/pull/4113/files was not failing.
@memsharded 
Because it doesn't test the `ForceImportBeforeCppTargets`. Configuration and arch are handled by other MSBuild parameters. To make a correct test one should test a different Runtime.
This is true, this is a regression and will be fixed in Conan 1.12.2 asap.

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
@@ -73,9 +73,11 @@ def build(self, project_file, targets=None, upgrade_project=True, build_type=Non
         with tools.environment_append(self.build_env.vars):
             # Path for custom properties file
             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_ver=vcvars_ver, winsdk_version=winsdk_version)
+                                    vcvars_ver=vcvars_ver, winsdk_version=winsdk_version,
+                                    output=self._output)
             command = self.get_command(project_file, property_file_name,
                                        targets=targets, upgrade_project=upgrade_project,
                                        build_type=build_type, arch=arch, parallel=parallel,
@@ -160,7 +162,8 @@ def get_command(self, project_file, props_file_path=None, targets=None, upgrade_
             command.append('/verbosity:%s' % verbosity)
 
         if props_file_path:
-            command.append('/p:ForceImportBeforeCppTargets="%s"' % props_file_path)
+            command.append('/p:ForceImportBeforeCppTargets="%s"'
+                           % os.path.abspath(props_file_path))
 
         for name, value in properties.items():
             command.append('/p:%s="%s"' % (name, value))


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
@@ -1,7 +1,8 @@
+import mock
+import os
 import platform
+import re
 import unittest
-
-import mock
 from parameterized import parameterized
 
 from conans.client.build.msbuild import MSBuild
@@ -131,17 +132,6 @@ def get_version_test(self):
         self.assertRegexpMatches(version, "(\d+\.){2,3}\d+")
         self.assertGreater(version, "15.1")
 
-    def custom_properties_test(self):
-        settings = MockSettings({"build_type": "Debug",
-                                 "compiler": "Visual Studio",
-                                 "arch": "x86_64"})
-        conanfile = MockConanfile(settings)
-        msbuild = MSBuild(conanfile)
-        command = msbuild.get_command("project_should_flags_test_file.sln",
-                                      properties={"MyProp1": "MyValue1", "MyProp2": "MyValue2"})
-        self.assertIn('/p:MyProp1="MyValue1"', command)
-        self.assertIn('/p:MyProp2="MyValue2"', command)
-
     @parameterized.expand([("15", "v141"),
                            ("14", "v140"),
                            ("12", "v120"),
@@ -246,3 +236,19 @@ def verbosity_explicit_test(self):
         command = msbuild.get_command("projecshould_flags_testt_file.sln", verbosity="quiet")
         self.assertIn('/verbosity:quiet', command)
 
+    def properties_injection_test(self):
+        # https://github.com/conan-io/conan/issues/4471
+        settings = MockSettings({"build_type": "Debug",
+                                 "compiler": "Visual Studio",
+                                 "arch": "x86_64"})
+        conanfile = MockConanfile(settings)
+        msbuild = MSBuild(conanfile)
+        command = msbuild.get_command("dummy.sln", props_file_path="conan_build.props")
+
+        match = re.search('/p:ForceImportBeforeCppTargets="(.+?)"', command)
+        self.assertTrue(
+            match, "Haven't been able to find the ForceImportBeforeCppTargets")
+
+        props_file_path = match.group(1)
+        self.assertTrue(os.path.isabs(props_file_path))
+        self.assertEquals(os.path.basename(props_file_path), "conan_build.props")