dotnet / format

Home for the dotnet-format command
MIT License
1.92k stars 172 forks source link

Versioning and support of framework? #2027

Closed Herve-M closed 5 months ago

Herve-M commented 8 months ago

Little question related to dotnet-format and framework version: should we use specific version of dotnet-format related to major version of framework?

Like:

Edit: If it would be the case, 4.1.X is for which framework?

JoeRobich commented 8 months ago

I would not try and match versions in this way. The version of dotnet-format which ships in your .NET SDK should be able to load your SDK projects regardless of which tfm you target.

If you are having issues with projects loading, please open an issue with details.

Herve-M commented 8 months ago

The version of dotnet-format which ships in your .NET SDK should be able to load your SDK projects regardless of which tfm you target.

Sadly, for project using global.json over legacy/eol LTS like .NET 3.1 it requires to install a global version using dnceng feeds which is problematics in CI env. where multiple TFM projects works ex: .NET 3.1, .NET 6, .NET 7; and for .NET 6 and onwards the matching of version is enforced by global.json file.

This would mean to that our script / task need to detect the current version of .NET over the working-dir and adapt the exec. target? Like dotnet format for .NET 6 / 7/ 8 and dotnet-format for .NET 3.1 and lower.

Otherwise, is the latest 8.x version capable to work over EOL/Legacy .NET Core and .NET Framework 4.8? If yes, this could simplify a lot.

sharwell commented 5 months ago

Hi @Herve-M,

I'm not sure I understand your question. Can you clarify?

Thanks!

ghost commented 5 months ago

Closing this issue as we've seen no reply to the request for more information. If you are able to get the requested information, please add it to the issue and we will retriage it.

Herve-M commented 4 months ago

@sharwell JoeRobich answer state we should let the .NET SDK find the good version, but it doesn't work for older project under .NET 5 included and .NET Framework 4.X.

In this case the only way to use dotnet-format is to use the dev. version from dnceng feeds which contradict the answer too, because it means using a unique version for any kind of TFM.

JoeRobich commented 4 months ago

@Herve-M Seems like there may be a couple different questions so I will answer the easiest one first.

it doesn't work for older project ... .NET Framework 4.X.

Loading .NET Framework projects isn't a supported scenario for dotnet-format. You could likely perform whitespace formatting by using the --folder options. Something like dotnet format whitespace --folder ./path-to-framework-source.

is the latest 8.x version capable to work over EOL/Legacy .NET Core

Newer SDKs will produce a warning when building projects targeting out-of-support TFMs, but this does not break dotnet-format's project loading. I tested the current 8.x SDK release against projects targeting net5.0 and netcoreapp3.1 with no issue.

Herve-M commented 4 months ago

Loading .NET Framework projects isn't a supported scenario for dotnet-format.

This is undocumented sadly but still working in general except legacy ASP .NET csproj, but using file filtering/selection should work as no csproj reading/loading is involved.

Newer SDKs will produce a warning when building projects targeting out-of-support TFMs

Never saw a warning, scoped to a project with a global.json tied to 3.1 and using global dotnet-format 8.X

λ dotnet-format --version
8.0.453106+2651752953c0d41c8c7b8d661cf2237151af33d0
 λ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.426
 Commit:    e81f6c8565
λ dotnet-format.exe template.sln --verify-no-changes -v diag
  The dotnet runtime version is '8.0.2'.
  The dotnet CLI version is '3.1.426'.
  Using MSBuild.exe located in 'C:\Program Files\dotnet\sdk\8.0.200\'.
  Formatting code files in workspace 'C:\Users\{me}\source\repos\{repos}\branches\eol-net3\template.sln'.
  Loading workspace.
    Determining projects to restore...
  All projects are up-to-date for restore.
λ dotnet-format.exe src\erpapi31\erpapi31.csproj --verify-no-changes -v diag
  The dotnet runtime version is '8.0.2'.
  The dotnet CLI version is '3.1.426'.
  Using MSBuild.exe located in 'C:\Program Files\dotnet\sdk\8.0.200\'.
  Formatting code files in workspace 'C:\Users\{me}\source\repos\{repo}\branches\eol-net3\src\erpapi31\erpapi31.csproj'.
  Loading workspace.
    Determining projects to restore...
  All projects are up-to-date for restore.
Msbuild failed when processing the file 'C:\Users\{me}\source\repos\{repo}\branches\eol-net3\src\erpapi31\erpapi31.csproj' with message: C:\Users\{me}\.nuget\packages\microsoft.codeanalysis.netanalyzers\7.0.4\build\Microsoft.CodeAnalysis.NetAnalyzers.targets: (593, 5): The .NET SDK has newer analyzers with version '8.0.0' than what version '7.0.4' of 'Microsoft.CodeAnalysis.NetAnalyzers' package provides. Update or remove this package reference.
Msbuild failed when processing the file 'C:\Users\{me}\source\repos\{repo}\branches\eol-net3\src\netstandard20\netstandard20.csproj' with message: C:\Users\{me}\.nuget\packages\microsoft.codeanalysis.netanalyzers\7.0.4\build\Microsoft.CodeAnalysis.NetAnalyzers.targets: (593, 5): The .NET SDK has newer analyzers with version '8.0.0' than what version '7.0.4' of 'Microsoft.CodeAnalysis.NetAnalyzers' package provides. Update or remove this package reference.
Found project reference without a matching metadata reference: C:\Users\{me}\source\repos\{repo}\branches\eol-net3\src\netstandard20\netstandard20.csproj
  Project erpapi31 is using configuration from 'C:\Users\{me}\source\repos\{repo}\.editorconfig'.
  Project erpapi31 is using configuration from 'C:\Users\{me}\source\repos\{repo}\branches\eol-net3\.editorconfig'.
  Project erpapi31 is using configuration from 'C:\Users\{me}\source\repos\{repo}\branches\eol-net3\src\erpapi31\obj\Debug\netcoreapp3.1\erpapi31.GeneratedMSBuildEditorConfig.editorconfig'.
  Project netstandard20 is using configuration from 'C:\Users\{me}\source\repos\{repo}\.editorconfig'.
  Project netstandard20 is using configuration from 'C:\Users\{me}\source\repos\{repo}\branches\eol-net3\.editorconfig'.
  Project netstandard20 is using configuration from 'C:\Users\{me}\source\repos\{repo}\branches\eol-net3\src\netstandard20\obj\Debug\netstandard2.0\netstandard20.GeneratedMSBuildEditorConfig.editorconfig'.
  Complete in 3498ms.
  Determining formattable files.
  Skipping referenced project 'netstandard20'.
  Complete in 207ms.
  Running formatters.
<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\netstandard20\netstandard20.csproj" />
  </ItemGroup>
</Project>
DennisDyallo commented 4 months ago

Sad to see that dotnet format ignores the SDK version specified in the global.json