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

问题描述 投票:3回答:2

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

成功完成后,我继续如下:

  • 右键单击主项目文件夹,选择“选项”。
  • 在Build下,一般情况下,在Target Framework下:.NET Portable:PCL 4.5 - 已经为我自动选择了Profile111。
  • 我将其切换到它上面的选项:.NET标准平台: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链接,并按照他们的instructions<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>添加到各种.csproj文件中。
  • 我将其添加到主.csproj文件中,重建项目并获得相同的警告。
  • 我将此添加到iOS和Android .csproj文件中,重建项目并获得相同的警告。

那么这个问题究竟是什么呢,它为什么如此执着,如果我忽视它会给我带来多大的麻烦呢?

xamarin.forms csproj visual-studio-mac
2个回答
1
投票

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

尽管有警告说“请在项目文件中将”AutoGenerateBindingRedirects“属性设置为true”,但只有将<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>更改为<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>时警告才会消失。


0
投票

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

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

我的开发环境:

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

#解:

我所做的是遵循以下MS Doc(link)中给出的说明。

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

注意:我只编辑了我的Xamarin.Forms iOS App项目的.csproj文件。因为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...

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

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

© www.soinside.com 2019 - 2024. All rights reserved.