Home: Multitargeted iOS/Android - Duplicate frameworks found: 'net5.0, net5.0'

Created on 27 Oct 2020  路  9Comments  路  Source: NuGet/Home

Details about Problem

A multi-targed iOS/Android project:

<TargetFrameworks>net5.0-android;net5.0-ios</TargetFrameworks>

dotnet build fails with:

/Users/runner/.dotnet/sdk/5.0.100-rtm.20509.5/NuGet.targets(131,5): Invalid restore input. Duplicate frameworks found: 'net5.0, net5.0'. Input files: /Users/runner/work/1/s/HelloForms/HelloForms.csproj. [/Users/runner/work/1/s/net6-samples.sln]
NuGet.Commands.RestoreSpecException: Invalid restore input. Duplicate frameworks found: 'net5.0, net5.0'. Input files: /Users/runner/work/1/s/HelloForms/HelloForms.csproj.
   at NuGet.Commands.SpecValidationUtility.ValidateFrameworks(PackageSpec spec, IEnumerable`1 files)
   at NuGet.Commands.SpecValidationUtility.ValidateProjectSpecPackageReference(PackageSpec spec, IEnumerable`1 files)
   at NuGet.Commands.SpecValidationUtility.ValidateProjectSpec(PackageSpec spec)
   at NuGet.Commands.SpecValidationUtility.ValidateDependencySpec(DependencyGraphSpec spec, HashSet`1 projectsToSkip)
   at NuGet.Commands.DependencyGraphSpecRequestProvider.GetRequestsFromItems(RestoreArgs restoreContext, DependencyGraphSpec dgFile)
   at NuGet.Commands.DependencyGraphSpecRequestProvider.CreateRequests(RestoreArgs restoreContext)
   at NuGet.Commands.RestoreRunner.CreatePreLoadedRequests(RestoreArgs restoreContext)
   at NuGet.Commands.RestoreRunner.GetRequests(RestoreArgs restoreContext)
   at NuGet.Commands.RestoreRunner.RunAsync(RestoreArgs restoreContext, CancellationToken token)
   at NuGet.Build.Tasks.BuildTasksUtility.RestoreAsync(DependencyGraphSpec dependencyGraphSpec, Boolean interactive, Boolean recursive, Boolean noCache, Boolean ignoreFailedSources, Boolean disableParallel, Boolean force, Boolean forceEvaluate, Boolean hideWarningsAndErrors, Boolean restorePC, Boolean cleanupAssetsForUnsupportedProjects, ILogger log, CancellationToken cancellationToken)
   at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log)

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): dotnet

NuGet version (x.x.x.xxx): .NET 5.0.100-rtm.20509.5

dotnet.exe --version (if appropriate): 5.0.100-rtm.20509.5

OS version (i.e. win10 v1607 (14393.321)): macOS 10.15.7 (macOS-latest image on Azure DevOps)

Worked before? If so, with which NuGet version:

It works on my local Mac, but not on Azure DevOps.

Detailed repro steps so we can see the same problem

Context: https://github.com/xamarin/net6-samples/pull/39

  1. Install:
  1. Clone, and build the peppers/workload branch:

https://github.com/xamarin/net6-samples

dotnet build

Other suggested things

Verbose Logs

Attached a failing vs working .binlog: logs.zip

Sample Project

https://github.com/xamarin/net6-samples - the peppers/workload branch.

/cc @dsplaisted

NewFrameworks Bug

Most helpful comment

I've sent a PR to the SDK which should fix the error message here: https://github.com/dotnet/sdk/pull/14374

All 9 comments

@zkat @aortiz-msft - i repro with dotnet build on an RC2 build which includes 5.8.0.6860.
i also repro using 'msbuild restore' using 16.8.0-preview-20513-... which includes 5.8.0.6896
filer found it in an rtm build of dotnet.

my steps... dotnet new classlib
replace targetframework with:
<TargetFrameworks>net5.0-android;net5.0-ios</TargetFrameworks>
dotnet build
expected: happy
actual: duplicate TFM error

//cc: @zivkan @nkolev92

if i change the ios one to net5.0-ios12, then my errors complain:

C:\Program Files\dotnet\sdk\5.0.100-rc.2.20479.15\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(109,5): error NETSDK1139: The target platform identifier android was not recognized. [C:\temp\n5\n5.csproj]
C:\Program Files\dotnet\sdk\5.0.100-rc.2.20479.15\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(109,5): error NETSDK1139: The target platform identifier ios was not recognized. [C:\temp\n5\n5.csproj]

Can we get a bin log from restore?

The SDK is supposed to translate the targetframework into different properties, TargetFrameworkMoniker and TargetPlatformMoniker.

On another note, the ios/android target platforms aren't supported with GA, so maybe that's what you are hitting.

Looking at the binlogs, it looks like the Azure DevOps build is not importing the iOS and Android workloads. Probably in this case the restore error is pre-empting the error you would get telling you that the workloads need to be installed.

So I suspect that the workloads aren't being installed, or are not being installed correctly, in Azure DevOps.

EDIT: Even without the workloads installed, I'm not sure why NuGet seems to think both of the TargetFrameworks are equivalent to net5.0. So there may also be a NuGet issue here somewhere.

I missed the fact that there was already a binlog.

Gonna look at it quickly.

@dsplaisted

If you look at the failing log and search TargetFrameworkInformation, you'd see the props NuGet reads.

The TargetPlatformIdentifier is set, but not the moniker.
stuff

Looks like the issue causing the restore failure is because the SDK doesn't set the TargetPlatformMoniker if the TargetPlatformVersion isn't set:

https://github.com/dotnet/sdk/blob/8514b0cea454c4db082fedc11d349612fed40183/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets#L1038

We probably need to set the TargetPlatformMoniker in this case, so that restore will succeed and we can generate the error message that the required workloads aren't installed.

Ok, I think the workloads are probably installed to a different folder than the dotnet being used during the build. 馃う

I鈥檒l look into this tomorrow, I think the only issue here is the error message needs to say X and Y workloads are not installed.

https://github.com/xamarin/net6-samples/pull/39 works now, we can close this.

The problem was we were installing .NET 5 to ~/.dotnet/, which was the default location on Azure DevOps. The workload installers expect /usr/local/share/dotnet/ right now.

I've sent a PR to the SDK which should fix the error message here: https://github.com/dotnet/sdk/pull/14374

Was this page helpful?
0 / 5 - 0 ratings