简体   繁体   English

CMake CSharp 参考 nuget 包

[英]CMake CSharp reference nuget packges

I have a CSharp project configured via CMake, and I have a problem referencing nuget packages.我有一个通过 CMake 配置的 CSharp 项目,但在引用 nuget 包时遇到问题。 I tried to add them via:我尝试通过以下方式添加它们:

set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES
"../../packages/ExcelDna.Integration.0.34.6/lib/ExcelDna.Integration.dll")

After restoring the nuget packages, I still have to double click the reference in Visual Studio (2015) in order to compile the program successfully.恢复nuget包后,我仍然需要双击Visual Studio(2015)中的引用才能成功编译程序。 Furthermore, is there a version number independent way to add references to nuget packages?此外,是否有一种独立于版本号的方式来添加对 nuget 包的引用? And how is it possible to add ExtensionTargets required by some packages (eg ExcelDna.AddIn)?以及如何添加某些包(例如 ExcelDna.AddIn)所需的ExtensionTargets

EDIT : As of CMake 3.15, CMake supports referencing Nuget packages with VS_PACKAGE_REFERENCES .编辑:从 CMake 3.15 开始,CMake 支持使用VS_PACKAGE_REFERENCES引用 Nuget 包。 This is a cleaner solution than restoring the Nuget packages manually, and hard-coding the package paths in CMake.与手动恢复 Nuget 包并在 CMake 中硬编码包路径相比,这是一种更简洁的解决方案。 The VS_PACKAGE_REFERENCES target property now handles all of that overhead for you. VS_PACKAGE_REFERENCES目标属性现在为您处理所有这些开销。

To add a Nuget package reference to a CMake target, use the package name and package version separated by an underscore _ , like this:要将 Nuget 包引用添加到 CMake 目标,请使用由下划线_分隔的包名称和包版本,如下所示:

set_property(TARGET ${PROJECT_NAME}
    PROPERTY VS_PACKAGE_REFERENCES "ExcelDna.Integration_0.34.6"
)

You can grab any version number in a range, with * , and append multiple packages using a semicolon:您可以使用*获取范围内的任何版本号,并使用分号附加多个包:

set_property(TARGET ${PROJECT_NAME}
    PROPERTY VS_PACKAGE_REFERENCES "ExcelDna.Integration_0.34.*;ExcelDna.AddIn_1.0.0"
)

You can use VS_DOTNET_REFERENCE_<YourLibrary> to get CMake to find your Nuget package references.您可以使用VS_DOTNET_REFERENCE_<YourLibrary>让 CMake 找到您的 Nuget 包引用。 Try this:尝试这个:

set_property(TARGET ${PROJECT_NAME} PROPERTY 
    VS_DOTNET_REFERENCE_ExcelDna.Integration 
    ${CMAKE_BINARY_DIR}/packages/ExcelDna.Integration.0.34.6/lib/ExcelDna.Integration.dll
)

Note, the full DLL name must be appended to the VS_DOTNET_REFERENCE_ directive to create the full variable.请注意,完整的 DLL 名称必须附加到VS_DOTNET_REFERENCE_指令以创建完整变量。 However, I have not seen a version number independent way to load the Nuget packages, and I've had to manually edit my CMake files to include these packages.但是,我还没有看到加载 Nuget 包的独立于版本号的方式,我不得不手动编辑我的 CMake 文件以包含这些包。 You can check out this answer for a more detailed explanation.您可以查看此答案以获得更详细的解释。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM