简体   繁体   English

我是否可以使用不在.NET Framework上的旧版DLL创建NuGet包(或其他包)?

[英]Can I create a NuGet package (or other package) with legacy dll's that are not on a .NET Framework?

We have a bunch of legacy dll's (basically could be anything, some are old fortran, some .NET) and we want to move them to Azure Artifacts. 我们有一堆遗留的dll(基本上可以是任何东西,有些是旧的fortran,有些是.NET),我们想将它们移动到Azure Artifacts。 Can I create NuGet packages from these legacy dll's that are not based on .NET (like the Fortran ones) by themselves. 我是否可以从这些不基于.NET的遗留DLL(如Fortran)创建NuGet包。

I've already tried creating the NuGet packages, but I get warnings on my dependencies because it looks like they are trying to load the packages on a .NET framework. 我已经尝试过创建NuGet包,但是我的依赖项会收到警告,因为看起来他们正试图在.NET框架上加载这些包。 Is the only real workaround here to build a .NET say class library or something, then reference the dll through that, and create a NuGet package with that library and just add the legacy dll's as references? 这是构建.NET说法类库的唯一真正的解决方法,然后通过它引用dll,并使用该库创建一个NuGet包,只需添加旧的dll作为引用?

Can I create a NuGet package (or other package) with legacy dll's that are not on a .NET Framework? 我是否可以使用不在.NET Framework上的旧版DLL创建NuGet包(或其他包)?

The answer is yes. 答案是肯定的。

You could target those legacy dlls to the tools folder instead of the lib folder. 您可以将这些遗留dll定位到tools文件夹而不是lib文件夹。 like: 喜欢:

<files>
    <file src="legacy\*.dll" target="Tools" />
    <!-- Other files -->
</files>

Then pack this .nuspec file when you build the pipeline, those legacy dlls are located in the tools folder, which will not add as references. 然后在构建管道时打包此.nuspec文件,这些旧的dll位于tools文件夹中,不会添加为引用。

Check the From a convention-based working directory for some details. 检查From a基于约定的工作目录以获取一些详细信息。

在此输入图像描述

Hope this helps. 希望这可以帮助。

I assume what you mean is that your managed code is usng DllImport attributes to call native code, which in the .NET ecosystem is called Platform Invoke, or P/Invoke. 我假设您的意思是您的托管代码使用DllImport属性来调用本机代码,在.NET生态系统中称为平台调用或P / Invoke。 I mention this because if you googled terms around P/Invoke and nuget you probably would have had better luck finding existint stack overflow questions, blog posts and so on. 我提到这一点是因为如果你用P / Invoke和nuget搜索条件你可能会有更好的运气找到存在堆栈溢出问题,博客帖子等等。 For this reason it's useful to try to find out the official or commonly used names of the features you use, so you know what to search for. 因此,尝试查找您使用的功能的官方或常用名称非常有用,因此您知道要搜索的内容。 Unfortunately I don't think the NuGet team has any docs on this scenario at the moment. 不幸的是,我认为NuGet团队目前没有关于这种情况的任何文档。

SDK style projects support the runtime\\ directory in the package, although I think that's somewhat undocumented as well. SDK样式项目支持包中的runtime\\目录,尽管我认为它也有些未记录。 I don't know about traditional projects using PackageReference (PR), but packages.config (PC) definately does not support runtimes\\ . 我不知道使用PackageReference (PR)的传统项目,但packages.config (PC)肯定不支持runtimes\\ For PC projects, the package author typically (always?) includes build targets to copy the native assemblies after build. 对于PC项目,包作者通常(总是?)包括构建目标,以在构建后复制本机程序集。 In the package, the native dlls are elsewhere, often the author puts them in the build directory next to the targets, but I think I've also seen the targets copy from the runtime directory so that the package supports both PC and SDK style projects. 在包中,本机dll在其他地方,通常作者将它们放在目标旁边的build目录中,但我想我也看到目标从runtime目录中复制,以便该包支持PC和SDK样式项目。

I suggest you try to think of some commonly used native libraries that have .NET bindings and see how the package works ( nupkg is just a zip renamed). 我建议您尝试考虑一些常用的具有.NET绑定的本机库,并查看该包的工作原理( nupkg只是一个zip重命名)。 My guesses would be sqlite or curl, or how asp.net core's kestrel web server bundles libuv (or did in earlier versions if it no longer does). 我的猜测是sqlite或curl,或者asp.net core的kestrel web服务器如何捆绑libuv(如果不再使用早期版本的话)。 I'm on vacation at the moment, so don't have the motivation to dig deep myself. 我现在正在度假,所以没有动力深入挖掘自己。

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

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