Providing a code analysis ruleset to a .net core project through NuGet

后端 未结 1 1364
我寻月下人不归
我寻月下人不归 2021-01-12 18:45

I\'ve run into a problem when upgrading a .NET 4.6 project to .NET Core 2.0. All our projects use a custom StyleCop ruleset which is provided by a NuGet package. The ruleset

1条回答
  •  南笙
    南笙 (楼主)
    2021-01-12 19:06

    The idea is to not try to deploy the file as content but add build logic to the NuGet package.

    Make sure that the package is structured in the following way:

    • build\
    • build\custom.ruleset
    • build\{YourPackageName}.targets (e.g. CustomRuleset.targets)

    This structure causes the .targets file to be automatically imported into the consuming project by convention.

    The .targets file should then contain:

    
      
        $(MSBuildThisFileDirectory)custom.ruleset
      
    
    

    This will cause the project's ruleset property to be overwritten to the location relative to the .targets file.

    Note that this also applies to .net framework projects using the new PackageReference style of NuGet packages (replacement of packages.config) which is opt-in in VS 2017 (15.2+).

    0 讨论(0)
提交回复
热议问题