Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Set AutoGenerateBindingRedirects in Visual Studio for Mac?

I'm currently working on a Xamarin.Forms project named ABCD, using macOS Sierra v10.12.6 and Visual Studio (VS) for Mac v7.3.2 (the set up steps are detailed here).

Having successfully set that up, I continue as follows:

  • Right-clicking the main project folder, I select Options.

  • Under Build, in General, under Target Framework: .NET Portable: PCL 4.5 - Profile111 has been automatically selected for me.

  • I switch this to the option right above it: .NET Standard Platform: netstandard1.5; then select OK.

  • After switching this framework, I rebuild the project. After the rebuild, a warning appears:

Warning MSB3276: Found conflicts between different versions of the same dependent assembly. Please set the "AutoGenerateBindingRedirects" property to true in the project file. For more information, see http://go.microsoft.com/fwlink/?LinkId=294190. (MSB3276) (ABCD.iOS)

  • So maybe this is because the NETStandard.Library package is out-of-date.

  • In the main Packages folder, right-clicking NETStandard.Library says version 1.6.0, but typing dotnet --version into Terminal shows 2.1.3, so I update NETStandard.Library in VS – accept the licenses that come up.

  • Same warning still in place after rebuilding.

  • So I go to the Microsoft link provided by the warning and follow their instructions to add <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> to the various .csproj files.

  • I added this to the main .csproj file, rebuilt the project and got the same warning.

  • I added this to both the iOS and Android .csproj files, rebuilt the project and got the same warning.

So what's this problem, why is it so persistent, and how much trouble will it give me down the road if I just ignore it?

like image 764
user2323030 Avatar asked Jan 02 '18 23:01

user2323030


People also ask

How do I run xamarin forms on Mac?

In Visual Studio for Mac, right-click on the existing Xamarin. Forms solution and choose Add > Add New Project... In the New Project window choose Mac > App > Cocoa App and press Next. Type an App Name (and optionally choose a different name for the Dock Item), then press Next.

How do I enable and disable automatic binding redirection?

Right-click the project in Solution Explorer and select Properties. On the Application page, uncheck the Auto-generate binding redirects option. If you don't see the option, you'll need to manually disable the feature in the project file.

What is automatic binding redirection?

1 use automatic binding redirection. This means that if two components reference different versions of the same strong-named assembly, the runtime automatically adds a binding redirection to the newer version of the assembly in the output app configuration (app. config) file.


2 Answers

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

My experience was that we need <AutoGenerateBindingRedirects> to be true.

My Dev Environment:

  • macOS Mojave 10.14.2 (18C54)
  • VisualStudio for Mac Professional Version 7.7.4 (Build 1)

#Solution:

What I did is followed the instructions as given in following MS Doc(link).

  1. Unload the MyBeautifulApp.Xamarin.iOS.csproj from the Visual Studio Xamarin Forms solution.
  2. Edit the MyBeautifulApp.Xamarin.iOS.csproj file manually using TextEdit and add the following line <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    to the PropertyGroup which is related to your Build Config which you were trying to build and was giving the error.
  3. Save the .csproj file. Then close the file and reload the Project in your VS Solution Explorer.
  4. Then clean and try to build, and it should successfully build without giving any warnings or errors. -----> For me this worked.

Note: I edited the .csproj file of my Xamarin.Forms iOS App project only. Because Android project which was within the Xamarin.Forms solution were already built successfully.

After editing my MyBeautifulApp.Xamarin.iOS.csproj file manually it looked like following:

<?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...

Further More: The question now I have is should I do this change for all the other PropertyGroups of that .iOS.csproj file which are related to other Build configurations? I would be glad to know from someone out there. But for now I have decided not to touch those until it gives me a warning/error in the future.

Hope this will be helpful to anybody out there.

like image 190
Randika Vishman Avatar answered Nov 06 '22 04:11

Randika Vishman


Finally fixed this warning, and the solution was rather counterintuitive.

Despite the warning saying specifically "Please set the "AutoGenerateBindingRedirects" property to true in the project file", the warning will only go away if you change <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> to <AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>.

like image 2
user2323030 Avatar answered Nov 06 '22 03:11

user2323030