如何在 Visual Studio for Mac 中设置 AutoGenerateBindingRedirects?

use*_*030 11 csproj xamarin.forms visual-studio-mac

我目前正在开发一个名为 ABCD 的 Xamarin.Forms 项目,使用 macOS Sierra v10.12.6 和 Visual Studio (VS) for Mac v7.3.2(此处详细介绍了设置步骤)。

成功设置后,我继续如下:

  • 右键单击主项目文件夹,我选择Options

  • Build 下,在General下,在Target Framework 下.NET Portable: PCL 4.5 - Profile111已为我自动选择。

  • 我将其切换到其正上方的选项:.NET Standard Platform: netstandard1.5 ; 然后选择确定

  • 切换这个框架后,我重建项目。重建后,出现警告:

警告 MSB3276:发现同一依赖程序集的不同版本之间存在冲突。请在项目文件中将“AutoGenerateBindingRedirects”属性设置为 true。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=294190。(MSB3276) (ABCD.iOS)

  • 所以这可能是因为NETStandard.Library包已经过时了。

  • 在主Packages文件夹中,右键单击NETStandard.Library 会显示版本1.6.0,但在终端中键入dotnet --version 会显示2.1.3,因此我在 VS 中更新NETStandard.Library - 接受出现的许可证。

  • 重建后相同的警告仍然存在。

  • 所以我转到警告提供的 Microsoft 链接并按照他们的说明添加<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>到各种 .csproj 文件中。

  • 我将此添加到主 .csproj 文件中,重建项目并收到相同的警告。

  • 我将此添加到 iOS 和 Android .csproj 文件中,重建项目并收到相同的警告。

那么这是什么问题,为什么会如此顽固,如果我不理会它会给我带来多大的麻烦?

Ran*_*man 10

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

我的经验是,我们需要<AutoGenerateBindingRedirects>成为true

我的开发环境:

  • macOS Mojave 10.14.2 (18C54)
  • VisualStudio for Mac 专业版 7.7.4(内部版本 1)

#解决方案:

我所做的是按照以下 MS Doc(链接)中给出的说明进行操作。

  1. MyBeautifulApp.Xamarin.iOS.csproj从 Visual Studio Xamarin Forms 解决方案中卸载。
  2. MyBeautifulApp.Xamarin.iOS.csproj使用 TextEdit 手动编辑文件,并将以下行添加 <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    到与您尝试构建并出现错误的构建配置相关的 PropertyGroup。
  3. 保存.csproj文件。然后关闭文件并在 VS 解决方案资源管理器中重新加载项目。
  4. 然后清理并尝试构建,它应该成功构建而不会给出任何警告或错误。-----> 对我来说这有效。

注意:我只编辑了.csprojXamarin.Forms iOS App 项目的文件。因为 Xamarin.Forms 解决方案中的 Android 项目已经成功构建。

MyBeautifulApp.Xamarin.iOS.csproj手动编辑我的文件后,它看起来如下所示:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{asdf-7AC6-asdf-9890-asdf}</ProjectGuid>
    <ProjectTypeGuids>{asdfasd-340asdf5-455asdfC-asdf-asdf};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <TemplateGuid>{6143fdea-f3c2-4a09-aafa-6e230626515e}</TemplateGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>MyBeautifulApp.Xamarin.iOS</RootNamespace>
    <IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
    <AssemblyName>MyBeautifulApp.Xamarin.iOS</AssemblyName>
    <MtouchHttpClientHandler>NSUrlSessionHandler</MtouchHttpClientHandler>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
    **<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>**
  </PropertyGroup>
  <PropertyGroup>
  ....For another build configuration related property group...
Run Code Online (Sandbox Code Playgroud)

更多信息:现在我的问题是我是否应该对与其他 Build 配置相关的 .iOS.csproj 文件的所有其他 PropertyGroup 进行此更改?我很高兴从外面的人那里知道。但现在我决定不碰那些,直到它在未来给我一个警告/错误。

希望这对那里的任何人都有帮助。


use*_*030 3

最后修复了这个警告,而且解决方案相当违反直觉。

尽管警告特别指出“请在项目文件中将“AutoGenerateBindingRedirects”属性设置为 true”,但只有更改<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects><AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>.