5

This answer mentions the following method to link to the static version of a C++ library [in this case, "freeglut"] installed via Nuget:

Project->Properties->Configuration Properties->Referenced Packages->freeglut->Linkage (select static) 

With Visual Studio 2015 I can't find "Referenced Packages". The only explicit reference to Nuget packages that I have is the packages.config xml file. If I go to the "Manage Nuget packages" section of the project I can install or un-install but I can't find any detail of the package.

I have searched msdn for documentation but all the pages are devoted to the creation of a package, while I need to espress the way to consume such a package. The package in question (Boost Unit Test Framework) can be used header-only, with static or with dynamic linkage and I would like to know where I can decide it.

Maybe I am getting old, but Nuget is a bit too magic for me...

UPDATE

This is what I am seeing - you can see that there are Nuget packages installed, in particular boost, but that under the Configuration properties there is no link to "Referenced packages": screenshot of Nuget installed packages and of the Configuration Properties without a link to "Referenced Packages

For completeness, the version of VS 2015 Enterprise is:

14.0.25431.01 Update 3

and I have checked that when I installed the Boost Test Package I got both the static (.lib) and dynamic (.dll) linkage versions, since the files for my VS version are present in the packages folder.

Francesco
  • 3,200
  • 1
  • 34
  • 46

2 Answers2

2

With Visual Studio 2015 I can't find "Referenced Packages".

It depends on whether you have installed freeglut package into your project. If you create a C++ project without any NuGet package installed, you could not find the "Referenced Packages":

enter image description here

After installed the nuget package "freeglut", the "Referenced Packages" and "Project Master Settings" would add to the Configuration Properties:

enter image description here

Update for Boost Package: You should install the package freeglut to check the "Referenced Packages" and "Project Master Settings". Since you noticed the different behavior between the package freeglutand Boost, I would like provide more about Native NuGet packages. After installed the freeglut and Boost in to your project, you can find the freeglut.targets and boost.targets in the packages folder(..\packages\freeglut.2.8.1.15\build\native & packages\boost.1.64.0.0\build\native), open them with notepad or VS, you will noticed that:

In freeglut.targets:

<PropertyGroup Label="Debug and static and RuntimeLibraryNull" Condition="( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 ) And '$(Linkage-freeglut.ToLower())' == 'static' And ('$(RuntimeLibrary)' == '')">
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
 </PropertyGroup>
 <PropertyGroup Label="Release and static and RuntimeLibraryNull" Condition="( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And '$(Linkage-freeglut.ToLower())' == 'static' And ('$(RuntimeLibrary)' == '')">
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</PropertyGroup>
<PropertyGroup Label="Debug and ltcg and RuntimeLibraryNull" Condition="( $(Configuration.ToLower().IndexOf('debug')) &gt; -1 ) And '$(Linkage-freeglut.ToLower())' == 'ltcg' And ('$(RuntimeLibrary)' == '')">
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
</PropertyGroup>
<PropertyGroup Label="Release and ltcg and RuntimeLibraryNull" Condition="( $(Configuration.ToLower().IndexOf('debug')) == -1 ) And '$(Linkage-freeglut.ToLower())' == 'ltcg' And ('$(RuntimeLibrary)' == '')">
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</PropertyGroup>

This will add the options "Referenced Packages" and "Project Master Settings" via PropertyGroup in to the C++ properties.

But in the boost.targets file, only:

   <ItemDefinitionGroup>
    <ClCompile>
      <PreprocessorDefinitions>;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\lib\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>
  </ItemDefinitionGroup>

So whether the "Referenced Packages" and "Project Master Settings" will be added is based on the .targets file in the package`s folder.

If I go to the "Manage Nuget packages" section of the project I can install or un-install but I can't find any detail of the package.

On the right of the "Manage Nuget packages" section of the project, you can notice some more detail Description:

enter image description here

I have searched msdn for documentation but all the pages are devoted to the creation of a package, while I need to espress the way to consume such a package.

You can refer to the document Consume Packages for how to consume a package.

The package in question (Boost Unit Test Framework) can be used header-only, with static or with dynamic linkage and I would like to know where I can decide it.

You can decide it on the Project->Properties->Configuration Properties->Referenced Packages->freeglut:

enter image description here

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • 1
    That is missing from my Properties. I have General, Debugging, VC++ Directories. I don't have "Project Master Settings" and "Referenced Packages". If I go to Manage Nuget Packages, it results that Boost is installed (and, in fact, I am using its headers). – Francesco Aug 21 '17 at 07:30
  • I added a screenshot for better clarity – Francesco Aug 21 '17 at 07:39
  • @Francesco, I'm sorry not to provide you with a detailed answer, because I afraid too much information will bring you troubled. Since your update question involves more info, I have updated my answer with more detail info, you can check the Update for Boost Package for detail. – Leo Liu Aug 21 '17 at 08:25
  • actually the update info is very useful: it appears that the boost package is "different" (in its .targets) from the freeglut example and so I don't find the section. Why do you say "troubles"? more information is welcome! Is there a link on MSDN about this target so that maybe I can modify it myself. – Francesco Aug 21 '17 at 08:31
  • 1
    @Francesco, Sorry, I also don`t know that link on MSDN :( . If possilbe, hope you can get some help from:https://hmemcpy.com/2015/03/adding-a-custom-property-page-to-existing-project-types-in-visual-studio/ and https://msdn.microsoft.com/en-us/library/669zx6zc.aspx – Leo Liu Aug 21 '17 at 09:17
  • Thanks. In the meanwhile I opened an issue on github wrt this topic: https://github.com/sergey-shandar/getboost/issues/34 – Francesco Aug 21 '17 at 09:19
2

Boost is using auto-linking. It means, the Boost source code decides which library (file) to use depending on build environment and configuration.

Update Here's the process

  1. You add the Boost headers only NuGet package to your project.
  2. Depending on what are you using and build configuration, Boost may require additional libraries (lib files). In this case, you will receive a compilation/linking error.
  3. Depending on the compilation/linking error, you add to your project additional NuGet packages with precompiled Boost libraries from here

I agree, the process is not obvious. To improve it, Boost should finalize their modularization first. I mean, when Boost libraries (headers and binaries) can be shipped separately.

Sergey Shandar
  • 2,357
  • 18
  • 25
  • Thanks @sergey but I was under the impression that auto linking was avoiding the need to specify things like vc140, mt, d... but I still have to choose if I want to consume the library header only, static or dynamic, no? – Francesco Aug 22 '17 at 02:58
  • I already did that, in fact as you can see in the screenshot I have both the boost package and the precompiled libraries (in the screenshot you can see e.g. bzip2). Furthermore I have checked that the .lib and .dll files of the Test library are present on my system, for the various setup (debug, release, and so on). But my question is: how can I choose if in my .exe I want to consume a dynamic or a static library? Right now I am manually linking to avoid unneded recompilation but this defeats the purpose of auto-linking... – Francesco Aug 22 '17 at 17:51
  • Btw thanks for your efforts mantaining the nuget boost packages, they are much appreciated! – Francesco Aug 22 '17 at 17:52
  • 1
    @Francesco I see. The one way is to change how Boost select packages is to change your C++ project configuration. Another way is to add "BOOST_ALL_NO_LIB" and then manually link packages to your code using "#pragma" or build configuration. Currently, Boost NuGet packages only deliver libraries and relay on auto-linking. You may add a feature request to GetBoost but I (or someone else) need to design how this feature will work in all cases. – Sergey Shandar Aug 22 '17 at 18:29