Skip to content

Conversation

@rshade
Copy link
Contributor

@rshade rshade commented Oct 14, 2025

This commit adds comprehensive support for testing .NET/C# Pulumi applications in the pulumitest library, following existing patterns from Node.js (YarnLink) and Go (GoModReplacement).

Changes

Core Functionality

  • New DotNetReference Option (opttest/opttest.go)

    • Allows specifying local NuGet packages or projects to reference
    • Adds <ProjectReference> elements to .csproj files on stack creation
    • Supports both .csproj file paths and directories containing .csproj files
    • Automatic absolute path resolution
  • New .csproj Manipulation (pulumitest/csproj.go)

    • findCsprojFile() - Locates .csproj files in a directory
    • addProjectReferences() - Adds ProjectReference elements to .csproj files
    • Text-based XML manipulation for reliability
  • Stack Creation Integration (newStack.go)

    • Automatic .csproj modification when DotNetReferences are specified
    • Similar pattern to existing GoModReplacements and YarnLinks

Test Data

  • New Test Programs
    • testdata/csharp_simple/ - Simple C# program using Random provider
    • testdata/csharp_aws/ - AWS S3 bucket example
    • Both use latest package versions:
      • Pulumi 3.90.0 (latest stable .NET SDK)
      • Pulumi.Random 4.18.4
      • Pulumi.Aws 7.8.0
      • Target framework: net8.0

Tests

  • Unit Tests (pulumiTest_test.go)

    • TestDotNetDeploy - Full deployment workflow
    • TestDotNetSkipInstall - Manual install and stack creation
  • Integration Test (dotnet_aws_test.go)

    • TestDotNetAwsDeploy - Real AWS S3 bucket deployment
    • Verifies automatic cleanup via t.Cleanup()

Documentation

  • Added DotNetReference to key options
  • Added .NET/C# SDK configuration section
  • Added csproj.go to file organization

Testing

All tests pass successfully:

  • TestDotNetDeploy - Deploys Random provider resources
  • TestDotNetSkipInstall - Manual installation flow
  • TestDotNetAwsDeploy - Real AWS S3 bucket deployment and cleanup
  • ✅ Existing tests remain unaffected

Example Usage

// Basic .NET project test
test := NewPulumiTest(t, "path/to/csharp/project")
up := test.Up(t)

// Test with local SDK reference
test := NewPulumiTest(t,
    "path/to/csharp/project",
    opttest.DotNetReference("Pulumi.Aws", "../pulumi-aws/sdk/dotnet"),
)

This commit adds comprehensive support for testing .NET/C# Pulumi applications
in the pulumitest library, following existing patterns from Node.js (YarnLink)
and Go (GoModReplacement).

## Changes

### Core Functionality

- **New `DotNetReference` Option** (`opttest/opttest.go`)
  - Allows specifying local NuGet packages or projects to reference
  - Adds `<ProjectReference>` elements to .csproj files on stack creation
  - Supports both .csproj file paths and directories containing .csproj files
  - Automatic absolute path resolution

- **New `.csproj` Manipulation** (`pulumitest/csproj.go`)
  - `findCsprojFile()` - Locates .csproj files in a directory
  - `addProjectReferences()` - Adds ProjectReference elements to .csproj files
  - Text-based XML manipulation for reliability

- **Stack Creation Integration** (`newStack.go`)
  - Automatic .csproj modification when `DotNetReferences` are specified
  - Similar pattern to existing `GoModReplacements` and `YarnLinks`

### Test Data

- **New Test Programs**
  - `testdata/csharp_simple/` - Simple C# program using Random provider
  - `testdata/csharp_aws/` - AWS S3 bucket example
  - Both use latest package versions:
    - Pulumi 3.90.0 (latest stable .NET SDK)
    - Pulumi.Random 4.18.4
    - Pulumi.Aws 7.8.0
    - Target framework: net8.0

### Tests

- **Unit Tests** (`pulumiTest_test.go`)
  - `TestDotNetDeploy` - Full deployment workflow
  - `TestDotNetSkipInstall` - Manual install and stack creation

- **Integration Test** (`dotnet_aws_test.go`)
  - `TestDotNetAwsDeploy` - Real AWS S3 bucket deployment
  - Verifies automatic cleanup via `t.Cleanup()`

### Documentation

- **Updated `pulumitest/CLAUDE.md`**
  - Added `DotNetReference` to key options
  - Added .NET/C# SDK configuration section
  - Added `csproj.go` to file organization

- **New `DOTNET-TODO.md`**
  - Tracks completed items and future enhancements

## Testing

All tests pass successfully:
- ✅ `TestDotNetDeploy` - Deploys Random provider resources
- ✅ `TestDotNetSkipInstall` - Manual installation flow
- ✅ `TestDotNetAwsDeploy` - Real AWS S3 bucket deployment and cleanup
- ✅ Existing tests remain unaffected

## Example Usage

```go
// Basic .NET project test
test := NewPulumiTest(t, "path/to/csharp/project")
up := test.Up(t)

// Test with local SDK reference
test := NewPulumiTest(t,
    "path/to/csharp/project",
    opttest.DotNetReference("Pulumi.Aws", "../pulumi-aws/sdk/dotnet"),
)
```

## Notes

- Installation via `pulumi install` already supports .NET
- The Pulumi .NET SDK uses different versioning than the CLI (3.90.0 vs 3.200+)
- Future enhancements tracked in DOTNET-TODO.md
@rshade rshade force-pushed the feature/dotnet-support branch from b1228ff to 60f54cc Compare October 16, 2025 13:58
@rshade rshade force-pushed the feature/dotnet-support branch from 60f54cc to fc51eb9 Compare October 16, 2025 16:09
@rshade rshade marked this pull request as ready for review October 16, 2025 17:07
Copy link
Contributor

@danielrbradley danielrbradley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. One minor comment on options which aren't tested and aren't obvious to me what they'd be needed for.

Would be ideal to get someone on the providers team to also look through this.

@danielrbradley danielrbradley requested a review from a team October 20, 2025 12:57
@rshade rshade force-pushed the feature/dotnet-support branch from fc51eb9 to b6c99f6 Compare October 20, 2025 20:50
@rshade rshade force-pushed the feature/dotnet-support branch from b6c99f6 to 948484d Compare October 21, 2025 20:44
@rshade rshade merged commit 6af27cd into main Oct 23, 2025
2 checks passed
@rshade rshade deleted the feature/dotnet-support branch October 23, 2025 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants