我构建了一个StyleCop Analyzer nuget包,以在多个团队和项目中共享我的设置。尽管遵循了文档中创建Nuget包的示例,并尝试使用此处的StackOverflow问题来解决问题,但是当我安装nuget包并运行构建时,未报告任何违规情况。
我以前确实使用标准StyleCop Analyzers Nuget程序包,自定义共享规则集和stylecop.json文件来完成此工作。创建nuget程序包时,我使用了相同的stylecop.json和.ruleset文件。
我在.nuspec中尝试了.props和.targets文件的各种组合,但是消除过程却使我无所适从。
这是我的.nuspec文件:
// Watch files
function watchFiles() {
gulp.watch("*.js", gulp.series(scriptsLint, scripts, browserSyncReload));
gulp.watch(["processHTML"], gulp.series(browserSyncReload));
}
//Task Live Reload
function browserSyncFunc(done) {
browserSync.init({
server: './dist',
port: 8080,
ui: {
port: 8081
}
})
done()
};
// BrowserSync Reload
function browserSyncReload(done) {
browserSync.reload();
done();
}
// define complex tasks
const js = gulp.series(scriptsLint, scripts);
const build = gulp.parallel(processHTML,js);
const watch = gulp.parallel(watchFiles, browserSyncFunc /* I'm guessing you meant to use the browserSync function here, not the object */);
这是我的.props文件
<?xml version="1.0" encoding="UTF-8"?>
<package>
<metadata>
<authors>Eric Burcham</authors>
<copyright>Enterprise Products Partners L.P. 2019</copyright>
<dependencies>
<dependency id="StyleCop.Analyzers" version="1.1.118" />
</dependencies>
<description>Standard StyleCop Analyzer Settings from the E-Prod Technical Architecture Group.</description>
<id>StyleCop.Analyzers.Eprod</id>
<license type="expression">MIT</license>
<owners>Enterprise Products Partners L.P.</owners>
<projectUrl>http://tfs/LS/TAG/_git/stylecop-analyzers</projectUrl>
<title>Enterprise Products StyleCop Settings</title>
<version>1.1.3</version>
</metadata>
<files>
<file src="StyleCop.Analyzers.Eprod.props" target="build" />
<file src="StyleCop.Analyzers.Eprod.ruleset" target="RuleSet" />
<file src="stylecop.json" target="Config" />
</files>
</package>
这是我的stylecop.json文件:
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="14.0">
<PropertyGroup>
<CodeAnalysisRuleSetLocation Condition=" '$(NuGetPackageRoot)' != '' ">$(NuGetPackageRoot)\StyleCop.Analyzers.Eprod\1.1.3</CodeAnalysisRuleSetLocation>
<CodeAnalysisRuleSetLocation Condition=" '$(CodeAnalysisRuleSetLocation)' == '' and '$(SolutionDir)' != '' ">$(SolutionDir)\packages\StyleCop.Analyzers.Eprod.1.1.3</CodeAnalysisRuleSetLocation>
<CodeAnalysisRuleSetLocation Condition=" '$(CodeAnalysisRuleSetLocation)' == '' ">$([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory)))\packages\StyleCop.Analyzers.Eprod.1.1.3</CodeAnalysisRuleSetLocation>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>$(CodeAnalysisRuleSetLocation)\RuleSet\StyleCop.Analyzers.Eprod.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="$(CodeAnalysisRuleSetLocation)\Config\stylecop.json" Link="stylecop.json" />
</ItemGroup>
</Project>
当我从专用注册表中安装.nuget软件包时,所有内容似乎都落在正确的文件夹中。从我项目的src文件夹中,将程序包部署到:packages \ StyleCop.Analyzers.Eprod.1.1.3
包中的所有文件都在正确的相对路径中。
.csproj文件也包含预期的部分:
{
// ACTION REQUIRED: You have successfully added this file to your project, but it
// will not take effect until additional steps are taken to enable it. See the
// following page for additional information:
//
// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"companyName": "Enterprise Products Partners L.P. (Enterprise)",
"copyrightText": "© Copyright 2012 - 2019, {companyName}, All Rights Reserved.\nPermission to use, copy, modify, or distribute this software source code, binaries or\nrelated documentation, is strictly prohibited, without written consent from Enterprise.\nFor inquiries about the software, contact Enterprise: Enterprise Products Company Law\nDepartment, 1100 Louisiana, 10th Floor, Houston, Texas 77002, phone 713-381-6500.",
"documentationCulture": "en-US",
"documentExposedElements": false,
"documentInterfaces": false,
"documentInternalElements": false,
"documentPrivateElements": false,
"documentPrivateFields": false,
"excludeFromPunctuationCheck": [
// None here, for now.
],
"fileNamingConvention": "stylecop",
"headerDecoration": "-----------------------------------------------------------------------",
"xmlHeader": true
},
"indentation": {
"indentationSize": 4,
"tabSize": 4,
"useTabs": false
},
"layoutRules": {
"allowConsecutiveUsings": false,
"newlineAtEndOfFile": "require"
},
"maintainabilityRules": {
"topLevelTypes": [
"class",
"delegate",
"enum",
"interface",
"struct"
]
},
"namingRules": {
"allowCommonHungarianPrefixes": true,
"allowedHungarianPrefixes": [
// None here, for now.
]
},
"orderingRules": {
"blankLinesBetweenUsingGroups": "allow",
"elementOrder": [
"kind",
"constant",
"accessibility",
"static",
"readonly"
],
"systemUsingDirectivesFirst": true,
"usingDirectivesPlacement": "outsideNamespace"
},
"readabilityRules": {
"allowBuiltInTypeAliases": false
},
"spacingRules": {
// There are currently no supported spacing rules.
}
}
}