简体   繁体   English

在项目之间共享DLL

[英]Sharing a DLL between projects

Microsoft says it's platform neutral these days, so I'm trying to build on Mac and Linux only with VS Code and deploy to Azure. 微软表示它现在处于平台中性,因此我试图仅使用VS Code构建Mac和Linux并部署到Azure。 Why? 为什么? It's mainly to prove that I can. 这主要是为了证明我能。

Our project has several parts which include a couple of different websites, a Web API, er API and a few other bits. 我们的项目有几个部分,包括几个不同的网站,一个Web API,呃API和一些其他位。 On my Mac I've built a .Net Core Class Library with a load of objects in. Command line, dotnet build, DLL out, no problem. 在我的Mac上,我已经构建了一个带有大量对象的.Net核心类库。命令行,dotnet构建,DLL输出,没问题。

I want to put that DLL on the Linux machine where the MVC website is being built - the objects forming the models part of that site hopefully. 我想把这个DLL放在构建MVC网站的Linux机器上 - 希望这个对象构成该站点的模型部分。 I cannot figure out how to get the website project to reference my DLL and use the objects. 我无法弄清楚如何让网站项目引用我的DLL并使用这些对象。

I had assumed I copy it to the other machine, place it in the bin folder of the site being developed and reference it in the Dependencies section of the site's project.json. 我假设我将它复制到另一台机器,将它放在正在开发的站点的bin文件夹中,并在站点的project.json的Dependencies部分中引用它。 Nope. 不。 I saw a few articles that said .Net Core only works with NuGet and it had to be a package. 我看到一些文章说.Net Core只适用于NuGet,它必须是一个包。 Is that really true? 这是真的吗?

I've found and read (if not entirely understood) everything you could imagine on sharing between .net core and .net framework. 我发现并阅读了(如果不完全理解的话)在.net核心和.net框架之间共享的一切。 This is a core-only project so not applicable. 这是一个仅核心项目,因此不适用。 Frankly I'm lost, and something called .Net Standard has just rolled into my field of vision. 坦率地说,我迷失了,所谓的.Net Standard刚刚进入了我的视野。

So instead of copying the DLL, use dotnet pack to build a nuget package on your Mac, and copy that to your Linux machine instead. 因此,不要复制DLL,而是使用dotnet pack在Mac上构建nuget包,然后将复制到Linux机器上。 Put it in a directory that you configure as a local nuget repository (no server or anything required) and you're away. 将它放在一个配置为本地nuget存储库的目录中(没有服务器或任何需要的东西),你就离开了。

I agree it's not as straightforward as a reference to a DLL, but it's not too bad. 我同意它并不像对DLL的引用那么简单,但它并不是太糟糕。 Note that you'll need to version the package appropriately, so that the tool system can detect when it's changed. 请注意,您需要对软件包进行适当的版本控制,以便工具系统可以检测软件包何时更改。

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

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