更新:如果您使用 Xamarin Studio 的 Alpha 通道,则不再需要从 Windows 复制 PCL。您可以使用 v4.0,Profile158,这也适用于 Async。
更新:我在这篇文章中添加了关于如何让异步在 PCL 中工作的说明:Xamarin Studio Mac, Portable class library, Async and Android,所以如果你想在你的 PCL 中使用异步,请在这篇文章之后去那里。
我必须让 Mvvm+PCL+Xamarin Studio 在 Mac 上工作的问题的一种有效解决方案。详情见下文。
以下步骤可让 Android 和 PCL 项目正常运行。对于 iOS 项目,Mac 上的 Xamarin Studio 将 MonoTouch 的 TargetFramework,Version=v1.0 传递给 Nuget。由于 mvvm 包包含 +MonoTouch40 Nuget 拒绝在项目上安装包。一种解决方法是添加
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
到 .csproj,使用 Nuget 添加包并将 TargetFrameworkVersion 设置回 v1.0。
我已经验证了 Visual Studio 中的行为。有一个 TargetFramework MonoTouch,Version=v4.0 的项目被报告给 Nuget 插件。这就是为什么相同的包适用于 Visual Studio 而不是 Xamarin Studio Mac 的原因。我想这应该更正以保持一致。
步骤
Xamarin 工作室
- 确保在 Mac 下的 Xamarin Studio 中使用 Beta 或 Alpha 通道
- 安装 Nuget 包管理器:Xamarin Studio / Add-In Manager
将 .NETPortable 安装到 Mono.Framework 中
- 将 .NETPortable (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable) 文件夹从 Windows PC 复制到 Mac
- 将它放在 /Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable/ 下(确保不要覆盖已经存在的文件夹,以防 Xamarin Studio 附带此文件夹!!!)(@987654322 @)
补丁 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 's excellent 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))