【问题标题】:Not able to create a Xamarin-component for android Source code无法为 android 源代码创建 Xamarin 组件
【发布时间】:2017-07-27 12:00:54
【问题描述】:

• 我已经使用了命令

xamarin-component.exe package C:\cmp\AndroidComponent\component 

用于创建 Xamarin 组件。在构建示例 android 项目时,它显示以下错误。 (我已经使用命令 xamarin-component.exe package C:\cmp\AndroidComponent\component -verbose 来详细显示错误信息)。

错误信息:

C:\程序文件 (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Bindings.targets(155,2): 错误 MSB3644:框架的参考程序集 未找到“MonoAndroid,Version=v1.0”。要解决此问题,请安装 此框架版本的 SDK 或 Targeting Pack 或重新定位您的 应用到您拥有 SDK 的框架版本 或已安装目标包。请注意,程序集将被解析 来自全局程序集缓存 (GAC) 并将用于代替 参考程序集。因此您的组装可能不正确 针对您想要的框架。 [C:\cmp\AndroidComponent\component\samples\App17\VidyoClientAndroid\VidyoClientAndroid.csproj]

注意:

我能够成功地为 iOS 源代码创建 Xamarin 组件。 • 在为 Android 源代码创建 Xamarin 组件时,从 64 位文件夹(C:\Program Files (x86)\MSBuild\14.0\bin**amd64**\ msbuild.exe "/p:Configuration=Release" "C:\cmp\AndroidComponent\component\samples\App17\App17.sln"...)。 • 构建android 项目时,从路径“C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe”(32 位) 调用msbuild.exe 时构建成功明确的。

【问题讨论】:

标签: android xamarin msbuild nuget


【解决方案1】:

我们遇到了同样的问题;您已经接近正确的答案,而论坛也有正确的答案。

首先让我们看看出错的代码部分(Xamarin.Android.Common.targets;在较新版本的 Xamarin 中,此代码要低得多):

<Target Name="_GetReferenceAssemblyPaths">
<GetReferenceAssemblyPaths
        TargetFrameworkMoniker="$(TargetFrameworkIdentifier),Version=v1.0"
        RootPath="$(TargetFrameworkRootPath)">
    <Output TaskParameter="ReferenceAssemblyPaths" PropertyName="_XATargetFrameworkDirectories" />
</GetReferenceAssemblyPaths>

这里最重要的部分是

$(TargetFrameworkRootPath)

当通过命令行运行 NuGet 时,我们看到它正在使用 64 位 MSBuild 可执行文件:

MSBuild 自动检测:使用来自“C:\Program Files (x86)\MSBuild\14.0\bin\amd64”的 msbuild 版本“14.0”。

(您在上面自己正确识别了这一点)但只是为了让任何跟随的人都清楚。

当您使用 64 位版本的 MSBuild 时,$(TargetFrameworkRootPath) 被定义为 C:\Program Files\Reference Assemblies\Microsoft\Framework 但是 Xamarin 不会将任何 Framework Utilities 安装到该目录;相反,一切都生活在 x86 版本中 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework

当您在线阅读时,很多人通过安装 Visual Studio 2017 解决了这个问题;但这是一个红鲱鱼,它只能工作,因为它导致 NuGet 使用 MSBuild 15,它与 Visual Studio 2017 一起提供,显然不受此错误的影响。

有几种方法可以解决此问题:

  1. 使用可选的 -MSBuildPath 参数还原时告诉 NuGet 使用 x86 MSBuild,如此处所述How Can I Tell NuGet What MSBuild Executable to Use?
  2. 升级到 Visual Studio 2017 以获取 MSBuild 15
  3. 将$(TargetFrameworkRootPath)定义为C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework;这可以随心所欲地完成,最大的锤子是在执行之前将其设置为环境中的环境变量。请注意,如果您不小心,这可能会导致一堆意想不到的副作用。

【讨论】:

    猜你喜欢
    • 2016-01-28
    • 1970-01-01
    • 2013-08-10
    • 2018-08-16
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多