To which Project should LibVLC dependencies be added?

孤者浪人 提交于 2021-01-27 19:04:42

问题


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

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.

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?


回答1:


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

Short Answer:

  • LibVLC must always be referenced on the executable project (A)
  • WinForms isn't compatible with .net standard, so you can't reference it in B if you keep using netstandard.
  • LibVLCSharp can be moved "up" in project B if you need it there.

Long answer:

Let's see the packages in detail:

  • 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 : 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 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.

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>

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



来源:https://stackoverflow.com/questions/61480325/to-which-project-should-libvlc-dependencies-be-added

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!