在Mac上如何让PCL、Mvvmcross、Nuget和Xamarin Studio协同工作?

9

看到MvvmCross.PortableSupport.3.0.1.nuspec文件,我注意到有以下一行:

<file src="_._" target="lib\portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp71\_._" />.

我知道nuget正在创建一个支持的框架列表 (win+...+sl40+wp71),并且添加此库的项目必须支持其中之一。基本上,它枚举了可以添加此库的项目类型。
现在,如果我尝试将此包安装到具有Profile49的可移植项目中,这将在Windows上工作,因为Windows上的Profile49是net45+wp80。
然而,在Mac上,Profile49是net45+wp80+MonoAndroid10+MonoTouch10。
这意味着带有支持的框架 win+net45+MonoAndroid16+MonoTouch40+sl40+wp71 的nuget包无法安装在Mac上的Profile49项目中,因为有较低版本的框架 (MonoTouch10和MonoAndroid10)。
- mvvmcross方面是否可以使用字符串 portable-win+net45+MonoAndroid+MonoTouch+sl40+wp71?选择特定版本的原因是什么? - 为什么Xamarin附带的配置文件(例如/Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable/v4.5/Profile/Profile49)包括MonoTouch10和MonoAndroid10?
感谢您的见解。

你是怎么恢复.NETPortable文件夹的?我也没有这个文件夹。 - tofutim
我复制的路径是 /Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable/,不确定 Alpha 或 Beta 版本是否曾在该文件夹中安装 PCLs。Alpha 版本将 PCLs 发布在 /Library/Frameworks/Mono.framework//Versions/3.2.2/lib/mono/xbuild-frameworks/.NETPortable/ 下。 - revau.lt
谢谢,我看错文件夹了。Alpha 3.2.2确实安装了.NETPortable文件夹,但缺少104,我从Windows上复制了它。现在我必须撤销所有操作并安装nuget。;) - tofutim
就我个人而言,我使用的是稳定版本,配合Windows和Profile 104的配置文件以及Microsoft.Bcl.Async包。 - revau.lt
你还在使用 alpha 渠道吗?我有一个问题,重新打开项目后 MonoMac 无法被识别。 - tofutim
显示剩余3条评论
2个回答

16
更新:如果您正在使用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

  1. 确保在Mac上使用Beta或Alpha渠道的Xamarin Studio
  2. 安装Nuget软件包管理器:Xamarin Studio / Add-In Manager

将.NETPortable安装到Mono.Framework中

  1. 从Windows PC复制.NETPortable文件夹(C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable)到您的Mac上
  2. 将其放置在/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,请重新启动它。

测试一下!

  1. 打开Xamarin Studio
  2. 创建一个新的可移植库
  3. 在项目上,转到选项,构建/常规,您应该看到一个对话框,让您选择目标框架(例如.net45 + wp8对应于Profile49)
  4. 转到引用,管理Nuget包,添加Mvvmcross
  5. 从这里遵循@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))


这里的帖子很棒。几点说明: 如果您在安装nuget之前已经运行Xamarin Studio Alpha,则可能会遇到问题。因此,请先降级到稳定版本,安装nuget,然后再切换到Alpha通道。 再次强调 - 只有在您尚未安装nuget时才需要执行此操作。 - Frank Caico
我切换到了alpha通道,并升级到了4.1.11(build 10)。然而,当我打开一个新的PCL项目并转到常规选项卡时,它显示“未安装Profile136框架”。 - tofutim
Alpha附带的配置文件如下,请尝试158:find /Library/Frameworks/Mono.framework//Versions/3.2.2/ -type d -name Profile?* |sed 's#.*/##g' Profile136 Profile14 Profile147 Profile158 Profile19 Profile24 Profile37 Profile42 Profile47 Profile5 Profile6 Profile49 Profile7 Profile78 - revau.lt
有人知道NuGet补丁是否仍然必要吗? - tofutim
2
今天,我首先通过添加Mrward的存储库,然后安装NuGet插件来添加NuGet插件,并成功将目标切换到p49并直接添加了HotTuna包。 - Alexy
事实上,我也一样。使用打了补丁的 NuGet.Core.dll 对我来说也不起作用(关于方法未找到...IsReleaseVersion...的某些内容...抱歉,在尝试上面的替代方案之前,我没有捕获精确的文本)。 - jriggins

4

截至2014年2月,上述步骤已不再需要。使用Xamarin Studio 4.3.2 Alpha渠道和nuget插件,先添加mrward的插件库,然后安装nuget插件,即可将目标切换到p49并直接向新的PCL项目中添加HotTuna包。


确切。换句话说,在 IDE 中,您添加一个便携式类项目,然后在目标列表框中选择一个与 4.5 相关联的配置文件,而不是 4.0,并且与您需要的平台相关联。非常棒的东西。 - Léon Pelletier
如果您在 Mac 上使用 Mono 3.2.* 或更高版本以及 NuGet 插件版本 0.7 或更高版本,则无需自行修补 NuGet.Core。 - Matt Ward

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接