belav / csharpier

CSharpier is an opinionated code formatter for c#.
https://csharpier.com
MIT License
1.43k stars 99 forks source link

`CSharpier_FrameworkVersion` is unreliable #1027

Closed Tyrrrz closed 1 year ago

Tyrrrz commented 1 year ago

I don't have .NET 7.0 SDK installed anymore, since I've moved my projects off to .NET 8.0. CSharpier_FrameworkVersion sometimes incorrectly resolves to .NET 7.0 due to unreliable heuristics:

https://github.com/belav/csharpier/blob/ef795385ba4b83a0b61a56287fd380cc63000dee/Src/CSharpier.MsBuild/build/CSharpier.MsBuild.targets#L3-L4

The two most common scenarios are:

In either of these cases, CSharpier resolves to the .NET 7.0 version of the tool, which may not be able to execute (as in my case).

My suggestion is to not rely on the TargetFramework property for this, but instead use the current SDK version, which can be extracted from the NETCoreSdkVersion property, as defined by one of the built-in imports.

image

domn1995 commented 1 year ago

I believe I'm running into this issue in my source generator project. Here's the build output if it helps: https://github.com/domn1995/dunet/actions/runs/6900832597/job/18802795139?pr=187

belav commented 1 year ago

I believe I'm running into this issue in my source generator project. Here's the build output if it helps: https://github.com/domn1995/dunet/actions/runs/6900832597/job/18802795139?pr=187

That sounds like a problem with the nuget package not being restored correctly, I don't think I've seen that. I know one of the net8 RC's had some issues around restoring tools, but it looks like you are on the official release.