我创建了一个跨平台库,它有3个特定于平台的实现:
我已经将这个库与Nuget打包在一起,就像跨平台库项目一样。
现在,当我创建一个新的Xamarin Forms项目并选择.NET Standard作为共享代码的方法时,我引用我的nuget并尝试在android模拟器中运行它,我得到:
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2,2): Error: Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'SDK.NetStandard, Version=1.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'SDK.NetStandard.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference, Mono.Cecil.ReaderParameters parameters) [0x0009a] in /Users/builder/data/lanes/5945/342b2ce9/source/monodroid/external/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:229
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference) [0x00000] in /Users/builder/data/lanes/5945/342b2ce9/source/monodroid/external/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:179
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver, System.Collections.Generic.ICollection`1[T] assemblies, Mono.Cecil.AssemblyDefinition assembly, System.Boolean topLevel) [0x0014a] in <fdfe8f54615a4e2ab24c72dc90da5c64>:0
at Xamarin.Android.Tasks.ResolveAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver) [0x00237] in <fdfe8f54615a4e2ab24c72dc90da5c64>:0 (blank.Android)
我已经仔细检查过,nuget包中存在SDK.NetStandard.dll。
我已经通过创建一个带有.NET Core 2的简单控制台应用程序以及那里的库工作属性来测试它。
[编辑]
我已将我的软件包从SDK重命名为Matchmore.SDK以减轻混淆 在运行时iOS中,错误看起来像这样。
System.IO.FileNotFoundException: Could not load file or assembly 'Matchmore.SDK.NetStandard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies.
at blankstandard.App..ctor () [0x0001b] in /Users/lmlynik/Projects/blankstandard/blankstandard/App.xaml.cs:15
at blankstandard.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00007] in /Users/lmlynik/Projects/blankstandard/blankstandard.iOS/AppDelegate.cs:26
at at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/UIKit/UIApplication.cs:63
at blankstandard.iOS.Application.Main (System.String[] args) [0x00001] in /Users/lmlynik/Projects/blankstandard/blankstandard.iOS/Main.cs:17
答案 0 :(得分:1)
答案 1 :(得分:0)
https://bugzilla.xamarin.com/show_bug.cgi?id=43713应该可以帮到你。这基本上建议您使用msbuild而不是xbuild。
如果无法做到这一点,请改用
答案 2 :(得分:0)
使用.NET CLI 2的Visual Studio和.NET Core Tooling不完全支持引用程序集。您需要打包库并使用对soltuion的项目引用。原因是在编译期间解析了其版本所需的assmeblies,然后写入JSON文件。在加载zour库程序集时,这可能会失败,因为它们无法找到正确的程序集或依赖项。