是否可以使用“ PackageReference”在Xamarin.Android或Xamarin.iOS项目中? [英] Is it possible to use "PackageReference" in Xamarin.Android or Xamarin.iOS projects?

查看:98
本文介绍了是否可以使用“ PackageReference”在Xamarin.Android或Xamarin.iOS项目中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下,Xamarin.iOS和Xamarin.Android项目使用 package.config 文件来管理Nuget依赖项。有关包装参考(PackageReference)的Microsoft页面在项目文件中说:

By default, Xamarin.iOS and Xamarin.Android projects use a package.config file to manage Nuget dependencies. The Microsoft page about Package references (PackageReference) in project files says:


默认情况下,PackageReference用于.NET Core项目,.NET
标准项目和针对Windows 10 Build 15063
(创建者更新)及更高版本的UWP项目。 .NET完整框架项目支持
PackageReference,但当前默认为packages.config。要使用
PackageReference,请将依赖项从packages.config迁移到项目文件
中,然后删除packages.config。

By default, PackageReference is used for .NET Core projects, .NET Standard projects, and UWP projects targeting Windows 10 Build 15063 (Creators Update) and later. .NET full framework projects support PackageReference, but currently default to packages.config. To use PackageReference, migrate the dependencies from packages.config into your project file, then remove packages.config.

我认为对于Xamarin.Android或Xamarin.iOS项目中PackageReference样式的使用尚不清楚。

I think this is not clear about the use of PackageReference style in Xamarin.Android or Xamarin.iOS projects.

我的问题:是否可以在以下版本中使用PackageReference Xamarin.iOS和Xamarin.Android项目?

My question: is it possible to use PackageReference in Xamarin.iOS and Xamarin.Android projects?

推荐答案

是, PackageReference 适用于Xamarin.iOS | Android项目以及适用于Windows或Mac的Visual Studio或通过cmd行(nuget restore或通过msbuild)。

Yes, PackageReference works for Xamarin.iOS|Android projects and in Visual Studio for Windows or Mac or via the cmd-line (nuget restore or via msbuild).

将以下内容添加到 Xamarin.iOS 和/或 Xamarin的顶部。 Android .csproj 文件:

Add the following to the top of your Xamarin.iOS and/or Xamarin.Android .csproj file:

  <PropertyGroup>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  </PropertyGroup>

我当前的步骤是:


  • 复制您的 packages.config 作为备份


    • 用作参考当您在最后一步重新添加软件包时

    • Copy your packages.config as a backup
      • Use it as a reference when you re-add the packages on the last step

      注意:我会通过IDE手动删除软件包,以正确更新项目引用。另外,当在PackageReference附加项之后重新添加它们时,csproj会正确更新(您可以在csproj文本中手动执行此操作,但这很麻烦且容易搞砸)。

      Note: I do the manual package remove one-by-one via the IDE in order to properly update the project references. Also, when re-adding them after the PackageReference additional, the csproj is updated correctly (you can do this manually in the csproj text but it is a pain and easy to screwup).

      这篇关于是否可以使用“ PackageReference”在Xamarin.Android或Xamarin.iOS项目中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆