An MSBuild project file linter to validate project files as part of the build process. ProjectLinter helps maintain consistent and correct MSBuild project files across your codebase by enforcing best practices and catching common issues early.
ProjectLinter is a development tool designed to enforce MSBuild project file standards and best practices. It integrates seamlessly into your build process and helps catch common issues before they cause problems in production. The tool is particularly useful for:
- Maintaining consistent project structures across a large codebase
- Preventing common MSBuild configuration mistakes
- Enforcing best practices for project references and dependencies
- Ensuring test projects have the correct testing framework dependencies
- Catching potential build issues early in the development cycle
-
Add ProjectLinter to your project using NuGet:
<PackageReference Include="ProjectLinter" Version="0.2.9" PrivateAssets="All" />
-
For multi-project solutions, add it to your
Directory.Build.targets
file at the root of your repository:<Project> <ItemGroup> <PackageReference Include="ProjectLinter" Version="0.2.9" PrivateAssets="All" /> </ItemGroup> </Project>
-
Build your project - ProjectLinter will automatically run as part of the build process.
The ProjectLinter consists of a set of validators which run against the MSBuild project to check for known issues. These validators are automatically wired into the build process using the package .targets file and run before the 'CoreBuild' target.
The tool includes the following validators:
- NoOldStyleProjects: Ensures projects use the modern SDK-style format
- NoStupidProperties: Checks for unnecessary or incorrect property settings
- TestProjectDependencyValidator: Validates test project dependencies
- ReferenceValidator: Checks for proper reference configurations
- ProjectReferenceValidator: Validates project references
- NoXCopyCallsValidator: Prevents use of xcopy commands in favor of MSBuild tasks
- EmptyGroupValidator: Detects empty property and item groups
- ConditionValidator: Validates condition expressions
- DuplicateReferenceValidator: Prevents duplicate project and package references
Warnings and errors are written to the standard build output, and any validation failures will fail the build.
To add linting to your project, simply add a PackageReference:
<Project>
<ItemGroup>
<PackageReference Include="ProjectLinter" Version="0.2.9" PrivateAssets="All" />
</ItemGroup>
</Project>
To skip particular validators for a project, add their IDs (separated by semicolons) to the ProjectLinterSuppressions
property:
<Project>
<PropertyGroup>
<ProjectLinterSuppressions>NoOldStyleProjects;XCopyValidator</ProjectLinterSuppressions>
</PropertyGroup>
</Project>
NoOldStyleProjects
: Skip SDK-style project validationPropertyValidator
: Skip property validationTestDependencyValidator
: Skip test project dependency checksReferenceValidator
: Skip reference validationProjectReferenceValidator
: Skip project reference validationXCopyValidator
: Skip xcopy command validationEmptyGroup
: Skip empty group validationCondition
: Skip condition validationDuplicateReference
: Skip duplicate reference validation
Please see our contributing guide for details on how to contribute to the project.
Please see our security policy for details on reporting security vulnerabilities.