<legend id='5TbOy'><style id='5TbOy'><dir id='5TbOy'><q id='5TbOy'></q></dir></style></legend>
        <bdo id='5TbOy'></bdo><ul id='5TbOy'></ul>

      1. <i id='5TbOy'><tr id='5TbOy'><dt id='5TbOy'><q id='5TbOy'><span id='5TbOy'><b id='5TbOy'><form id='5TbOy'><ins id='5TbOy'></ins><ul id='5TbOy'></ul><sub id='5TbOy'></sub></form><legend id='5TbOy'></legend><bdo id='5TbOy'><pre id='5TbOy'><center id='5TbOy'></center></pre></bdo></b><th id='5TbOy'></th></span></q></dt></tr></i><div id='5TbOy'><tfoot id='5TbOy'></tfoot><dl id='5TbOy'><fieldset id='5TbOy'></fieldset></dl></div>
      2. <small id='5TbOy'></small><noframes id='5TbOy'>

        <tfoot id='5TbOy'></tfoot>

        CMake 和 MsVS-NuGet

        CMake and MsVS-NuGet(CMake 和 MsVS-NuGet)

          <tfoot id='gusaT'></tfoot>

            <i id='gusaT'><tr id='gusaT'><dt id='gusaT'><q id='gusaT'><span id='gusaT'><b id='gusaT'><form id='gusaT'><ins id='gusaT'></ins><ul id='gusaT'></ul><sub id='gusaT'></sub></form><legend id='gusaT'></legend><bdo id='gusaT'><pre id='gusaT'><center id='gusaT'></center></pre></bdo></b><th id='gusaT'></th></span></q></dt></tr></i><div id='gusaT'><tfoot id='gusaT'></tfoot><dl id='gusaT'><fieldset id='gusaT'></fieldset></dl></div>

            • <bdo id='gusaT'></bdo><ul id='gusaT'></ul>
                <tbody id='gusaT'></tbody>
              • <small id='gusaT'></small><noframes id='gusaT'>

                  <legend id='gusaT'><style id='gusaT'><dir id='gusaT'><q id='gusaT'></q></dir></style></legend>
                  本文介绍了CMake 和 MsVS-NuGet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在使用 C++ REST SDK(代号 Casablanca)、Qt5 和其他一些库开发桌面应用程序.

                  I'm currently developing a desktop application, using the C++ REST SDK (codename Casablanca), Qt5 and some other libraries.

                  对于项目设置,我使用 CMake.

                  For the project setup, I use CMake.

                  如何让 CMake 安装 NuGet 包?

                  How to get CMake to install NuGet Packages?

                  我现在每次都必须手动安装它,如果我重新运行 CMake,这不是一个真正的选择.

                  I now have to install it each time manually, if I rerun CMake, which isn't really an option.

                  推荐答案

                  EDIT:从 CMake 3.15 开始,CMake 支持使用 VS_PACKAGE_REFERENCES.现在,这是一个 比下面早些时候提出的变通方法更简洁的解决方案.要将 Nuget 包引用添加到 CMake 目标,请使用由 _ 下划线分隔的包名称和包版本.以下是 BouncyCastle 版本 1.8.5 的示例:

                  EDIT: As of CMake 3.15, CMake supports referencing Nuget packages with VS_PACKAGE_REFERENCES. Now, this is a much cleaner solution than the work-around proposed earlier below. To add a Nuget package reference to a CMake target, use the package name and package version separated by an _ underscore. Here is an example for BouncyCastle version 1.8.5:

                  set_property(TARGET MyApplication
                      PROPERTY VS_PACKAGE_REFERENCES "BouncyCastle_1.8.5"
                  )
                  

                  文档展示了如何添加多个 Nuget 包通过分号分隔 ; 包.

                  The documentation shows how you can add multiple Nuget packages by semicolon-delimiting ; the packages.

                  对于 3.15 之前的 CMake 版本,这是一种潜在的解决方法:

                  For CMake versions older than 3.15, here is one potential work-around:

                  感谢@Markus Mayer 的出色回答.我采纳了这个建议,但发现如果您要从头开始生成 VS 项目/解决方案文件,则使用 nuget 命令行是行不通的.具体来说,nuget 命令行不会更新项目文件 (.csproj),并且似乎需要一些手动工作来告诉您的项目在哪里可以找到已安装的依赖项.以下步骤概述了我如何针对具有一个 Nuget 包依赖项的简单项目解决此问题:

                  Kudos to @Markus Mayer for the excellent answer. I ran with the suggestion, but found that using the nuget command line doesn't hold up if you're generating your VS project/solution files from scratch. Specifically, the nuget command line does not update the project files (.csproj), and some manual effort seems necessary to tell your project where to find the installed dependencies. The following steps outline how I worked around this for a simple project with one Nuget package dependency:

                  1. 在 Visual Studio 中使用 Nuget 包管理器安装了 Nuget 包依赖项.
                  2. 复制生成的 packages.config 文件(在与受影响的 .csproj 文件相同的目录中生成).将副本放入源目录,并将其重命名为 packages.config.in.现在,我们可以在配置阶段使用 configure_file 告诉 CMake 将此文件复制回 CMake 二进制目录.如果依赖项缺失,Nuget 将使用它来安装/恢复依赖项.
                  3. 记下 Nuget 为该包安装 DLL 的位置.在我的机器上,它位于 packages 目录中的 CMake 二进制目录中.
                  1. Installed the Nuget package dependency using Nuget Package Manager in Visual Studio.
                  2. Copied the generated packages.config file (generated in the same directory as the affected .csproj file). Placed the copy into a source directory, and renamed it as packages.config.in. Now, we can tell CMake to copy this file back to the CMake binary directory during the configure stage with configure_file. Nuget will use it to install/restore dependencies, if they are missing.
                  3. Took note of where Nuget installed the DLL for this package. On my machine, this was in the CMake binary directory in a packages directory.

                  我们可以使用这个路径告诉 CMake 我们的引用包的位置:

                  We can use this path to tell CMake our reference package's location:

                  set_property(TARGET MyApplication PROPERTY VS_DOTNET_REFERENCE_MyReferenceLib
                      ${CMAKE_BINARY_DIR}/packages/path/to/lib/MyReferenceLib.dll)
                  

                  我们还可以在 .csproj 文件中查看此依赖项的安装位置,以验证我们获得了正确的路径(请参阅 HintPath),并且没有遗漏任何其他依赖:

                  We can also see where this dependency is installed in the .csproj file to verify we got the correct path (see HintPath), and didn't miss any other dependencies:

                  <Reference Include="MyReferenceLib, Version=2.5.0, Culture=neutral, PublicKeyToken=1234567891234567, processorArchitecture=MSIL">
                    <HintPath>packagespath	olibMyReferenceLib.dll</HintPath>
                  </Reference>
                  

                  1. 卸载了 Nuget 包,因为现在我们拥有让 CMake 完成所有繁重工作所需的所有信息.

                  综合起来,CMake 命令如下所示:

                  Putting it together, the CMake commands look like this:

                  # Find Nuget (install the latest CLI here: https://www.nuget.org/downloads).
                  find_program(NUGET nuget)
                  if(NOT NUGET)
                      message(FATAL "CMake could not find the nuget command line tool. Please install it!")
                  else()
                      # Copy the Nuget config file from source location to the CMake build directory.
                      configure_file(packages.config.in packages.config COPYONLY)
                      # Run Nuget using the .config file to install any missing dependencies to the build directory.
                      execute_process(COMMAND 
                          ${NUGET} restore packages.config -SolutionDirectory ${CMAKE_BINARY_DIR}
                          WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
                      )
                  endif()
                  # Provide the path to the Nuget-installed references, in case this is a fresh project build.
                  set_property(TARGET MyApplication PROPERTY 
                      VS_DOTNET_REFERENCE_MyReferenceLib
                      ${CMAKE_BINARY_DIR}/packages/path/to/lib/MyReferenceLib.dll)
                  

                  虽然这现在也将为新的 CMake 构建提供到 VS 项目的包路径,但有一个警告.如果要升级正在使用的 Nuget 安装包的版本,则必须重新执行上述手动步骤.

                  While this will now also provide package paths to the VS project for fresh CMake builds, there is one caveat. If you want to upgrade the version of the Nuget-installed package you are using, you'll have to re-do the aforementioned manual steps.

                  TL;DR:这是我使用 Nuget 安装的 SQLite 尝试的完整 CMakeLists.txt 文件:

                  TL;DR: Here is the full CMakeLists.txt file that I tried out with Nuget-installed SQLite:

                  cmake_minimum_required(VERSION 3.8)
                  
                  # Project name
                  project(MyProject LANGUAGES CSharp)
                  
                  # Include CMake utilities for CSharp, for WinForm and WPF application support.
                  include(CSharpUtilities)
                  
                  set(MyProject_SOURCES 
                      Form1.cs
                      Form1.Designer.cs
                      Form1.resx
                      Program.cs
                      Properties/AssemblyInfo.cs
                      Properties/Resources.Designer.cs
                      Properties/Resources.resx
                      Properties/Settings.Designer.cs
                      Properties/Settings.settings
                  )
                  
                  # Define the executable, including any .cs files. 
                  # The .resx and other Properties files are optional here, but including them makes them visible in the VS solution for easy editing. 
                  add_executable(MyWinFormApp ${MyProject_SOURCES})
                  
                  # Set the source file properties for Windows Forms use.
                  csharp_set_windows_forms_properties(${MyProject_SOURCES})
                  
                  # Find Nuget (install the latest CLI here: https://www.nuget.org/downloads).
                  find_program(NUGET nuget)
                  if(NOT NUGET)
                      message(FATAL "CMake could not find the nuget command line tool. Please install it!")
                  else()
                      # Copy the Nuget config file from source location to the CMake build directory.
                      configure_file(packages.config.in packages.config COPYONLY)
                      # Run Nuget using the .config file to installing any missing dependencies to the build directory.
                      execute_process(COMMAND 
                          ${NUGET} restore packages.config -SolutionDirectory ${CMAKE_BINARY_DIR}
                          WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
                      )
                  endif()
                  
                  # Set the .NET Framework version for the executable.
                  set_property(TARGET MyWinFormApp PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v4.6.1")
                  
                  # Provide the path to the Nuget-installed references, in case this is a fresh project build.
                  set_property(TARGET MyWinFormApp PROPERTY 
                      VS_DOTNET_REFERENCE_EntityFramework 
                      ${CMAKE_BINARY_DIR}/packages/EntityFramework.6.2.0/lib/net45/EntityFramework.dll)
                  set_property(TARGET MyWinFormApp PROPERTY 
                      VS_DOTNET_REFERENCE_EntityFramework.SqlServer 
                      ${CMAKE_BINARY_DIR}/packages/EntityFramework.6.2.0/lib/net45/EntityFramework.SqlServer.dll)
                  set_property(TARGET MyWinFormApp PROPERTY 
                      VS_DOTNET_REFERENCE_System.Data.SQLite
                      ${CMAKE_BINARY_DIR}/packages/System.Data.SQLite.Core.1.0.110.0/lib/net46/System.Data.SQLite.dll)
                  set_property(TARGET MyWinFormApp PROPERTY 
                      VS_DOTNET_REFERENCE_System.Data.SQLite.EF6 
                      ${CMAKE_BINARY_DIR}/packages/System.Data.SQLite.EF6.1.0.110.0/lib/net46/System.Data.SQLite.EF6.dll)
                  set_property(TARGET MyWinFormApp PROPERTY 
                      VS_DOTNET_REFERENCE_System.Data.SQLite.Linq
                      ${CMAKE_BINARY_DIR}/packages/System.Data.SQLite.Linq.1.0.110.0/lib/net46/System.Data.SQLite.Linq.dll)
                  
                  # Add in the .NET reference libraries.
                  set_property(TARGET MyWinFormApp PROPERTY VS_DOTNET_REFERENCES
                      "System"
                      "System.Core"
                      "System.Data"
                      "System.Windows.Forms"
                  )
                  

                  这篇关于CMake 和 MsVS-NuGet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)

                    <bdo id='W7u7K'></bdo><ul id='W7u7K'></ul>
                  • <small id='W7u7K'></small><noframes id='W7u7K'>

                    <i id='W7u7K'><tr id='W7u7K'><dt id='W7u7K'><q id='W7u7K'><span id='W7u7K'><b id='W7u7K'><form id='W7u7K'><ins id='W7u7K'></ins><ul id='W7u7K'></ul><sub id='W7u7K'></sub></form><legend id='W7u7K'></legend><bdo id='W7u7K'><pre id='W7u7K'><center id='W7u7K'></center></pre></bdo></b><th id='W7u7K'></th></span></q></dt></tr></i><div id='W7u7K'><tfoot id='W7u7K'></tfoot><dl id='W7u7K'><fieldset id='W7u7K'></fieldset></dl></div>
                  • <legend id='W7u7K'><style id='W7u7K'><dir id='W7u7K'><q id='W7u7K'></q></dir></style></legend>

                          <tbody id='W7u7K'></tbody>

                          • <tfoot id='W7u7K'></tfoot>