LegacyLibAnalyzer 0.1.0
dotnet add package LegacyLibAnalyzer --version 0.1.0
NuGet\Install-Package LegacyLibAnalyzer -Version 0.1.0
<PackageReference Include="LegacyLibAnalyzer" Version="0.1.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="LegacyLibAnalyzer" Version="0.1.0" />
<PackageReference Include="LegacyLibAnalyzer"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add LegacyLibAnalyzer --version 0.1.0
#r "nuget: LegacyLibAnalyzer, 0.1.0"
#:package LegacyLibAnalyzer@0.1.0
#addin nuget:?package=LegacyLibAnalyzer&version=0.1.0
#tool nuget:?package=LegacyLibAnalyzer&version=0.1.0
LegacyLibAnalyzer
Rule-agnostic MSBuild analyzer for NuGet package references.
LegacyLibAnalyzer reports matches as MSBuild errors/warnings/messages and can optionally
write a SARIF report. The package does not require built-in defaults; define your own
rules for the packages and versions your organization wants to flag.
Install
<PackageReference Include="LegacyLibAnalyzer" Version="0.1.0" PrivateAssets="all" />
Define rules
<ItemGroup>
<LegacyLibraryRule Include="Moq"
Code="LegacyLib-Moq"
Severity="Error"
Message="Moq is forbidden; use NSubstitute." />
<LegacyLibraryRule Include="xUnitV1"
Code="LegacyLib-xUnitV1"
IncludePattern="xunit*"
ExcludePattern="xunit.v3*"
MaxVersion="1"
Severity="Error"
Message="xUnit v1 is legacy; upgrade to xunit.v3." />
<LegacyLibraryRule Include="xUnitV2"
Code="LegacyLib-xUnitV2"
IncludePattern="xunit*"
ExcludePattern="xunit.v3*"
MinVersion="2"
MaxVersion="2"
Severity="Warning"
Message="xUnit v2 is legacy; upgrade to xunit.v3." />
</ItemGroup>
Note:
xunit.v3is a separate package name (not just "version 3" ofxunit), and it has since released its own major versions 3.x and 4.x. Don't confuse the package name with its version number when writingMinVersion/MaxVersionbounds.
Metadata:
Include(required by MSBuild): identity/key of the rule, used to merge/override rules. In the common case this is simply the package name (e.g.Include="Moq") and doubles as the match value, so you don't need to setIncludePatternseparately.Code: error/warning code reported to MSBuild and used as the SARIF rule id.IncludePattern(optional): the actual value matched against resolved package names. Can be a wildcard pattern (*/?, e.g.xunit*). Only needed when it differs fromInclude(for example, to keep a stableIncludekey for overrides while matching a pattern).Severity:Error,WarningorNote(defaults toWarning).Message: the message shown to the user.MinVersion/MaxVersion(optional): inclusive allowed version bounds. A partial version (e.g.2) represents the whole range it covers: asMinVersionit means "2.0.0.0 or higher", asMaxVersionit means "any 2.x.x.x version" (so2,2.4and2.4.1are all allowed byMaxVersion="2"). Pre-release versions are matched by their release version, so2.2.0-rc1is treated as2.2.0.ExcludePattern(optional): a wildcard pattern of package names to still exclude, even if they matchIncludePattern.
Two ways to use this package
- Directly: reference
LegacyLibAnalyzerand declare<LegacyLibraryRule>items in your own.csproj, as shown above. Good for a single repo or project-specific policy. - Via a company package: create a thin internal package (e.g.
MyCompany.LegacyLibAnalyzer) that referencesLegacyLibAnalyzer(withoutPrivateAssets="all") and ships your organization's<LegacyLibraryRule>items in its ownbuildTransitive\*.targetsfile. Consumers then only reference your company package to get the shared policy automatically, and can still override or soften individual rules locally by declaring a<LegacyLibraryRule>with the sameIncludekey. See the root repository README for the full walkthrough and an override example.
Optional SARIF output
<PropertyGroup>
<LegacyLibGenerateSarif>true</LegacyLibGenerateSarif>
<LegacyLibSarifOutputPath>$(MSBuildProjectDirectory)\legacylib.sarif</LegacyLibSarifOutputPath>
</PropertyGroup>
Minimal SARIF example:
{
"version": "2.1.0",
"runs": [
{
"tool": { "driver": { "name": "LegacyLibAnalyzer" } },
"results": [
{ "ruleId": "LegacyLib-Moq", "level": "error", "message": { "text": "Moq is forbidden; use NSubstitute." } }
]
}
]
}
Disable
<LegacyLibAnalyzerEnabled>false</LegacyLibAnalyzerEnabled>
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.1.0 | 46 | 9/8/2026 |