Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

Migration *.cs File Cause Visual Studio Warning CS1591 When XML Doc Enabled #120

Open
gpresland opened this issue Apr 9, 2019 · 5 comments

Comments

@gpresland
Copy link

Condition

  • Visual Studio
  • *.csproj has XML documentation file enabled.

Issue

*.cs migrations files cause Visual Studio to output warnings for rule CS1591 (Missing XML comment for publicly visible type or member 'Type_or_Member').

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs1591

Solutions

Generate *.cs migration files should be prepended with:

#pragma warning disable CS1591
@eavonius
Copy link

eavonius commented Dec 5, 2019

Just noticed this too. Should add after namespace but before class declaration in both the migration and it's partial class (in EF core).

@Ablinne
Copy link

Ablinne commented May 8, 2020

I am annoyed by this too. Unfortunately devs do not seem to be wanting to implement this simple fix: dotnet/efcore#10695

@codeaphex
Copy link

codeaphex commented May 29, 2020

I dont understand the actual reason behind not wanting to implement this.
I can't force me and our devs to include XML comments for public APIs by using TreatWarningsAsErrors, if I use migrations. So I'm either stuck with missing API docs or manually adjusting the migration files.
Is there any proper workaround for this?

@Ablinne
Copy link

Ablinne commented May 30, 2020

Well a Workaround would be to wrap dotnet ef migrations add by a powershell/cmd/bash script that adds the #pragma warning disable CS1591 line to all files in the Migrations folder that don't already have it. Something like

dotnet ef migrations add ...

for f in $(find Migrations -iname '*.cs')
do
  if grep -vq CS1591 $f
  then
      echo "#pragma warning disable CS1591" > tempfile.tmp
      cat $f >> tempfile.tmp
      mv tempfile.tmp $f
  fi
done

(not tested)

@jonny-powell
Copy link

If you have your migrations in their own project, you can solve this with a <CodeAnalysisRuleSet>migrations.ruleset</CodeAnalysisRuleSet> somewhere inside a <PropertyGroup> in the .csproj, and the make the contents of the migrations.ruleset file similar to the following:

<RuleSet Name="Migrations" ToolsVersion="15.0">
    <Rules AnalyzerId="Roslynator.CSharp.Analyzers" RuleNamespace="Roslynator.CSharp.Analyzers">
        <Rule Id="CS1591" Action="None" />
    </Rules>
</RuleSet>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants