LibVLC依赖项应添加到哪个项目? [英] To which Project should LibVLC dependencies be added?

查看:115
本文介绍了LibVLC依赖项应添加到哪个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET Framework项目 A 的解决方案,该解决方案构建了一个Winforms应用程序,其中包含需要 LibVLCSharp 的类 MyPlayer .为了使应用程序正确构建和运行,我必须添加以下Nuget软件包:

I have a Solution with .NET Framework Project A which builds a winforms application containing a class, MyPlayer which requires LibVLCSharp. In order for the application to build and run correctly I had to add the following Nuget packages:

  • LibVLCSharp
  • LibVLCSharp.WinForms
  • VideoLAN.LibVLC.Windows

现在,我想将类 MyPlayer 移到一个单独的.NET Standard类库Project B 中,以将功能与UI分离开,以便可以将其用于针对不同平台的多个其他项目.为了使 B 能够编译,我只需要添加 LibVLCSharp Nuget程序包.然后,将 B 设置为 A 的引用.

Now I want to move class MyPlayer to a separate .NET Standard class library, Project B, to separate out function from UI and so that it can be used by multiple other projects targeted to different platforms. In order for B to compile I only had to add the LibVLCSharp Nuget package. Then I set B as a Reference for A.

很显然,Project A 将以某种方式要求其他两个Nuget包,但是我不确定将它们添加到哪个项目中是最合适的.在这种情况下最有意义的是什么?还是真的只有一种方法可以工作?

Obviously, Project A is going to require the other two Nuget packages somehow, but I am unsure to which project it is most appropriate to add them. What makes the most sense in this situation? Or is there really only one way it would work?

推荐答案

这是一个好问题,我不知道它是否在LibVLCSharp上得到了正确的记录.

that's a good question, and I don't know if it is properly documented on LibVLCSharp.

简短回答:

  • 必须始终在可执行项目(A)中引用LibVLC
  • WinForms与.net标准不兼容,因此如果您继续使用netstandard,则无法在B中引用它.
  • 如果需要,可以将LibVLCSharp在项目B中上移".

长答案:

让我们详细查看软件包:

Let's see the packages in detail:

  • VideoLAN.LibVLC.Windows :该软件包包含使libvlc在Windows上运行所需的必需dll文件.它还包含用于将DLL复制到项目的输出目录的msbuild文件.您的应用程序中需要这些文件,因此您需要在 A 中引用此程序包.(它们不会被Project引用以可传递方式复制)

  • VideoLAN.LibVLC.Windows : This package contains the required dlls files that are required to make libvlc work on Windows. It also contains msbuild files that are used to copy the DLLs to the output directory of your project. You need those files in your application, so you need to reference this package in A. (They won't be transitively copied by a Project reference)

LibVLCSharp.WinForms :如所述

LibVLCSharp.WinForms : As stated here, this package only support .NET framework 4.0 and above, and .net core 3.0 and above. You will not be able to add this package in B, unless you replace your netstandard constraint and use multi-targetting instead. It will only work where WinForms is available.

LibVLCSharp ,而不会出现任何问题.由于您使用的是.net标准,因此您可能还会使用"SDK风格" csproj格式和 PackageReference .然后,该依赖项将在项目A中可传递地可用,而无需在其中添加.

LibVLCSharp can be referenced in project B without any issue. Since you're using .net standard, chances are you are also using the "SDK-style" csproj format and PackageReference. The dependency will then transitively be available in project A without adding it there.

如果您要在.net框架和.net核心中都提供一个播放器表单,则建议您将其放入B项目中,以使用多目标定位:

If your point was having a player Form available in both .net framework and .net core, I'd recommend that you use multi targetting, by putting this in your B project:

<TargetFrameworks>net40;netcoreapp3.0</TargetFrameworks>

否则,如果仅用于共享非ui代码,则不需要B中的LibVLCSharp.WinForms依赖项.

otherwise, if it's just for sharing non-ui code, you don't need the LibVLCSharp.WinForms dependency in B

这篇关于LibVLC依赖项应添加到哪个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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