我有一个非常棘手的问题。如何在 Visual Studio for Mac 中添加类?
更具体地说,我如何引用任何类?
我正在阅读说明 here。它说有一个使用 AVAudioPlayer 类的音频播放器示例。
它没有具体说明如何添加该类,而是转到“项目”>“添加引用”菜单并在搜索框中输入“音频”,什么也没显示:
这是我参考的说明页面:
https://docs.microsoft.com/en-us/xamarin/mac/app-fundamentals/sounds
页面还说这是一个示例,但我没有看到任何代码,只有 API 参考。
Apple API
https://developer.apple.com/documentation/avfaudio/avaudioplayer#see-also
https://developer.apple.com/documentation/avfaudio/avaudioengine
更新:
我想我可能已经想通了。
该类看起来像是在 AVFoundation 包中,而不是 AVFAudio
:
要使用它,您必须输入:
using AVFoundation;
在班级中名列前茅
然后在你的代码中你可以使用:
var player = new AVAudioPlayer();
或者看起来你可以使用完整的命名空间来创建一个实例:
var player = new AVFoundation.AVAudioPlayer();
我仍然遇到错误,所以我不知道是不是这样。
我还添加了一些 Nugen 库,如 Xamarin.CommunityToolkit,但我没有看到它们被引用,所以我不知道是否有必要。
更新 2:
看起来像这里的说明:
https://docs.microsoft.com/en-us/visualstudio/mac/nuget-walkthrough?view=vsmac-2019
以下是我遇到的错误:
<块引用>/应用程序/视觉 Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Microsoft.Common.CurrentVersion.targets(5,5): 警告 MSB3276:发现不同版本的 相同的依赖程序集。请设置“AutoGenerateBindingRedirects” 属性在项目文件中为 true。有关更多信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=294190。 (MSB3276) (项目)
<块引用>/Users/me/project/packages/Xamarin.CommunityToolkit.1.1.0/build/PreserveXamarinCommunityToolkit.cs(12,12): 错误 CS0246:类型或命名空间名称“PreserveToolkitAttribute” 找不到(您是否缺少 using 指令或程序集 参考?)(CS0246)(项目)
附注:
这里似乎没有太多关于 SO 的活动,所以我尝试访问 Visual Studio 论坛并发布您必须加入 Microsoft 文档网络的帖子。以下是尝试注册时的一些详细信息。他们在注册之前没有提到这一点。