abpframework/abp · error · CliUsageException

This command should be run inside a folder that contains a m

Error message

This command should be run inside a folder that contains a microservice solution! Or use -{Options.MainSolution.Short} parameter.

What it means

Thrown by ProjectCreationCommandBase when adding a microservice to a solution and no .sln or .slnx file can be found in the resolved output folder. The code searches Directory.GetFiles for *.sln and *.slnx; if slnPath remains null, the command cannot determine the microservice solution name and aborts. The message suggests running inside a solution folder or using the -ms (MainSolution) parameter.

Source

Thrown at framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProjectCreationCommandBase.cs:200

            {
                Directory.SetCurrentDirectory(Path.GetDirectoryName(slnPath));
                outputFolderRoot = Path.GetDirectoryName(slnPath);
            }
            else if (!Directory.Exists(slnPath))
            {
                slnPath = null;
            }
            else
            {
                Directory.SetCurrentDirectory(slnPath);
                outputFolderRoot = slnPath;
                slnPath = Directory.GetFiles(outputFolderRoot, "*.sln")
                    .Concat(Directory.GetFiles(outputFolderRoot, "*.slnx")).FirstOrDefault();
            }

            if (slnPath == null)
            {
                throw new CliUsageException($"This command should be run inside a folder that contains a microservice solution! Or use -{Options.MainSolution.Short} parameter.");
            }

            var microserviceSolutionName = Path.GetFileName(slnPath).RemovePostFix(".slnx", ".sln");

            version ??= SolutionPackageVersionFinder.FindByCsprojVersion(slnPath);
            solutionName = SolutionName.Parse(microserviceSolutionName, projectName);
            outputFolder = MicroserviceServiceTemplateBase.CalculateTargetFolder(outputFolderRoot, solutionName.ProjectName);
            uiFramework = uiFramework == UiFramework.NotSpecified ? FindMicroserviceSolutionUiFramework(outputFolderRoot) : uiFramework;
        }
        else
        {
            solutionName = SolutionName.Parse(projectName);

            outputFolder = createSolutionFolder ?
                Path.Combine(outputFolderRoot, SolutionName.Parse(projectName).FullName) :
                outputFolderRoot;
        }

View on GitHub (pinned to 7ed43b1931)

Solutions

  1. Change to the directory containing your microservice .sln/.slnx file before running the command
  2. Use the -ms parameter to point to the main solution path: `abp new ... -ms /path/to/MySolution.sln`
  3. Ensure the solution file exists and uses the .sln or .slnx extension
  4. If the microservice solution does not exist yet, create it first before adding services

Example fix

// before — run from wrong directory
abp new MyMicroservice -t microservice-service

// after
cd /path/to/microservice-solution-root
abp new MyMicroservice -t microservice-service
// or specify explicitly
abp new MyMicroservice -t microservice-service -ms /path/to/MySolution.sln
Defensive patterns

Strategy: validation

Validate before calling

// Verify a solution file exists before running microservice commands
var slnFiles = Directory.GetFiles(workingDir, "*.sln")
    .Concat(Directory.GetFiles(workingDir, "*.slnx"));
if (!slnFiles.Any() && !commandLineArgs.Options.ContainsKey(Options.MainSolution.Short))
{
    Console.Error.WriteLine("Error: No .sln/.slnx found. Run from solution root or use -ms <path>.");
    return;
}

Try / catch

try
{
    await projectCreationCommand.ExecuteAsync(commandLineArgs);
}
catch (CliUsageException ex) when (ex.Message.Contains("microservice solution"))
{
    logger.LogError("Run inside the solution folder or pass -ms <solution-path>.");
}

Prevention

When it happens

Trigger: Running a microservice service creation command in a directory that does not contain a .sln or .slnx file, without specifying the -ms parameter. slnPath == null after the file search.

Common situations: Developer runs the command from the wrong working directory (not the solution root), the solution file has a non-standard extension, or the microservice solution was not yet created. Also when -ms points to a path that itself lacks a solution file.

Related errors


AI-assisted analysis of abpframework/abp@7ed43b1931 (2026-08-13). Data as JSON: /api/errors/65d8b1fc6a16a627. Report an issue: GitHub.