让PCL,Mvvmcross,Nuget和Xamarin Studio在Mac上播放"nice"



查看MvvmCross.PortalSupport.3.0.1.nuspec我注意到有以下行:

<file src="_._" target="libportable-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项目上,因为有更低版本的框架(MonoTouch 10和MonoAndroid10)。

  • 字符串便携式win+net45+MonoAndroid+MonoTouch+sl40+wp71可以在mvvmcross侧使用吗?具体版本的原因是什么?

  • 为什么Xamarin附带的配置文件(例如/Library/Frameworks/Mono.framework/External/xbuild-Frameworks/.NETPortable/v4.5/Profile/Profile49)包括MonoTouch10和MonoAndroid10?

感谢您的真知灼见。

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

更新:我在这篇文章中添加了关于如何让async在PCL中工作的说明:Xamarin Studio Mac、Portable类库、async和Android,所以如果你想在你的PCL中使用async,请在本文之后访问。

这是一种有效的解决方案,我必须在Mac上使用Mvvm+PCL+Xamarin Studio。有关详细信息,请参见下文。

以下步骤使Android和PCL项目正常工作。对于iOS项目,Mac上的Xamarin Studio正在向Nuget传达MonoTouch的TargetFramework,版本=v1.0。由于mvvm包包含+MonoTouch40,Nuget拒绝在项目上安装这些包。解决方法是添加

  <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

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

我已经在Visual Studio中验证了这种行为。有一个使用TargetFramework MonoTouch的项目,版本=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 Assemblys\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

如果你保持Xamarin工作室的开放状态,请重新启动它。

测试一下

  1. 打开Xamarin工作室
  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 AssembliesMicrosoftFramework.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 AssembliesMicrosoftFramework.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))

自2014年2月起,不需要上述步骤。使用Xamarin Studio 4.3.2、Alpha通道和nuget插件,通过先添加mrward的插件库,然后安装nuget插件,我可以将目标切换到p49,并将HotTuna包直接添加到新的PCL项目中。

最新更新