Repository: conan-io/conan

Issue:
[question] How to not include some libs in conanbuildinfo.props
Conan version 1.19.0

I have a dependency on boost (boost/1.71.0@conan/stable).

I'm using the visual_studio generator with VS2017

This adds *all* of the boost libs to conanbuildinfo.props which causes my build to fail.  I don't completely understand why this used to be OK with 1.68 and now fails with that too after moving my cache to a different drive (perhaps it was due to installing vs2019 alongside vs2017). 

But regardless it would be good if I could either cherrypick which libs to include or remove specific ones from the list.

For example I don't want to include any of the stacktrace libs which result in duplicate symbols.

I can't figure out how to do it.  If I specify any of the 'without_xxx' options then it rebuilds the whole of the boost dependency which I would rather avoid - I just want to control which libs it puts in the vs props file!

I was trying to see if there was some place I could remove them from deps_cpp_info but it doesn't look like there is a place to put that (i.e. an event just before the generators are run).

Perhaps overriding the generator could do the trick but it seems like that would be a bit of a sledgehammer and not all that clean.





Discussion:

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
@@ -18,13 +18,15 @@ class VisualStudioGenerator(Generator):
   <ItemGroup />
 </Project>'''
 
-    properties_template = '''  <PropertyGroup Label="ConanVariables"{condition}>
+    properties_template = '''<PropertyGroup Label="ConanVariables"{condition}>
     <ConanCompilerFlags>{compiler_flags}</ConanCompilerFlags>
+    <ConanLinkerFlags>{linker_flags}</ConanLinkerFlags>
     <ConanPreprocessorDefinitions>{definitions}</ConanPreprocessorDefinitions>
     <ConanIncludeDirectories>{include_dirs}</ConanIncludeDirectories>
     <ConanResourceDirectories>{res_dirs}</ConanResourceDirectories>
     <ConanLibraryDirectories>{lib_dirs}</ConanLibraryDirectories>
     <ConanBinaryDirectories>{bin_dirs}</ConanBinaryDirectories>
+    <ConanLibraries>{libs}</ConanLibraries>
   </PropertyGroup>
   <PropertyGroup{condition}>
     <LocalDebuggerEnvironment>PATH=%PATH%;{bin_dirs}</LocalDebuggerEnvironment>
@@ -38,13 +40,9 @@ class VisualStudioGenerator(Generator):
     </ClCompile>
     <Link>
       <AdditionalLibraryDirectories>$(ConanLibraryDirectories)%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
-      <AdditionalDependencies>{libs}%(AdditionalDependencies)</AdditionalDependencies>
-      <AdditionalOptions>{linker_flags} %(AdditionalOptions)</AdditionalOptions>
+      <AdditionalDependencies>$(ConanLibraries)%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalOptions>$(ConanLinkerFlags) %(AdditionalOptions)</AdditionalOptions>
     </Link>
-    <Lib>
-      <AdditionalLibraryDirectories>$(ConanLibraryDirectories)%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
-      <AdditionalDependencies>{libs}%(AdditionalDependencies)</AdditionalDependencies>
-    </Lib>
     <Midl>
       <AdditionalIncludeDirectories>$(ConanIncludeDirectories)%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
     </Midl>


Test patch:
diff --git a/conans/test/functional/generators/visual_studio_test.py b/conans/test/functional/generators/visual_studio_test.py
--- a/conans/test/functional/generators/visual_studio_test.py
+++ b/conans/test/functional/generators/visual_studio_test.py
@@ -84,11 +84,11 @@ def build(self):
         files["MyProject/main.cpp"] = main_cpp
         files["conanfile.py"] = consumer
         props = os.path.join(client.current_folder, "conanbuildinfo.props")
-        old = '<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />'
+        old = r'<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />'
         new = old + '<Import Project="{props}" />'.format(props=props)
         files["MyProject/MyProject.vcxproj"] = files["MyProject/MyProject.vcxproj"].replace(old, new)
         client.save(files, clean_first=True)
         client.run("install .")
         client.run("build .")
-        client.run_command("x64\Release\MyProject.exe")
+        client.run_command(r"x64\Release\MyProject.exe")
         self.assertIn("Hello world!!!", client.out)
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
@@ -3,18 +3,13 @@
 import unittest
 
 from conans.model.graph_info import GRAPH_INFO_FILE
+from conans.model.graph_lock import LOCKFILE
 from conans.model.ref import ConanFileReference, PackageReference
 from conans.paths import (BUILD_INFO, BUILD_INFO_CMAKE, BUILD_INFO_GCC, BUILD_INFO_VISUAL_STUDIO,
                           BUILD_INFO_XCODE, CONANFILE_TXT, CONANINFO)
 from conans.test.utils.tools import TestClient
 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):
 
@@ -75,6 +70,9 @@ def package_info(self):
         compiler = definition_group.getElementsByTagName("ClCompile")[0]
         linker = definition_group.getElementsByTagName("Link")[0]
 
+        def element_content(node):
+            return node.firstChild.data if node.firstChild else ""
+
         include_dirs = element_content(xmldoc.getElementsByTagName("ConanIncludeDirectories")[0])
         definitions = element_content(xmldoc.getElementsByTagName("ConanPreprocessorDefinitions")[0])
         lib_dirs = element_content(xmldoc.getElementsByTagName("ConanLibraryDirectories")[0])
@@ -90,7 +88,7 @@ def package_info(self):
         expected_include_dirs = os.path.join(replaced_path, "include")
 
         self.assertIn(expected_lib_dirs, lib_dirs)
-        self.assertEqual("hello.lib;%(AdditionalDependencies)", libs)
+        self.assertEqual("$(ConanLibraries)%(AdditionalDependencies)", libs)
         self.assertEqual("", definitions)
         self.assertIn(expected_include_dirs, include_dirs)
 
diff --git a/conans/test/unittests/client/generators/visual_studio_multi_test.py b/conans/test/unittests/client/generators/visual_studio_multi_test.py
--- a/conans/test/unittests/client/generators/visual_studio_multi_test.py
+++ b/conans/test/unittests/client/generators/visual_studio_multi_test.py
@@ -117,9 +117,11 @@ def validate_additional_dependencies(libname, additional_dep):
                 self.assertIn('conanbuildinfo_release_x64_v141.props', content.keys())
 
                 content_release = content['conanbuildinfo_release_x64_v141.props']
+                self.assertIn("<ConanLibraries>%s;</ConanLibraries>" % additional_dep,
+                              content_release)
                 self.assertIn("<AdditionalDependencies>"
-                              "{};%(AdditionalDependencies)"
-                              "</AdditionalDependencies>".format(additional_dep), content_release)
+                              "$(ConanLibraries)%(AdditionalDependencies)"
+                              "</AdditionalDependencies>", content_release)
 
         # regular
         validate_additional_dependencies("foobar", "foobar.lib")
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
@@ -122,9 +122,11 @@ def validate_additional_dependencies(lib, additional_dep):
             cpp_info.libs = [lib]
             conanfile.deps_cpp_info.update(cpp_info, ref.name)
             generator = VisualStudioGenerator(conanfile)
+            content = generator.content
+            self.assertIn("<ConanLibraries>%s;</ConanLibraries>" % additional_dep, content)
             self.assertIn("<AdditionalDependencies>"
-                          "{};%(AdditionalDependencies)"
-                          "</AdditionalDependencies>".format(additional_dep), generator.content)
+                          "$(ConanLibraries)%(AdditionalDependencies)"
+                          "</AdditionalDependencies>", content)
 
         # regular
         validate_additional_dependencies("foobar", "foobar.lib")