为通过 Nuget 安装的 C++ 库设置链接类型

Fra*_*sco 5 c++ visual-studio nuget nuget-package visual-studio-2015

这个答案提到了以下方法来链接到通过 Nuget 安装的 C++ 库的静态版本 [在这种情况下,“freeglut”]:

Project->Properties->Configuration Properties->Referenced Packages->freeglut->Linkage (select static) 
Run Code Online (Sandbox Code Playgroud)

使用 Visual Studio 2015 我找不到“参考包”。我拥有的对 Nuget 包的唯一明确引用是 packages.config xml 文件。如果我转到项目的“管理 Nuget 包”部分,我可以安装或卸载,但找不到包的任何详细信息。

我已经在 msdn 中搜索了文档,但所有页面都专门用于创建包,而我需要强调使用这种包的方式。有问题的包(Boost 单元测试框架)可以仅用于标头、静态或动态链接,我想知道我可以在哪里决定它。

也许我老了,但 Nuget 对我来说有点太神奇了......

更新

这就是我所看到的 - 您可以看到安装了 Nuget 包,特别是 boost,但是在配置属性下没有指向“引用包”的链接: Nuget 安装包和配置属性的屏幕截图,没有指向“参考包”的链接

为完整起见,VS 2015 Enterprise 的版本为:

14.0.25431.01 更新 3

我已经检查过,当我安装 Boost 测试包时,我同时获得了静态 (.lib) 和动态 (.dll) 链接版本,因为我的 VS 版本的文件存在于包文件夹中。

Leo*_*SFT 2

在 Visual Studio 2015 中,我找不到“引用的包”。

这取决于你的项目中是否安装了 freeglut 包。如果您创建的 C++ 项目没有安装任何 NuGet 包,则无法找到“引用的包”:

在此输入图像描述

安装 nuget 包freeglut”后,“ Referenced Packages”和“ Project Master Settings”将添加到Configuration Properties

在此输入图像描述

Boost 软件包更新: 您应该安装该软件包freeglut以检查“ Referenced Packages”和“ Project Master Settings”。既然您注意到包freeglut和之间的不同行为Boost,我想提供有关本机 NuGet 包的更多信息。将freeglut和安装Boost到项目中后,您可以在软件包文件夹(..\packages\freeglut.2.8.1.15\build\native & packages\boost.1.64.0.0\build\native)中找到freeglut.targets和,使用以下命令打开它们boost.targets记事本或者VS,你会注意到:

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>
Run Code Online (Sandbox Code Playgroud)

这会将选项“ Referenced Packages”和Project Master Settings“via PropertyGroupin”添加到 C++ 属性中。

但在boost.targets文件中,只有:

   <ItemDefinitionGroup>
    <ClCompile>
      <PreprocessorDefinitions>;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)..\..\lib\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>
  </ItemDefinitionGroup>
Run Code Online (Sandbox Code Playgroud)

因此是否添加“ Referenced Packages”和“ Project Master Settings”取决于包文件夹中的.targets文件。

如果我转到项目的“管理 Nuget 包”部分,我可以安装或卸载,但找不到该包的任何详细信息。

在项目的“管理Nuget包”部分的右侧,您可以注意到一些更详细的说明:

在此输入图像描述

我已经在 msdn 中搜索了文档,但所有页面都专门用于创建包,而我需要强调使用此类包的方式。

您可以参考文档使用包来了解如何使用包。

有问题的包(Boost 单元测试框架)可以仅使用标头、静态或动态链接,我想知道在哪里可以决定它。

你可以在Project->Properties->Configuration Properties->Referenced Packages->freeglut中决定:

在此输入图像描述