Skip to content
DevOps AI ToolKit
Newsletter
All guides
AI for Pulumi By James Joyner IV · · 8 min read Last reviewed Jul 2026

Pulumi Error: '.NET build failed' — C# Program Compile Fix

Quick answer

Fix Pulumi '.NET build failed' running a C# program: missing SDK, NuGet restore failures, csproj target framework, and compile errors surfaced during preview.

  • #pulumi
  • #iac
  • #troubleshooting
  • #errors
Free toolkit

Stuck on this Pulumi error? Get the free incident triage checklist

A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.

Exact Error Message

error: failed to load language plugin dotnet: could not build project:
    Program.cs(31,20): error CS0246: The type or namespace name 'Bucket'
      could not be found (are you missing a using directive or an assembly reference?)

Build FAILED.
error: .NET build failed

You may also see error NETSDK1045: The current .NET SDK does not support targeting .NET x.0, error NU1101: Unable to find package Pulumi.Aws, or MSB1003: Specify a project or solution file. All of these are the dotnet build step failing before Pulumi can run your program.

What It Means

For C#/.NET projects, Pulumi’s dotnet language host compiles your program with the dotnet CLI before evaluating any resources. When that build fails — a compile error, a NuGet restore failure, a missing SDK, or a bad target framework — Pulumi has no runnable program and stops with .NET build failed, echoing the MSBuild/Roslyn diagnostic.

This is a standard .NET build error surfaced through Pulumi. The remedy is whatever dotnet build needs to succeed: the right SDK installed, packages restored, and the code compiling cleanly.

Common Causes

  • A missing using directive or assembly reference (CS0246) for a Pulumi type.
  • The installed .NET SDK does not support the TargetFramework in the .csproj (NETSDK1045).
  • NuGet restore cannot find or reach the Pulumi.* packages (NU1101, offline feed, proxy).
  • A Pulumi.yaml main pointing at a directory with no .csproj, or multiple project files (MSB1003).
  • Version drift between Pulumi and Pulumi.Aws/provider packages producing type mismatches.
  • An ordinary C# compile error (CS xxxx) in the program.

Diagnostic Commands

Reproduce the build directly for the clearest diagnostics:

dotnet build -v normal

Confirm which SDKs are installed and the target framework in use:

dotnet --list-sdks
cat *.csproj

Restore packages explicitly to isolate NuGet problems:

dotnet restore

Check the Pulumi project runtime and entry point:

cat Pulumi.yaml

Step-by-Step Resolution

  1. Read the error code. CSxxxx is a compile error, NETSDKxxxx is an SDK/target mismatch, and NUxxxx is a package-restore failure — each has a different fix.

  2. For a CS0246 missing-type error, add the correct using and make sure the provider package is referenced in the .csproj:

using Pulumi;
using Pulumi.Aws.S3;
<ItemGroup>
  <PackageReference Include="Pulumi" Version="3.*" />
  <PackageReference Include="Pulumi.Aws" Version="6.*" />
</ItemGroup>
  1. For NETSDK1045, align the TargetFramework with an installed SDK from dotnet --list-sdks (or install the newer SDK):
<TargetFramework>net8.0</TargetFramework>
  1. For NU1101 restore failures, restore against the public feed and clear a corrupt cache if needed:
dotnet nuget locals all --clear
dotnet restore --source https://api.nuget.org/v3/index.json
  1. If MSB1003 appears, point Pulumi.yaml at the folder containing exactly one .csproj:
name: my-app
runtime: dotnet
main: ./MyApp
  1. Confirm a clean build, then run the preview:
dotnet build && pulumi preview

When a CS diagnostic is cryptic, paste the offending lines and the error into a prompt from the Pulumi prompt library to get the missing reference or type usage explained.

Prevention

  • Pin Pulumi and provider packages to compatible major versions in the .csproj and upgrade them together.
  • Run dotnet build in CI before pulumi preview so compile and restore errors fail early with full context.
  • Keep the TargetFramework on a framework your CI and local SDKs both install; check dotnet --list-sdks.
  • Commit a nuget.config when using a private feed so restore is reproducible across machines.
  • Keep one .csproj per Pulumi project directory (or set main explicitly) to avoid ambiguous-project errors.
  • failed to load language plugin dotnet — the dotnet language host itself could not start.
  • error: Running program '...' failed with an unhandled exception — a runtime error after a successful build.
  • NU1102: Unable to find package ... with version — a restore version-constraint problem.
  • no Pulumi.yaml project file found — you are running outside the project directory.

Frequently Asked Questions

Why does Pulumi build my C# project? The dotnet language host compiles your program with dotnet build before evaluating resources, so any build failure stops Pulumi before a plan exists.

How do I fix NETSDK1045? Either lower the TargetFramework to a version your installed SDK supports or install the newer .NET SDK; dotnet --list-sdks shows what you have.

Restore fails only in CI — why? CI usually starts with an empty NuGet cache and may lack access to a private feed; add a nuget.config and run dotnet restore explicitly.

Can I precompile to speed up preview? Yes, but the build must still succeed; fixing the underlying compile or restore error is what clears .NET build failed. For more .NET setup guidance, see the Pulumi guides.

Free download · 368-page PDF

Fixed it? Get 500 Pulumi & DevOps AI prompts — free

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.

Did this fix your issue?

Free download · 368-page PDF

Get 500 Battle-Tested DevOps AI Prompts — Free

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.