【问题标题】:Getting PCL, Mvvmcross, Nuget and Xamarin Studio to play "nice" on Mac让 PCL、Mvvmcross、Nuget 和 Xamarin Studio 在 Mac 上玩得“不错”
【发布时间】:2013-07-13 06:09:29
【问题描述】:

查看 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?

感谢您的见解。

【问题讨论】:

  • 清除 Xamarin 和 Mono.Framework 后,文件夹 /Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable/ 消失了。我不确定它最初来自哪里。我可能只是从 Windows 复制了它,但我很确定我没有修改内容。
  • 以上内容适用于 Mac 上 Xamarin Studio 上的便携式库和 Android 项目。
  • 您是如何获得 .NETPortable 的。我也错过了那个文件夹。
  • /Library/Frameworks/Mono.framework/External/xbuild-frameworks/.NETPortable/ 是我从 Windows 复制到的路径,不确定其中一个 Alpha 或 Beta 是否曾在该文件夹中安装过 PCL . Alpha 版本在 /Library/Frameworks/Mono.framework//Versions/3.2.2/lib/mono/xbuild-frameworks/.NETPortable/ 下提供 PCL
  • 谢谢我看错了文件夹。 Alpha 3.2.2 确实安装了 .NETPortable 文件夹,尽管它缺少我从 Windows 复制的 104。现在我必须撤消所有操作并安装 nuget。 ;)

标签: xamarin.ios xamarin.android mvvmcross xamarin-studio


【解决方案1】:

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

【讨论】:

  • 准确。换句话说,在 IDE 中,添加一个 Portable Class 项目,然后在目标列表框中,选择与 4.5 而不是 4.0 相关联的配置文件,并且与您需要的平台相关联。很棒的东西。
  • 如果您在 Mac 上使用 Mono 3.2.* 或更高版本和 NuGet 插件 0.7 或更高版本,则无需自己修补 NuGet.Core。
【解决方案2】:

更新:如果您使用 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 工作室

  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 附带此文件夹!!!)(@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。

测试一下!

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

【讨论】:

  • 的帖子很棒。几点注意事项:如果您在安装 nuget 之前已经在运行 Xamarin Studio Alpha,那么这样做会遇到麻烦。所以首先降级到稳定,安装 nuget 然后切换到 Alpha 通道。再说一遍 - 如果你还没有安装 nuget,你只需要这样做。
  • 我切换到 Alpha 通道并升级到 4.1.11(内部版本 10)。但是,当我打开一个新的 PCL 项目并转到常规选项卡时,它会显示“未安装 Profile136 框架”。
  • 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
  • 有谁知道nuget补丁是否仍然需要?
  • 到今天为止,通过先添加mrward的存储库然后安装nuget插件来添加nuget插件,我能够将目标切换到p49并直接添加HotTuna包。
猜你喜欢
  • 1970-01-01
  • 2016-11-25
  • 1970-01-01
  • 2013-07-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多