更新:如果您正在使用Xamarin Studio的Alpha版本,则无需从Windows复制PCL。您可以使用v4.0,Profile158,这也可以与Async开箱即用。
更新:我在这篇文章中添加了有关如何在PCL中使异步工作的说明:
Xamarin Studio Mac,Portable class library, Async and Android,因此如果您想在PCL中使用异步,请在阅读本文后前往该网站。
解决我在Mvvm+PCL+Xamarin Studio on Mac上遇到的问题的一种可行的方法。请参见下面的详细信息。
The steps below make things work for Android and PCL projects. For iOS projects Xamarin Studio on Mac is communicating a TargetFramework of MonoTouch,Version=v1.0 to Nuget. Since the mvvm packages contain +MonoTouch40 Nuget refuses to install the packages on the project. A workaround is to add
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
to the .csproj, add the packages with Nuget and set TargetFrameworkVersion back to v1.0.
I have verified the behaviour in Visual Studio. There a project with TargetFramework MonoTouch,Version=v4.0 is reported to the Nuget plugin. This is why the same packages work on Visual Studio an not on Xamarin Studio Mac. I guess this should be corrected to be consistent.
步骤
Xamarin Studio
- 确保在Mac上使用Beta或Alpha渠道的Xamarin Studio
- 安装Nuget软件包管理器:Xamarin Studio / Add-In Manager
将.NETPortable安装到Mono.Framework中
- 从Windows PC复制.NETPortable文件夹(C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable)到您的Mac上
- 将其放置在/Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable/下(请确保不要覆盖已有文件夹,以防这个文件夹已经随Xamarin Studio一起发布!!!)(也可以看看这里)
修补Nuget
一个修补过的分支可以在这里找到:https://nuget.codeplex.com/SourceControl/network/forks/takoyakich/nuget/latest,选择2.7分支。如果您想自己打补丁:
git clone https://git01.codeplex.com/nuget
cd nuget
git checkout -b 2.7 origin/2.7
patch -p1 < {patch file saved from below}
cd src/Core
xbuild
cp bin/Debug/NuGet.Core.dll ~/Library/Application\ Support/XamarinStudio-4.0/LocalInstall/Addins/MonoDevelop.PackageManagement.0.6/NuGet.Core.dll
如果您已经打开了Xamarin Studio,请重新启动它。
测试一下!
- 打开Xamarin Studio
- 创建一个新的可移植库
- 在项目上,转到选项,构建/常规,您应该看到一个对话框,让您选择目标框架(例如.net45 + wp8对应于Profile49)
- 转到引用,管理Nuget包,添加Mvvmcross
- 从这里遵循@slodge的出色n + 1 mvvmcross教程视频之一...
Nuget.Core.dll的补丁:
diff --git a/src/Core/NETPortable/NetPortableProfileTable.cs b/src/Core/NETPortable/NetPortableProfileTable.cs
index 6f6a9ff..edc710c 100644
--- a/src/Core/NETPortable/NetPortableProfileTable.cs
+++ b/src/Core/NETPortable/NetPortableProfileTable.cs
@@ -49,16 +49,12 @@ namespace NuGet
private static NetPortableProfileCollection BuildPortableProfileCollection()
{
var profileCollection = new NetPortableProfileCollection();
- string portableRootDirectory =
- Path.Combine(
- Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86, Environment.SpecialFolderOption.DoNotVerify),
- @"Reference Assemblies\Microsoft\Framework\.NETPortable");
-
+ string portableRootDirectory = GetPortableRootDirectory ();
if (Directory.Exists(portableRootDirectory))
{
foreach (string versionDir in Directory.EnumerateDirectories(portableRootDirectory, "v*", SearchOption.TopDirectoryOnly))
{
- string profileFilesPath = versionDir + @"\Profile\";
+ string profileFilesPath = Path.Combine(versionDir,"Profile");
profileCollection.AddRange(LoadProfilesFromFramework(profileFilesPath));
}
}
@@ -66,6 +62,22 @@ namespace NuGet
return profileCollection;
}
+ private static string GetPortableRootDirectory()
+ {
+ if (IsMonoOnMac ()) {
+ return "/Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable";
+ }
+ return Path.Combine(
+ Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86, Environment.SpecialFolderOption.DoNotVerify),
+ @"Reference Assemblies\Microsoft\Framework\.NETPortable");
+ }
+
+ static bool IsMonoOnMac ()
+ {
+ // Environment.OSVersion.Platform returns UNIX, didn't find a better way :-(
+ return File.Exists ("/System/Library/CoreServices/Finder.app/Contents/MacOS/Finder");
+ }
+
private static IEnumerable<NetPortableProfile> LoadProfilesFromFramework(string profileFilesPath)
{
if (Directory.Exists(profileFilesPath))