Conditional PackageReference version splitting analyzer presence fails
See original GitHub issueIf a project references two different versions of the same package in two different TargetFrameworks, and the package has added or removed a Roslyn analyzer, the analyzer will be added from both versions of the package, even the one where it’s not present.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net472</TargetFrameworks>
<RootNamespace>two_systemtextjson</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="4.7.0" Condition=" '$(TargetFramework)' == 'net472' " />
<PackageReference Include="System.Text.Json" Version="6.0.0-preview.4.21253.7" Condition=" '$(TargetFramework)' == 'net6.0' " />
</ItemGroup>
</Project>
two-systemtextjson on master .NET v6.0.100-preview.5.21302.13 🎯 net6.0;net472
❯ dotnet build
Microsoft (R) Build Engine version 17.0.0-preview-21302-02+018bed83d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored S:\work\two-systemtextjson\two-systemtextjson.csproj (in 135 ms).
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
CSC : error CS0006: Metadata file 'C:\Users\raines\.nuget\packages\system.text.json\4.7.0\analyzers\dotnet\cs\System.Text.Json.SourceGeneration.dll' could not be found [S:\work\two-systemtextjson\two-systemtextjson.csproj]
two-systemtextjson -> S:\work\two-systemtextjson\bin\Debug\net6.0\two-systemtextjson.dll
Build FAILED.
CSC : error CS0006: Metadata file 'C:\Users\raines\.nuget\packages\system.text.json\4.7.0\analyzers\dotnet\cs\System.Text.Json.SourceGeneration.dll' could not be found [S:\work\two-systemtextjson\two-systemtextjson.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.20
Because 4.7.0 of that package didn’t have an analyzer/source generator, the file isn’t found in that package version. The reference is only there because it was found in the other version.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:19 (11 by maintainers)
Top Results From Across the Web
.net - Problems with conditional PackageReference & ...
The dependency version of a package is the version of the project when/if it packed itself. Give it a go, use only project...
Read more >Creating packages
Learn how to create packages in Dart. ... To conditionally import or export, you need to check for the presence of dart:* libraries....
Read more >Writing R Extensions
Such packages cannot be required to check the package: any tests which use them must be conditional on the presence of the package....
Read more >Performance Improvements in .NET 7
NET 7 is fast. Really fast. This post deep-dives into hundreds of performance improvements that contributed to that reality.
Read more >A comparison of the conditional inference survival forest ...
Despite the fact that the CIF survival model has been identified to reduce bias in covariate selection for splitting in survival forest models, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We just ran into this with the newly-introduced analyzer in Microsoft.Extensions.Logging.Abstractions 6.0.0-preview.5.21301.5. We found a fairly easy workaround for this, as long as you don’t actually need the analyzer in the project:
I went ahead and sent a PR to fix this: #18877
Thanks to @ericst for identifying where and what the fix was.
I still would really like to see NuGet fix this class of issue by treating analyzers as a proper asset type, though I recognize that’s a lot more complicated.