具有多个 DLL 的 nuget 包 [英] nuget package with multiple DLL's

查看:76
本文介绍了具有多个 DLL 的 nuget 包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 Nuget Package Explorer 创建了一个包含以下内容的 nuget 包.

I have created a nuget package via Nuget Package Explorer with the following content.

lib
   -- CPPLib.dll
   -- DotNetWrapper.dll

CPPLib.dll 是逻辑实现的主要库(在原生 C++ 中),DotNetWrapper.dll 是包装器,将在 C# 项目中引用.

CPPLib.dll is the main library with logic implementation (in native C++), and DotNetWrapper.dll is the wrapper which will be reference in C# projects.

当我尝试安装这个 nuget 包时,出现以下错误

When I try to install this nuget package, I got the following error

    Install failed. Rolling back...
    Install-Package : Failed to add reference to 'CPPLib.dll'.
    At line:1 char:16
    + install-package <<<<  -id MyPackage
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

我知道包内lib"文件夹中的所有内容都将作为参考安装,这就解释了为什么无法将本机 CPPLib.dll 安装到 C# 项目中.

I know everything in "lib" folder inside the package will be installed as reference, which explains why the native CPPLib.dll can't be installed to a C# project.

然后我尝试像这样将 CPPLib.dll 移动到包中的content"文件夹中

Then I tried to move the CPPLib.dll into "content" folder in the package like this

   content
       -- CPPLib.dll
   lib
       -- DotNetWrapper.dll

然后就可以安装包了,但是由于DotNetWrapper.dll在同一文件夹中找不到CPPLib.dll,所以项目不会构建.

Then the package can be installed, but the project will not build as DotNetWrapper.dll can not find CPPLib.dll in the same folder.

我该如何解决这个问题?是否有可能以某种方式将所有内容都放在 lib 文件夹中,并且只从包中公开"DotNetWrapper.dll?

How can I get around this issue? Is it possible to somehow put everything in lib folder and only "expose" DotNetWrapper.dll from the package?

推荐答案

您需要处理 nuspec 文件中的文件和引用:

you need to work with files and references in your nuspec file:

<?xml version="1.0"?>
<package  xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
    <metadata>
        ...
        <references>
            <reference file="DotNetWrapper.dll" />
        </references>  
    </metadata>
    <files>
        <file src="bin\Release\DotNetWrapper.dll" target="lib" />
        <file src="bin\Release\CPPLib.dll" target="lib" />
    </files>
</package>

因此您定义文件以使用文件"放入包中,并告诉 nuget 您要添加的唯一引用是带有引用"的包装器 DLL.

so you define files to put in your package with "files", and tell the nuget that your only reference to add is wrapper DLL with "references".

请提及这些标签在不同的级别 - 引用"必须在元数据"内,但文件"与元数据"同级

Pls mention that these tags are on different level - "references" must be inside "metadata", but "files" are sibling to "metadata"

这篇关于具有多个 DLL 的 nuget 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆