diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md new file mode 100644 index 00000000..5cd740a0 --- /dev/null +++ b/.github/copilot-instructions.md @@ -0,0 +1,148 @@ +# GitHub Copilot Instructions for nuget-license + +## Project Overview + +This repository contains **nuget-license**, a .NET tool for analyzing, printing, and validating licenses of NuGet package dependencies in .NET and C++ projects. The project supports .NET Core, .NET Standard, .NET Framework, and native C++ projects. + +## Project Structure + +- **src/**: Source code for the main tools + - **NuGetLicenseCore/**: Cross-platform .NET Core global tool + - **NuGetLicenseFramework/**: .NET Framework standalone executable + - **NuGetUtility/**: Core utility library + - **NuGetLicense/**: License validation and processing library + - **FileLicenseMatcher/**: License file matching library +- **tests/**: Test projects + - **NuGetUtility.Test/**: Core utility tests + - **NuGetLicense.Test/**: License validation tests + - **FileLicenseMatcher.Test/**: File license matcher tests + - **NuGetUtility.UrlToLicenseMapping.Test/**: URL to license mapping tests + - **targets/**: Test target projects with various configurations +- **integration/**: Integration test projects +- **docs/**: Documentation files +- **.github/workflows/**: CI/CD workflows + +## Building the Project + +### Prerequisites + +- .NET SDK 10.0.101 or later (with rollForward to support minor versions) + - The project also targets net8.0 and net9.0, which require their respective SDKs +- MSBuild (for .NET Framework and C++ projects on Windows) + +### Build Commands + +```bash +# Restore dependencies +dotnet restore + +# Build the entire solution +dotnet build --configuration Release --no-restore + +# Build a specific project +dotnet build ./src/NuGetLicenseCore/NuGetLicenseCore.csproj --configuration Release + +# On Windows with MSBuild +msbuild -t:rebuild -restore -p:RestorePackagesConfig=true -property:Configuration=Release +``` + +## Testing the Project + +### Running Tests + +```bash +# Run all tests +dotnet test --configuration Release --no-restore + +# Run specific test project +dotnet test --project ./tests/NuGetUtility.Test/NuGetUtility.Test.csproj --configuration Release + +# Run tests for a specific framework +dotnet test --project ./tests/NuGetUtility.Test/NuGetUtility.Test.csproj --configuration Release -f net10.0 +``` + +### Test Organization + +- Tests follow the pattern `ClassName.Test.cs` for testing `ClassName.cs` +- Use xUnit as the testing framework +- Test projects include both unit tests and integration tests + +## Code Formatting and Linting + +```bash +# Check code formatting (does not modify files) +dotnet format --verify-no-changes + +# Format code +dotnet format +``` + +## Coding Conventions + +### C# Code Style + +- **Indentation**: 4 spaces (never tabs) +- **Line endings**: CRLF for most files, LF for shell scripts +- **File header**: All C# files must include the license header: + ```csharp + // Licensed to the projects contributors. + // The license conditions are provided in the LICENSE file located in the project root + ``` +- **Namespaces**: Use block-scoped namespaces (not file-scoped) +- **Braces**: Opening braces on new lines (Allman style) +- **Using directives**: Outside namespace, sorted with System directives first + +### Naming Conventions + +- **Private/internal fields**: `_camelCase` with underscore prefix +- **Static private/internal fields**: `s_camelCase` with `s_` prefix (preferred for new code) + - Note: Some ported code (e.g., FileLicenseMatcher from Java SPDX library) uses `UPPER_CASE` for static readonly fields +- **Public static readonly fields**: `UPPER_CASE` (especially for constants and patterns in ported code) +- **Constants**: `PascalCase` +- **Public members**: `PascalCase` +- **Local variables**: `camelCase` + +### Code Quality + +- Avoid `this.` qualifier for members (except when necessary for disambiguation) +- Use explicit types instead of `var` for built-in types +- Use modern C# features: pattern matching, null propagation, coalesce expressions +- Prefer switch expressions over switch statements +- Use expression-bodied members where appropriate +- Always use braces for control flow statements + +### XML Documentation + +- Public APIs should have XML documentation comments +- Use ``, ``, ``, `` tags as appropriate + +## Common Patterns in This Codebase + +- License validation uses expression parsing and evaluation +- Package information is read from `project.assets.json` files generated by `dotnet restore` +- The tool supports multiple output formats: Table, Markdown, JSON, and JsonPretty +- Configuration files use JSON format for mappings, overrides, and filters + +## Dependencies + +- Avoid adding new NuGet dependencies unless absolutely necessary +- When adding dependencies, ensure they work with all target frameworks (net8.0, net9.0, net10.0, net472) +- Consider cross-platform compatibility when adding dependencies + +## Multi-targeting Considerations + +- The project targets multiple .NET versions including .NET Framework 4.7.2 +- Test code changes on all target frameworks when modifying core functionality +- Be aware of API availability differences between .NET Framework and .NET Core/5+ + +## GitHub Actions Workflows + +- `.github/workflows/action.yml`: Main CI workflow that runs tests, code formatting checks, and license validation +- `.github/workflows/release.yml`: Release workflow for publishing packages +- The CI validates against multiple frameworks: net8.0, net9.0, net10.0, and net472 + +## Additional Notes + +- The project includes both managed (.NET) and native (C++) project support +- Windows-specific paths are handled specially in some integration tests +- The tool does NOT restore NuGet packages itself - it reads from existing `project.assets.json` files