Skip to content

dotnet format should have an implicit call to dotnet restore #848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
aolszowka opened this issue Oct 25, 2020 · 0 comments · Fixed by #1015
Closed

dotnet format should have an implicit call to dotnet restore #848

aolszowka opened this issue Oct 25, 2020 · 0 comments · Fixed by #1015
Labels
Feature Request This issue is requesting an enhancement or new feature
Milestone

Comments

@aolszowka
Copy link

As it says on the tin, dotnet format should probably have an implicit call to dotnet restore or at least document this as a best practice. This would mimic behavior of other dotnet tools such as build, test, and package which will often perform implicit actions (such as restore or even build)

What is especially insidious is that if the package in question is in your NuGet Global Cache you won't realize something is broken until it ends up in the CI (such as GitHub Actions which will spin up a throw away container each time).

Here's the example I encountered:

2020-10-25T00:34:27.6648905Z   Formatting code files in workspace '/home/runner/work/VisualStudioSolutionSorter/VisualStudioSolutionSorter/VisualStudioSolutionSorter.sln'.
2020-10-25T00:34:32.4405953Z   VisualStudioSolutionSorter.Tests/GlobalAssemblyConfiguration.cs(9,12): The type or namespace name 'ParallelizableAttribute' could not be found (are you missing a using directive or an assembly reference?) (CS0246)
2020-10-25T00:34:32.4411366Z   VisualStudioSolutionSorter.Tests/GlobalAssemblyConfiguration.cs(9,12): The type or namespace name 'Parallelizable' could not be found (are you missing a using directive or an assembly reference?) (CS0246)
2020-10-25T00:34:32.4461340Z   VisualStudioSolutionSorter.Tests/GlobalAssemblyConfiguration.cs(9,27): The name 'ParallelScope' does not exist in the current context (CS0103)
2020-10-25T00:34:32.4464640Z   VisualStudioSolutionSorter.Tests/GlobalAssemblyConfiguration.cs(7,7): The type or namespace name 'NUnit' could not be found (are you missing a using directive or an assembly reference?) (CS0246)
.
. TRUNCATED FOR REPORT
.
2020-10-25T00:34:32.4580314Z   Formatted code file '/home/runner/work/VisualStudioSolutionSorter/VisualStudioSolutionSorter/VisualStudioSolutionSorter.Tests/IntegrationTests.cs'.
2020-10-25T00:34:32.4581444Z   Format complete in 4781ms.

This project is using the NUnit Unit Test Framework for its integration testing, this is a pretty popular package (at least on my machine) so it has long lived in my NuGet Global Cache.

To work around this issue perform an explicit restore like so (in GitHub Actions):

      # Restore any NuGet Packages Used by this Project
      - name: Restore Packages
        run: dotnet restore

      # Verify that the code is formatted correctly
      - name: Format Files
        run: dotnet format --fix-style warn --fix-analyzers warn --check

Currently using this version:

    "dotnet-format": {
      "version": "5.0.152301",
      "commands": [
        "dotnet-format"
      ]
    }

Thank you for this amazing tool, this is a goldmine for the CI junkies like myself!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request This issue is requesting an enhancement or new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants