-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add .NET/C# support to pulumitest #147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
pulumitest/testdata/mock_sdk/bin/Debug/net8.0/MockSdk.deps.json
Outdated
Show resolved
Hide resolved
b1228ff to
60f54cc
Compare
60f54cc to
fc51eb9
Compare
danielrbradley
approved these changes
Oct 20, 2025
Contributor
danielrbradley
left a comment
There was a problem hiding this 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.
fc51eb9 to
b6c99f6
Compare
b6c99f6 to
948484d
Compare
EronWright
approved these changes
Oct 23, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
DotNetReferenceOption (opttest/opttest.go)<ProjectReference>elements to .csproj files on stack creationNew
.csprojManipulation (pulumitest/csproj.go)findCsprojFile()- Locates .csproj files in a directoryaddProjectReferences()- Adds ProjectReference elements to .csproj filesStack Creation Integration (
newStack.go)DotNetReferencesare specifiedGoModReplacementsandYarnLinksTest Data
testdata/csharp_simple/- Simple C# program using Random providertestdata/csharp_aws/- AWS S3 bucket exampleTests
Unit Tests (
pulumiTest_test.go)TestDotNetDeploy- Full deployment workflowTestDotNetSkipInstall- Manual install and stack creationIntegration Test (
dotnet_aws_test.go)TestDotNetAwsDeploy- Real AWS S3 bucket deploymentt.Cleanup()Documentation
DotNetReferenceto key optionscsproj.goto file organizationTesting
All tests pass successfully:
TestDotNetDeploy- Deploys Random provider resourcesTestDotNetSkipInstall- Manual installation flowTestDotNetAwsDeploy- Real AWS S3 bucket deployment and cleanupExample Usage