我尝试将WMPLib nuget包作为包引用添加到我的项目中,但是在代码中找不到类。
这在我的csproj文件中:
<PackageReference Include="WMPLib">
<Version>1.0.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>在我的cs文件里:
using WMPLib;这是一个错误:
error CS0246: The type or namespace name 'WMPLib' could not be found (are you missing a using directive or an assembly reference?)这里我读到“这个问题是由于新的NuGet格式引用'PackageReference‘.文件夹和文件没有添加”。
有人知道这件事吗?解决方案是使用package.config而不是包引用吗?
发布于 2022-08-17 12:07:48
好吧,我能重现你的问题,也找到了一些解决办法。
问题
在我看来,最初的WMPLib NuGet包在某种程度上被破坏了/实际上不符合现在NuGet的期望。我认为这是因为以下两项指标:
WMPLib,它只显示.NET框架(请看这里) --但是哪个版本呢?将其与Newtonsoft.Json进行比较。lib文件夹中找到了程序集。但通常情况下,它们都在lib\<<TFM>>内部,例如lib\net48.解决办法
我使用AxInterop.WMPLib.dll和Interop.WMPLib.dll提取了两个程序集-- dotPeek,并将它们保存在C:\temp\NewWMPLib\lib\net35中。
然后我创建了以下文件C:\temp\NewWMPLib.nuspec
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>NewWMPLib</id>
<version>1.0.0</version>
<authors>me</authors>
<owners>me</owners>
<description>Lorem ipsum</description>
</metadata>
</package>最后,我通过NuGet构建了一个新的nuget pack C:\temp\NewWMPLib.nuspec包。
当通过NuGet使用这个包时,下面的代码现在编译:
using WMPLib;
namespace ConsoleApp4
{
internal class Program
{
static void Main(string[] args)
{
var windowsMediaPlayerClass = new WindowsMediaPlayerClass();
}
}
}免责声明
我不是律师,我不知道遵循我的解决办法在法律上是否安全。
https://stackoverflow.com/questions/73377275
复制相似问题