From eaf6c898238ba53bab0734427f22c7f6fb1e6039 Mon Sep 17 00:00:00 2001
From: Marco Fogliatto <2962955+mfogliatto@users.noreply.github.com>
Date: Sat, 20 Dec 2025 09:26:04 +0100
Subject: [PATCH] Add playground environment for end-to-end testing
- Created playground directory with sample projects (SampleApp, SampleLibrary)
- Configured offline dev feed pointing to package build output
- Automatic version detection via package-version.txt
- ReferenceCop.config with examples of all rule types
- Directory.Build.props for centralized package reference
- Proper ReferenceCop setup per project README requirements
- Added Newtonsoft.Json reference to test violation detection
- Updated .gitignore to exclude auto-generated files
---
.gitignore | 5 ++-
playground/.gitignore | 3 ++
playground/README.md | 43 +++++++++++++++++++
playground/TestProject/Directory.Build.props | 33 ++++++++++++++
playground/TestProject/ReferenceCop.config | 38 ++++++++++++++++
playground/TestProject/SampleApp/Program.cs | 29 +++++++++++++
.../TestProject/SampleApp/SampleApp.csproj | 15 +++++++
.../TestProject/SampleLibrary/Calculator.cs | 23 ++++++++++
.../SampleLibrary/SampleLibrary.csproj | 15 +++++++
playground/TestProject/nuget.config | 10 +++++
.../ReferenceCop.Package.csproj | 9 ++++
11 files changed, 222 insertions(+), 1 deletion(-)
create mode 100644 playground/.gitignore
create mode 100644 playground/README.md
create mode 100644 playground/TestProject/Directory.Build.props
create mode 100644 playground/TestProject/ReferenceCop.config
create mode 100644 playground/TestProject/SampleApp/Program.cs
create mode 100644 playground/TestProject/SampleApp/SampleApp.csproj
create mode 100644 playground/TestProject/SampleLibrary/Calculator.cs
create mode 100644 playground/TestProject/SampleLibrary/SampleLibrary.csproj
create mode 100644 playground/TestProject/nuget.config
diff --git a/.gitignore b/.gitignore
index f601032..0cabefc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -148,4 +148,7 @@ L10N.Integrations/phantom*
tools/
# VS Code settings
-.vscode/mcp.json
\ No newline at end of file
+.vscode/mcp.json
+
+# Auto-generated package version file for playground
+src/ReferenceCop.Package/package-version.txt
\ No newline at end of file
diff --git a/playground/.gitignore b/playground/.gitignore
new file mode 100644
index 0000000..0b61c43
--- /dev/null
+++ b/playground/.gitignore
@@ -0,0 +1,3 @@
+# Standard .NET ignores for the test projects
+**/bin/
+**/obj/
diff --git a/playground/README.md b/playground/README.md
new file mode 100644
index 0000000..d064b27
--- /dev/null
+++ b/playground/README.md
@@ -0,0 +1,43 @@
+# ReferenceCop Playground
+
+This is a playground environment for testing ReferenceCop changes end-to-end.
+
+## Structure
+
+- `TestProject/` - Sample project that uses ReferenceCop for validation
+ - `SampleApp/` - Sample application project
+ - `SampleLibrary/` - Sample library project
+ - `nuget.config` - Configured to use ReferenceCop package from build output
+ - `Directory.Build.props` - Centralized ReferenceCop package reference with auto-version detection
+
+## Workflow
+
+1. **Make changes** to ReferenceCop source code
+2. **Build and pack** the ReferenceCop package:
+ ```powershell
+ cd ..\src\ReferenceCop.Package
+ dotnet pack -c Debug
+ ```
+ This automatically writes the package version to `package-version.txt`
+3. **Restore and build** the test project:
+ ```powershell
+ cd playground\TestProject\SampleApp
+ dotnet restore
+ dotnet build
+ ```
+4. **Introduce test violations** or modify the `ReferenceCop.config` to test your changes
+
+**Note**:
+- The `nuget.config` uses the package directly from the build output directory (`../../src/ReferenceCop.Package/bin/Debug`)
+- The package version is automatically read from `package-version.txt` via `Directory.Build.props`
+- No manual version updates needed!
+
+## Testing Different Rule Types
+
+The `ReferenceCop.config` includes examples of all three rule types:
+
+1. **AssemblyName** - Blocks references to assemblies matching a pattern
+2. **ProjectTag** - Blocks references between projects with specific tags
+3. **ProjectPath** - Blocks references based on project folder paths
+
+Modify the rules or project references to test violations.
diff --git a/playground/TestProject/Directory.Build.props b/playground/TestProject/Directory.Build.props
new file mode 100644
index 0000000..965c080
--- /dev/null
+++ b/playground/TestProject/Directory.Build.props
@@ -0,0 +1,33 @@
+
+
+
+
+ $(MSBuildThisFileDirectory)
+
+
+ $(MSBuildThisFileDirectory)..\..\src\ReferenceCop.Package\package-version.txt
+ $([System.IO.File]::ReadAllText('$(PlaygroundVersionFile)').Trim())
+ 20241220.000000
+
+
+
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
diff --git a/playground/TestProject/ReferenceCop.config b/playground/TestProject/ReferenceCop.config
new file mode 100644
index 0000000..27a7169
--- /dev/null
+++ b/playground/TestProject/ReferenceCop.config
@@ -0,0 +1,38 @@
+
+
+
+
+
+ NoSystemWebReferences
+ System.Web assemblies should not be referenced
+ Error
+ System.Web*
+
+
+
+
+ AppCannotReferenceTools
+ Application projects should not reference tool projects
+ Warning
+ App
+ Tools
+
+
+
+
+ AppCannotReferenceInternal
+ Applications should not reference internal implementation libraries
+ Error
+ **/SampleApp/**
+ **/Internal/**
+
+
+
+
+ NoNewtonsoftJson
+ Use System.Text.Json instead of Newtonsoft.Json
+ Warning
+ Newtonsoft.Json*
+
+
+
diff --git a/playground/TestProject/SampleApp/Program.cs b/playground/TestProject/SampleApp/Program.cs
new file mode 100644
index 0000000..1303a0f
--- /dev/null
+++ b/playground/TestProject/SampleApp/Program.cs
@@ -0,0 +1,29 @@
+using SampleLibrary;
+
+namespace SampleApp;
+
+///
+/// Sample application to test ReferenceCop.
+///
+public class Program
+{
+ public static void Main(string[] args)
+ {
+ Console.WriteLine("ReferenceCop Playground Test Application");
+ Console.WriteLine("=========================================");
+
+ var calculator = new Calculator();
+
+ Console.WriteLine($"5 + 3 = {calculator.Add(5, 3)}");
+ Console.WriteLine($"10 - 4 = {calculator.Subtract(10, 4)}");
+ Console.WriteLine($"6 * 7 = {calculator.Multiply(6, 7)}");
+ Console.WriteLine($"20 / 5 = {calculator.Divide(20, 5)}");
+
+ Console.WriteLine("\nTest completed successfully!");
+
+ // Uncomment to test violation detection:
+ // 1. Add a PackageReference to Newtonsoft.Json in the .csproj
+ // 2. Add: using Newtonsoft.Json;
+ // 3. Build to see the warning
+ }
+}
diff --git a/playground/TestProject/SampleApp/SampleApp.csproj b/playground/TestProject/SampleApp/SampleApp.csproj
new file mode 100644
index 0000000..bba6818
--- /dev/null
+++ b/playground/TestProject/SampleApp/SampleApp.csproj
@@ -0,0 +1,15 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+ App
+
+
+
+
+
+
+
diff --git a/playground/TestProject/SampleLibrary/Calculator.cs b/playground/TestProject/SampleLibrary/Calculator.cs
new file mode 100644
index 0000000..f87d143
--- /dev/null
+++ b/playground/TestProject/SampleLibrary/Calculator.cs
@@ -0,0 +1,23 @@
+namespace SampleLibrary;
+
+///
+/// A simple calculator class for demonstration.
+///
+public class Calculator
+{
+ public int Add(int a, int b) => a + b;
+
+ public int Subtract(int a, int b) => a - b;
+
+ public int Multiply(int a, int b) => a * b;
+
+ public int Divide(int a, int b)
+ {
+ if (b == 0)
+ {
+ throw new DivideByZeroException("Cannot divide by zero");
+ }
+
+ return a / b;
+ }
+}
diff --git a/playground/TestProject/SampleLibrary/SampleLibrary.csproj b/playground/TestProject/SampleLibrary/SampleLibrary.csproj
new file mode 100644
index 0000000..1cbd80b
--- /dev/null
+++ b/playground/TestProject/SampleLibrary/SampleLibrary.csproj
@@ -0,0 +1,15 @@
+
+
+
+ net8.0
+ enable
+ enable
+
+ Library
+
+
+
+
+
+
+
diff --git a/playground/TestProject/nuget.config b/playground/TestProject/nuget.config
new file mode 100644
index 0000000..8418d88
--- /dev/null
+++ b/playground/TestProject/nuget.config
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/ReferenceCop.Package/ReferenceCop.Package.csproj b/src/ReferenceCop.Package/ReferenceCop.Package.csproj
index 24c6aa5..d3736d6 100644
--- a/src/ReferenceCop.Package/ReferenceCop.Package.csproj
+++ b/src/ReferenceCop.Package/ReferenceCop.Package.csproj
@@ -58,4 +58,13 @@
+
+
+
+ $(MSBuildThisFileDirectory)package-version.txt
+
+
+
+
+
\ No newline at end of file