sdk
sdk copied to clipboard
`dotnet list package` fails when dependency is in TargetFramework matching condition
Describe the bug
dotnet list package will fail when a PackageReference is included based on evaluation of the TargetFramework value.
To Reproduce
dotnet new globaljson --sdk-version "7.0.401" # (I tested on 7.0.401 and 8.0.100-rc.2.23502.2)
dotnet new maui
dotnet restore; dotnet list package
The above works as expected. Now open the new .csproj file, and add a package reference that will only be included if the TargetFramework is net7.0-android:
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0-android'">
<PackageReference Include="Xamarin.GooglePlayServices.Location" Version="121.0.1.1" />
</ItemGroup>
Save the file, run dotnet restore; dotnet list package, it will fail with the following output:
Unable to read a package reference from the project `/private/tmp/test-dotnet/test-dotnet.csproj`. Please make sure that your project file and project.assets.json file are in sync by running restore.
Exceptions (if any)
No C# exceptions, but the above error message is encountered despite dotnet restore happening immediately before.
Further technical details
- Include the output of
dotnet --info
% dotnet --info
.NET SDK:
Version: 8.0.100-rc.2.23502.2
Commit: 0abacfc2b6
Runtime Environment:
OS Name: Mac OS X
OS Version: 13.5
OS Platform: Darwin
RID: osx-arm64
Base Path: /Users/junlin/dotnet/sdk/8.0.100-rc.2.23502.2/
.NET workloads installed:
[maui]
Installation Source: SDK 8.0.100-rc.2
Manifest Version: 8.0.0-rc.2.9373/8.0.100-rc.2
Manifest Path: /Users/junlin/dotnet/sdk-manifests/8.0.100-rc.2/microsoft.net.sdk.maui/8.0.0-rc.2.9373/WorkloadManifest.json
Install Type: FileBased
Host:
Version: 8.0.0-rc.2.23479.6
Architecture: arm64
Commit: 0b25e38ad3
.NET SDKs installed:
7.0.401 [/Users/junlin/dotnet/sdk]
8.0.100-rc.1.23463.5 [/Users/junlin/dotnet/sdk]
8.0.100-rc.2.23502.2 [/Users/junlin/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.11 [/Users/junlin/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29 [/Users/junlin/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.0-rc.2.23480.2 [/Users/junlin/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.11 [/Users/junlin/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-rc.1.23419.4 [/Users/junlin/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0-rc.2.23479.6 [/Users/junlin/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
DOTNET_ROOT [/Users/junlin/dotnet]
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
- The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
Not using an IDE, testing only using a user install of dotNET
same for me
Similar problem https://github.com/dotnet/sdk/issues/37193
Similar problem #37193
Which was unceremoniously closed.
We also have a setup that makes this tool fail.
FWIW, dotnet-outdated seems to cope just fine with our dependency specifications.
Same here. And this is a regression; it worked with .NET 6 SDK.
Trying to sort out Nuget packages in project - and came across this bug. Still happening for .Net 9 SDK
Confirmed still an issue, able to repro (.NET 9)
I have met same issue on macOS and solved.
With dotnet v9.0.301, it accepts newer word order, package add.
If adding package by dotnet package add (not dotnet add package), dotnet list package won't work.
Adding package by dotnet add package instead will solve the problem.
I recently ran into a similar issue, but I was able to find a workaround.
When you have a condition like the one below, dotnet list package fails
<PackageReference Include="Xamarin.AndroidX.Credentials" Version="1.5.0.1" Condition="'$(TargetFramework)' == 'net9.0-andorid'" />
However, if you invert the logic and use a condition with "not equal" for other target frameworks, it magically works:
<PackageReference Include="Xamarin.AndroidX.Credentials" Version="1.5.0.1" Condition="'$(TargetFramework)' != 'net9.0' and '$(TargetFramework)' != 'net9.0-ios'" />