xamarin 重新Map组件不起作用

bweufnob  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(161)

I am getting the MSB3277 error code when I am building my project in VS2015 RC. The full message is:
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3277: Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
So I did that, I changed my output to detailed to see what is going on.
My app.config looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Primitives" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
        <bindingRedirect oldVersion="3.9.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

A more detailed errors comes along:
2> Consider app.config remapping of assembly "System.Net.Primitives, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "3.9.0.0" [] to Version "4.0.0.0" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Net.Primitives.dll] to solve conflict and get rid of warning.
On the app.config bindings, I have tried both 0.0.0.0-4.0.0.0 as oldVersion and specifying an exact oldVersion , but both result in the same way.
When I go to properties of the System.Net.Http.Primitives it says:

  • Runtime version: v4.0.30319
  • Version: 1.5.0.0

It is a Xamarin project, if that matters anyhow.

kninwzqo

kninwzqo1#

当你有不同版本的这个相同的NuGet时,程序集绑定是一场噩梦。当我遇到类似的问题时,我使用三种方法。

  1. NuGet软件包的合并。如果可能,安装最新的和缺少的。
    1.从代码中删除所有“assemblyBinding”部分,并重新安装所有NuGet包,以获得当前安装的干净版本。
    1.使用自定义的MSBuild任务来解决这个问题,但您确实不想使用它。如果您可以将项目迁移到.NET核心库或仅迁移到.NET SDK,那么就去做吧。我不得不强制重新Map所有项目,因为我有100多个与旧的.NET Framework绑定的项目,我不能轻松地迁移它们。维护是一场噩梦,所以我创建了一个基于MSBuild的任务。
    第一个
    来自csproj:
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  
  <ItemGroup>
    <PackageReference Include="Microsoft.Build.Tasks.Core" Version="16.4.0" />
  </ItemGroup>

  <UsingTask TaskName="RemoveRuntimeNode" AssemblyFile="$([MSBuild]::ValueOrDefault('$(YourLibPath)', '$(MSBuildThisFileDirectory)..\lib\netstandard2.0\YourNamespace.Sdk.dll'))" />

  <UsingTask TaskName="GenerateConfigBindingRedirects" AssemblyFile="$([MSBuild]::ValueOrDefault('$(YourLibPath)', '$(MSBuildThisFileDirectory)..\lib\netstandard2.0\YourNamespace.Sdk.dll'))" />

  <Target Name="RemoveConfigRuntimeNode" BeforeTargets="ResolveAssemblyReferences" Condition="Exists('$(MSBuildProjectDirectory)\app.config')">
    <RemoveRuntimeNode ConfigFilePath="$(MSBuildProjectDirectory)\app.config" />
  </Target>

  <Target Name="GenerateConfigBindingRedirects" AfterTargets="RemoveConfigRuntimeNode" Condition="Exists('$(MSBuildProjectDirectory)\app.config')">
    <GenerateConfigBindingRedirects ConfigFilePath="$(MSBuildProjectDirectory)\app.config" SuggestedBindingRedirects="@(SuggestedBindingRedirects)"/>
  </Target>
</Project>

相关问题