c# - 无法将 wmp.dll 引用添加到 C# .Net Core 项目
问题描述
我正在构建用 c# 编写的简单媒体播放器。它是 Windows 窗体应用程序,按.csproj
文件,我的目标框架是net5.0-windows
.
我想使用 wmp.dll。
问题是,Visual Studio 2019 向我显示一条错误消息“引用无效或不受支持”。当通过解决方案资源管理器添加对 wmp.dll 的引用时,我得到了这个。
wmp.dll 位于我的 PC 中的 C:\Windows\System32 目录中。
我还尝试使用 nuget 包下载 wmp.dll。当我这样做时,我在.csproj
文件中得到了以下代码
<ItemGroup>
<PackageReference Include="Up3.5" Version="1.0.0" />
<PackageReference Include="WMPLib" Version="1.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
而且我仍然不能在我的项目中使用 WMPLib。我很感激任何帮助。
编辑
我在 nuget 包中添加了对 wmp.dll 的直接引用。但是我不知道当我将我的项目变成可执行文件时是否可以依赖它。
添加引用时的 Visual Studio 错误消息
那是我的.csproj
文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<Compile Update="Presentation\Form1.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Up3.5" Version="1.0.0" />
<PackageReference Include="WMPLib" Version="1.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="Interop.WMPLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\.nuget\packages\wmplib\1.0.0\lib\Interop.WMPLib.dll</HintPath>
</Reference>
<Reference Include="PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<HintPath>..\..\..\..\..\..\Windows\Microsoft.NET\Framework\v4.0.30319\WPF\PresentationCore.dll</HintPath>
</Reference>
</ItemGroup>
</Project>