让PCL,Mvvmcross,Nuget和Xamarin Studio在Mac上玩"好"

rev*_*.lt 9 xamarin.ios xamarin.android mvvmcross xamarin-studio

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

<file src="_._" target="lib\portable-win+net45+MonoAndroid16+MonoTouch40+sl40+wp71\_._" />.
Run Code Online (Sandbox Code Playgroud)

我知道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?

感谢您的见解.

rev*_*.lt 16

更新:如果您使用的是Xamarin Studio的Alpha通道,则不再需要从Windows复制PCL.您可以使用v4.0,Profile158,这也可以与Async一起使用.

更新:我在本文中添加了有关如何在PCL中使用异步的说明:Xamarin Studio Mac,可移植类库,Async和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>
Run Code Online (Sandbox Code Playgroud)

到.csproj,使用Nuget添加包并将TargetFrameworkVersion设置回v1.0.

我已经验证了Visual Studio中的行为.有一个项目使用TargetFramework MonoTouch,Version = v4.0被报告给Nuget插件.这就是为什么相同的包在Visual Studio上工作而不在Xamarin Studio Mac上.我想这应该纠正一致.

脚步

Xamarin工作室

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

将.NETPortable安装到Mono.Framework中

  1. 将.NETPortable(C:\ Program Files(x86)\ Reference Assemblies\Microsoft\Framework.NETPortable)文件夹从Windows PC复制到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
Run Code Online (Sandbox Code Playgroud)

如果你打开它,请重新启动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))

Run Code Online (Sandbox Code Playgroud)

  • 截至今天,通过首先添加mrward的存储库然后安装nuget addin添加了nuget addin,我能够将目标切换到p49并直接添加HotTuna包. (2认同)