Repository: conan-io/conan

Issue:
VS generator not exporting for <Lib> tag in vcxproj
Need to add Conan-handled lib to be referenced in .vcxproj in <Lib> tags. Conan VS-generator is exporting only in <Link> tag. 



Discussion:
Hi, @kucerad 

I need you to provide an example or more information on this issue, I don't know what you mean by `tags` in relation to `.vcxproj` files.

Thanks

Resolving patch:
diff --git a/conans/client/generators/visualstudio.py b/conans/client/generators/visualstudio.py
--- a/conans/client/generators/visualstudio.py
+++ b/conans/client/generators/visualstudio.py
@@ -19,8 +19,12 @@ class VisualStudioGenerator(Generator):
 </Project>'''
 
     properties_template = '''  <PropertyGroup Label="ConanVariables"{condition}>
-    <ConanBinaryDirectories>{bin_dirs};%(ConanBinaryDirectories)</ConanBinaryDirectories>
-    <ConanResourceDirectories>{res_dirs};%(ConanResourceDirectories)$(</ConanResourceDirectories>
+    <ConanCompilerFlags>{compiler_flags}</ConanCompilerFlags>
+    <ConanPreprocessorDefinitions>{definitions}</ConanPreprocessorDefinitions>
+    <ConanIncludeDirectories>{include_dirs}</ConanIncludeDirectories>
+    <ConanResourceDirectories>{res_dirs}</ConanResourceDirectories>
+    <ConanLibraryDirectories>{lib_dirs}</ConanLibraryDirectories>
+    <ConanBinaryDirectories>{bin_dirs}</ConanBinaryDirectories>
   </PropertyGroup>
   <PropertyGroup{condition}>
     <LocalDebuggerEnvironment>PATH=%PATH%;{bin_dirs}</LocalDebuggerEnvironment>
@@ -28,22 +32,26 @@ class VisualStudioGenerator(Generator):
   </PropertyGroup>
   <ItemDefinitionGroup{condition}>
     <ClCompile>
-      <AdditionalIncludeDirectories>{include_dirs}%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>{definitions}%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalOptions>{compiler_flags} %(AdditionalOptions)</AdditionalOptions>
+      <AdditionalIncludeDirectories>$(ConanIncludeDirectories)%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>$(ConanPreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalOptions>$(ConanCompilerFlags) %(AdditionalOptions)</AdditionalOptions>
     </ClCompile>
     <Link>
-      <AdditionalLibraryDirectories>{lib_dirs}%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <AdditionalLibraryDirectories>$(ConanLibraryDirectories)%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
       <AdditionalDependencies>{libs}%(AdditionalDependencies)</AdditionalDependencies>
       <AdditionalOptions>{linker_flags} %(AdditionalOptions)</AdditionalOptions>
     </Link>
+    <Lib>
+      <AdditionalLibraryDirectories>$(ConanLibraryDirectories)%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
+      <AdditionalDependencies>{libs}%(AdditionalDependencies)</AdditionalDependencies>
+    </Lib>
     <Midl>
-      <AdditionalIncludeDirectories>{include_dirs}%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(ConanIncludeDirectories)%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </Midl>
     <ResourceCompile>
-      <AdditionalIncludeDirectories>{include_dirs}%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <PreprocessorDefinitions>{definitions}%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <AdditionalOptions>{compiler_flags} %(AdditionalOptions)</AdditionalOptions>
+      <AdditionalIncludeDirectories>$(ConanIncludeDirectories)%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>$(ConanPreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <AdditionalOptions>$(ConanCompilerFlags) %(AdditionalOptions)</AdditionalOptions>
     </ResourceCompile>
   </ItemDefinitionGroup>'''
 


Test patch:
diff --git a/conans/test/functional/generators/xcode_gcc_vs_test.py b/conans/test/functional/generators/xcode_gcc_vs_test.py
--- a/conans/test/functional/generators/xcode_gcc_vs_test.py
+++ b/conans/test/functional/generators/xcode_gcc_vs_test.py
@@ -10,6 +10,11 @@
 from conans.util.files import load
 from conans.model.graph_lock import LOCKFILE
 
+def element_content(node):
+    if node.firstChild:
+        return node.firstChild.data
+    else:
+        return ""
 
 class VSXCodeGeneratorsTest(unittest.TestCase):
 
@@ -68,14 +73,12 @@ def package_info(self):
         xmldoc = minidom.parse(os.path.join(client.current_folder, BUILD_INFO_VISUAL_STUDIO))
         definition_group = xmldoc.getElementsByTagName('ItemDefinitionGroup')[0]
         compiler = definition_group.getElementsByTagName("ClCompile")[0]
-
-        elem = compiler.getElementsByTagName("AdditionalIncludeDirectories")
-        include_dirs = elem[0].firstChild.data
-        definitions = compiler.getElementsByTagName("PreprocessorDefinitions")[0].firstChild.data
-
         linker = definition_group.getElementsByTagName("Link")[0]
-        lib_dirs = linker.getElementsByTagName("AdditionalLibraryDirectories")[0].firstChild.data
-        libs = linker.getElementsByTagName("AdditionalDependencies")[0].firstChild.data
+
+        include_dirs = element_content(xmldoc.getElementsByTagName("ConanIncludeDirectories")[0])
+        definitions = element_content(xmldoc.getElementsByTagName("ConanPreprocessorDefinitions")[0])
+        lib_dirs = element_content(xmldoc.getElementsByTagName("ConanLibraryDirectories")[0])
+        libs = element_content(linker.getElementsByTagName("AdditionalDependencies")[0])
 
         package_id = os.listdir(client.cache.package_layout(ref).packages())[0]
         pref = PackageReference(ref, package_id)
@@ -88,7 +91,7 @@ def package_info(self):
 
         self.assertIn(expected_lib_dirs, lib_dirs)
         self.assertEqual("hello.lib;%(AdditionalDependencies)", libs)
-        self.assertEqual("%(PreprocessorDefinitions)", definitions)
+        self.assertEqual("", definitions)
         self.assertIn(expected_include_dirs, include_dirs)
 
         # CHECK XCODE GENERATOR
diff --git a/conans/test/unittests/client/generators/visual_studio_test.py b/conans/test/unittests/client/generators/visual_studio_test.py
--- a/conans/test/unittests/client/generators/visual_studio_test.py
+++ b/conans/test/unittests/client/generators/visual_studio_test.py
@@ -55,16 +55,20 @@ def user_profile_test(self):
 
         path1 = os.path.join("$(USERPROFILE)", "pkg1", "include")
         path2 = os.path.join("$(USERPROFILE)", "pkg2", "include")
-        expected = "<AdditionalIncludeDirectories>%s;%s;" % (path1, path2)
+        expected1 = "<ConanIncludeDirectories>%s;%s;" % (path1, path2)
+        expected2 = "<AdditionalIncludeDirectories>$(ConanIncludeDirectories)%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>"
+
         with tools.environment_append({"USERPROFILE": tmp_folder}):
             content = generator.content
             xml.etree.ElementTree.fromstring(content)
-            self.assertIn(expected, content)
+            self.assertIn(expected1, content)
+            self.assertIn(expected2, content)
 
         with tools.environment_append({"USERPROFILE": tmp_folder.upper()}):
             content = generator.content
             xml.etree.ElementTree.fromstring(content)
-            self.assertIn(expected, content)
+            self.assertIn(expected1, content)
+            self.assertIn(expected2, content)
 
     def multi_config_test(self):
         tmp_folder = temp_folder()
@@ -81,22 +85,25 @@ def multi_config_test(self):
 
         content = generator.content
 
-        defines_common = "<PreprocessorDefinitions>" \
-                         "_WIN32_WINNT=x0501;%(PreprocessorDefinitions)" \
-                         "</PreprocessorDefinitions>"
-        defines_debug = "<PreprocessorDefinitions>" \
-                        "_DEBUG;DEBUG;%(PreprocessorDefinitions)" \
-                        "</PreprocessorDefinitions>"
-        defines_release = "<PreprocessorDefinitions>" \
-                          "NDEBUG;%(PreprocessorDefinitions)" \
-                          "</PreprocessorDefinitions>"
-        defines_custom = "<PreprocessorDefinitions>" \
-                         "CUSTOM_BUILD;%(PreprocessorDefinitions)" \
-                         "</PreprocessorDefinitions>"
+        defines_common = "<ConanPreprocessorDefinitions>" \
+                         "_WIN32_WINNT=x0501;" \
+                         "</ConanPreprocessorDefinitions>"
+        defines_debug = "<ConanPreprocessorDefinitions>" \
+                        "_DEBUG;DEBUG;" \
+                        "</ConanPreprocessorDefinitions>"
+        defines_release = "<ConanPreprocessorDefinitions>" \
+                          "NDEBUG;" \
+                          "</ConanPreprocessorDefinitions>"
+        defines_custom = "<ConanPreprocessorDefinitions>" \
+                         "CUSTOM_BUILD;" \
+                         "</ConanPreprocessorDefinitions>"
+        defines_always = "<PreprocessorDefinitions>$(ConanPreprocessorDefinitions)%(PreprocessorDefinitions)</PreprocessorDefinitions>"
+
         self.assertIn(defines_common, content)
         self.assertIn(defines_debug, content)
         self.assertIn(defines_release, content)
         self.assertIn(defines_custom, content)
+        self.assertIn(defines_always, content)
 
         condition_debug = "<ItemDefinitionGroup Condition=\"'$(Configuration)' == 'debug'\">"
         condition_release = "<ItemDefinitionGroup Condition=\"'$(Configuration)' == 'release'\">"