0

I have been trying to use dotnet format with an .editorconfig but it keeps on failing(details below).

Context:

  • In our repo we want to introduce formatters and linters. I decided to go ahead with .editorconfig approach and thought I could use dotnet format to apply the formatting on the whole repo. I have added simple dotnet rules and have also added stylecop rules in my editorconfig. Few snippets of my editorconfig:
# Microsoft .NET properties
csharp_new_line_before_members_in_object_initializers = false
csharp_preferred_modifier_order = public, private, protected, internal, file, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async, required:suggestion
csharp_style_namespace_declarations = block_scoped:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion
csharp_style_var_elsewhere = false:none
csharp_style_var_for_built_in_types = false:suggestion
dotnet_naming_rule.private_constants_rule.severity = warning
dotnet_naming_rule.private_constants_rule.style = upper_camel_case_style
.
.
# Stylecop analysis
# Special Rules
dotnet_diagnostic.SA0001.severity = warning    # XML comment analysis disabled
dotnet_diagnostic.SA0002.severity = warning    # Invalid settings file

# Spacing Rules
dotnet_diagnostic.SA1000.severity = warning    # Keywords should be spaced correctly
dotnet_diagnostic.SA1001.severity = warning    # Commas should be spaced correctly
  • dotnet format is not working at all. Cmd: dotnet format my\csproj\file -v diag is giving me output like this:
The dotnet runtime version is '8.0.8'.
  The dotnet CLI version is '6.0.425'.
  Using MSBuild.exe located in 'C:\Program Files\dotnet\sdk\6.0.425\'.
  Formatting code files in workspace ...
  Loading workspace.
    Determining projects to restore...
.
Msbuild failed when processing the file 'C:\MySource\Mycsproj' with message: C:\MySource\Mycsproj: (0, 0): There are 2 package sources defined in your configuration. When using central package management, please map your package sources with package source mapping (https://aka.ms/nuget-package-source-mapping) or specify a single package source. The following sources are defined: https://my/company/Repo/nuget/v3/index.json, C:\Program Files\dotnet\library-packs
Msbuild failed when processing the file 'C:\MySource\Mycsproj' with message: C:\MySource\Mycsproj: (0, 0): Package 'Microsoft.Hadoop.Avro 1.5.6' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Msbuild failed when processing the file 'C:\MySource\Mycsproj' with message: C:\MySource\Mycsproj: (0, 0): Package 'Microsoft.Win32 2.0.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Msbuild failed when processing the file 'C:\MySource\Mycsproj' with message: C:\MySource\Mycsproj: (0, 0): Package 'System.Web.Http 4.0.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Msbuild failed when processing the file 'C:\MySource\OtherDependentcsproj' with message: C:\MySource\OtherDependentcsproj: (0, 0): There are 2 package sources defined in your configuration. When using central package management, please map your package sources with package source mapping (https://aka.ms/nuget-package-source-mapping) or specify a single package source. The following sources are defined: https://my/company/Repo/nuget/v3/index.json, C:\Program Files\dotnet\library-packs
Msbuild failed when processing the file 'C:\MySource\OtherDependentcsproj' with message: C:\MySource\OtherDependentcsproj: (0, 0): Package 'Microsoft.Hadoop.Avro 1.5.6' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Msbuild failed when processing the file 'C:\MySource\OtherDependentcsproj' with message: C:\MySource\OtherDependentcsproj: (0, 0): Package 'Microsoft.Win32 2.0.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Msbuild failed when processing the file 'C:\MySource\OtherDependentcsproj' with message: C:\MySource\OtherDependentcsproj: (0, 0): Package 'System.Web.Http 4.0.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Msbuild failed when processing the file 'C:\MySource\EvenOtherDependentcsproj' with message: C:\MySource\EvenOtherDependentcsproj: (0, 0): There are 2 package sources defined in your configuration. When using central package management, please map your package sources with package source mapping (https://aka.ms/nuget-package-source-mapping) or specify a single package source. The following sources are defined: https://my/company/Repo/nuget/v3/index.json, C:\Program Files\dotnet\library-packs
Msbuild failed when processing the file 'C:\MySource\EvenOtherDependentcsproj' with message: C:\MySource\EvenOtherDependentcsproj: (0, 0): Package 'Microsoft.Hadoop.Avro 1.5.6' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Msbuild failed when processing the file 'C:\MySource\EvenOtherDependentcsproj' with message: C:\MySource\EvenOtherDependentcsproj: (0, 0): Package 'Microsoft.Win32 2.0.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Msbuild failed when processing the file 'C:\MySource\EvenOtherDependentcsproj' with message: C:\MySource\EvenOtherDependentcsproj: (0, 0): Package 'System.Web.Http 4.0.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
.
.
Determining formattable files.
Skipping referenced project P1
Skipping referenced project P2
.
  Complete in 222ms.
  Running formatters.
  Running Code Style analysis.
  Determining diagnostics...
  Running 2 analyzers on AdapterConnector.
  Complete in 3483ms.
  Fixing diagnostics...
  Complete in 4ms.
  Analysis complete in 3487ms.
  Running Analyzer Reference analysis.
  Determining diagnostics...
  Complete in 0ms.
  Fixing diagnostics...
  Complete in 0ms.
  Analysis complete in 0ms.
  Complete in 3893ms.
  Formatted 0 of 6 files.
  Format complete in 26428ms.

Can someone please help take a look? Not sure what I am missing here. Few more cmds and their output.

> dotnet --list-sdks
6.0.425 \[C:\\Program Files\\dotnet\\sdk\]
8.0.400 \[C:\\Program Files\\dotnet\\sdk\]

Also I see two Nuget.config files. One is present at the root location of the repo and other is at %AppData\Roaming\Nuget\ folder.

4
  • The error messages seem to be quite clear: you are trying to target Net Standard 2.0, but your dependencies so not support that target. (If this really is a .NET Framework project, then dotnet CLI is generally going to struggle somewhat as it is about .NET Core & newer.) Commented Sep 17, 2024 at 14:04
  • I see. Most (more than 90%) of the projects in my repo target netstandard2.0, others target net6.0. Seems some of the references in the projects(dependencies) are targeting net framework. Is there a way I can use dotnet format here? Or would I need to go other routes like rulesets? Commented Sep 17, 2024 at 14:50
  • You really need to sort out those dependencies.... then likely you'll have less of a problem working on the projects. Commented Sep 17, 2024 at 19:17
  • Got it. Thanks for the help. I will try to sort out the dependencies. Commented Sep 18, 2024 at 7:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.