There's no need to script this. Both the ruleset and dictionary can be registered via an imported MSBuild .props
file, as described here https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#include-msbuild-props-and-targets-in-a-package
For example, your NuGet source folder structure might look like this (assuming "CodeAnalysisSettings" is your package ID):
- build
- CodeAnalysisSettings.props
- content
- MyCustomDictionary.xml
- MyRules.ruleset
where the contents of CodeAnalysisSettings.props
are something like the following:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<RunCodeAnalysis>true</RunCodeAnalysis>
<CodeAnalysisRuleSet>MyRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="MyCustomDictionary.xml" />
</ItemGroup>
</Project>