This error is caused by a conflict of support mechanisms for the Portable Class Library and the .NET Standard.
The first is in MSBuild\14.0\Bin\Microsoft.NetFramework.CurrentVersion.targets , the second is in MSBuild\Microsoft\Microsoft.NET.Build.Extensions\Microsoft.NET.Build.Extensions.NETFramework.targets . They do the same thing - they add references to "virtual" platform-independent assemblies to the project so that the compiler does not worry about their absence. And since they do the same thing, they add the same links to the assemblies.
In this case, references to PCL are always added, and references to .NET Standard - only in the presence of such dependencies.
If your project does not have references to PCL libraries, then the correct solution would be to write the following key in the project file:
<ImplicitlyExpandDesignTimeFacades>false</ImplicitlyExpandDesignTimeFacades>
This will disable the first mechanism and it will work.
If in the project such dependences are present - then the following error may appear at compile time:
error CS0012: The type 'System.ComponentModel.DataAnnotations.ValidationResult' is defined by an assembly that is not referenced. You can add a reference to assembly 'System.ComponentModel.DataAnnotations, Version = 4.1.0.0, Culture = neutral, PublicKeyToken = b03f5f7f11d50a3a'.
Similar issues are possible with the following builds (they are included in PCL, but not included in .NET Standard):
- System.ComponentModel.Annotations.dll
- System.Reflection.Emit.dll
- System.Reflection.Emit.ILGeneration.dll
- System.Reflection.Emit.Lightweight.dll
- System.Runtime.InteropServices.WindowsRuntime.dll
- System.ServiceModel.Duplex.dll
- System.ServiceModel.Http.dll
- System.ServiceModel.NetTcp.dll
- System.ServiceModel.Primitives.dll
- System.ServiceModel.Security.dll
In this case, instead of solving above, you can try to create a Target like this:
<Target Name="ResolvePCLAndNETStandardConflicts" DependsOnTargets="ImplicitlyExpandDesignTimeFacades;ImplicitlyExpandNETStandardFacades" BeforeTargets="ResolveAssemblyReferences"> <ItemGroup> <ResolvePCLAndNETStandardConflicts_ReferencePathToExclude Include="@(DesignTimeFacadeDirectories)"> <RelativeName>%(_NETStandardLibraryNETFrameworkReference.Filename).dll</RelativeName> </ResolvePCLAndNETStandardConflicts_ReferencePathToExclude> <ReferencePath Remove="@(ResolvePCLAndNETStandardConflicts_ReferencePathToExclude->'%(Identity)%(RelativeName)')" /> </ItemGroup> </Target>