NSwag项目构建报错:‘run’命令未识别,退出码9009
Let's break down what's going wrong here: Your BeforeBuild step is trying to execute run C:\agent_work\8\s\Web\webapi.nswag, but your build agent's shell (likely Windows CMD or PowerShell) doesn't recognize run as a valid standalone command. Exit code 9009 almost always means the system can't locate the executable you're trying to invoke.
Here's how to fix this issue step by step:
1. Use the correct NSwag command syntax
NSwag doesn't use a standalone run command—you need to call the NSwag executable first, then pass run as an argument. The exact command depends on how you installed NSwag:
Option A: Globally installed NSwag CLI
If you installed NSwag globally (via NuGet, Chocolatey, or the official installer), update your BeforeBuild command to:
nswag run "C:\agent_work\8\s\Web\webapi.nswag"
Option B: Local .NET Tool installation
If you added NSwag as a local .NET tool in your project (via dotnet tool install NSwag.ConsoleCore), use this command instead:
dotnet nswag run "C:\agent_work\8\s\Web\webapi.nswag"
2. Validate your build agent environment
- For global installations: Confirm the NSwag executable path is added to the system
PATHvariable on your build agent. Test this manually by runningnswag --versionin the agent's command prompt—if it returns a version number, the path is configured correctly. - For local .NET tools: Add a pre-build step to run
dotnet tool restoreto ensure the NSwag tool is downloaded and available before executing the generation command.
3. Double-check the NSwag file path
Make sure the path to webapi.nswag is accurate (wrap it in quotes if there are spaces in the path, though your example doesn't have any). You can test the command directly in the agent's working directory to confirm it runs without errors before updating your build configuration.
内容的提问来源于stack exchange,提问作者Marcus Vinícius

