You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Xunit.DependencyInjection is a .NET library that enables Microsoft.Extensions.DependencyInjection to resolve xUnit test cases. It provides dependency injection for xUnit tests with support for multiple target frameworks and integrates with ASP.NET Core TestHost.
4
+
5
+
Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.
6
+
7
+
## Working Effectively
8
+
9
+
### CRITICAL REQUIREMENTS
10
+
**STOP**: Do not proceed without .NET 10.x preview SDK. All build/test commands will fail otherwise.
11
+
12
+
### Environment Setup
13
+
-**CRITICAL**: Install .NET 10.x preview SDK. This project CANNOT be built without .NET 10.x preview.
14
+
```bash
15
+
# Check current version
16
+
dotnet --version
17
+
# Must show 10.x.x preview version for building to work
18
+
19
+
# If you see 8.x.x or 9.x.x, all builds will fail with:
20
+
# "error NU1011: Centrally defined floating package versions are not allowed"
21
+
```
22
+
- The project multi-targets .NET Framework 4.7.2, .NET 8.0, and .NET 9.0 but requires .NET 10.x SDK to build
23
+
- Uses Central Package Management with floating versions (requires .NET 10.x preview)
24
+
-**DO NOT ATTEMPT TO BUILD** without .NET 10.x preview - it will fail consistently
25
+
26
+
### Build Process
27
+
-**NEVER CANCEL builds or test runs** - they can take significant time and must complete
28
+
- Build the entire solution:
29
+
```bash
30
+
dotnet build -c Release -v n
31
+
```
32
+
**TIMING**: Build takes approximately 5-15 minutes. NEVER CANCEL. Set timeout to 30+ minutes.
33
+
- Individual project builds:
34
+
```bash
35
+
dotnet build src/Xunit.DependencyInjection/Xunit.DependencyInjection.csproj -c Release -v n
36
+
```
37
+
-**IMPORTANT**: If floating package versions cause build failures, the issue is likely .NET SDK version mismatch. Ensure .NET 10.x preview is installed.
38
+
39
+
### Test Execution
40
+
- Run core tests:
41
+
```bash
42
+
dotnet test -c Release --no-build ./test/Xunit.DependencyInjection.Test/Xunit.DependencyInjection.Test.csproj
43
+
```
44
+
**TIMING**: Test execution takes 3-10 minutes. NEVER CANCEL. Set timeout to 20+ minutes.
45
+
- Run ASP.NET Core tests:
46
+
```bash
47
+
dotnet test -c Release --no-build ./test/Xunit.DependencyInjection.Test.AspNetCore/Xunit.DependencyInjection.Test.AspNetCore.csproj
48
+
```
49
+
- Run parallelization tests:
50
+
```bash
51
+
dotnet test -c Release --no-build ./test/Xunit.DependencyInjection.Test.Parallelization/Xunit.DependencyInjection.Test.Parallelization.csproj
52
+
```
53
+
- Run F# tests:
54
+
```bash
55
+
dotnet test -c Release --no-build ./test/Xunit.DependencyInjection.Test.FSharp/Xunit.DependencyInjection.Test.FSharp.fsproj
56
+
```
57
+
-**CRITICAL**: Always use `--no-build` when running tests after a successful build to save time.
1. Navigate to template: `cd src/Xunit.DependencyInjection.Template/`
129
+
2. Package template: `dotnet pack -o out`
130
+
3. Install locally: `dotnet new install ./out/Xunit.DependencyInjection.Template.*.nupkg`
131
+
4. Test template: `dotnet new create xunit-di -n TestProject`
132
+
5. Uninstall: `dotnet new uninstall Xunit.DependencyInjection.Template`
133
+
134
+
### Running Sample Applications
135
+
- MinimalAPI sample is not directly runnable as a web app - it's designed for testing via TestHost
136
+
- Test projects demonstrate various usage patterns - examine test classes for implementation examples
137
+
138
+
### Code Analysis
139
+
- The project includes a Roslyn analyzer that validates Startup class configurations
140
+
- Analyzer tests are in `test/Xunit.DependencyInjection.Analyzer.Test/`
141
+
- Always run analyzer tests when modifying analyzer rules
142
+
143
+
## Troubleshooting
144
+
145
+
### Build Issues
146
+
-**"Centrally defined floating package versions are not allowed"**: The most common error. Upgrade to .NET 10.x preview SDK immediately.
147
+
-**"CS0106: The modifier 'public' is not valid for this item"**: Language version issue - this project uses C# 14 features that require .NET 10.x preview SDK
148
+
-**Cannot restore packages**: Verify internet connectivity and NuGet package sources
149
+
-**Projects fail to build on .NET 8.x/9.x**: Expected behavior. This project is designed for .NET 10.x preview only.
150
+
151
+
### Test Issues
152
+
-**Tests hang or timeout**: Allow sufficient time - some tests verify timing behavior and intentionally delay
153
+
-**Parallelization tests fail**: May indicate threading issues - check test output for timing information
154
+
-**ASP.NET Core tests fail**: Verify MinimalApiSample builds correctly as a dependency
155
+
156
+
### Template Issues
157
+
-**"Template not found"**: Ensure template is packaged and installed correctly
158
+
-**Template creates project with wrong framework**: Use `-f` parameter to specify target framework
0 commit comments