dotnet / cli-migrate

MIT License
9 stars 15 forks source link

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

Open gpresland opened 5 years ago

gpresland commented 5 years ago

Condition

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 commented 4 years ago

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 commented 4 years ago

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

codeaphex commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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>