Table of Contents

AL0017: Hardcoded package version detected

Cause

A PackageVersion element in Directory.Packages.props uses a hardcoded version string instead of an MSBuild property variable.

Rule description

Package versions should use MSBuild variables from Version.props for centralized version management. This ensures:

  • Consistency: All projects use the same package versions
  • Maintainability: Version updates require changing only one file
  • Discoverability: All version numbers are documented in one place
  • AI-friendliness: Claude Code can easily find and update versions

How to fix

Replace the hardcoded version with the appropriate $(VariableName) from Version.props.

Before (violation)

<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="5.0.0" />

After (correct)

<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(RoslynVersion)" />

Common version variables

Package Pattern Variable Name
Microsoft.CodeAnalysis.* $(RoslynVersion)
Microsoft.CodeAnalysis.Analyzers $(RoslynAnalyzersVersion)
xunit.v3* $(XunitV3Version)
AwesomeAssertions $(AwesomeAssertionsVersion)
Meziantou.Framework $(MeziantouFrameworkVersion)
Meziantou.Framework.FullPath $(MeziantouFullPathVersion)
Microsoft.Extensions.* $(MicrosoftExtensionsVersion)
Microsoft.AspNetCore.* $(AspNetCoreVersion)
OpenTelemetry.* $(OpenTelemetryVersion)
Basic.Reference.Assemblies.* $(BasicReferenceAssembliesVersion)

Where to define new variables

Add new version variables to ANcpLua.NET.Sdk/src/common/Version.props:

<PropertyGroup Label="Your Category">
  <YourPackageVersion>1.2.3</YourPackageVersion>
</PropertyGroup>

When to suppress

Suppress this warning only for:

  • Local development overrides (temporary)
  • Package versions that intentionally differ from the centralized version
<!-- Suppress for specific package -->
<PackageVersion Include="SpecialPackage" Version="1.0.0" />
<!-- AL0017 suppression: This package requires a specific version for compatibility -->

Severity

Warning (can be elevated to Error via .editorconfig)

# .editorconfig
[*.props]
dotnet_diagnostic.AL0017.severity = error