The specified solution configuration is invalid

88 views Asked by At

Using .NET Core 7 (SDK 7.0.402), I am running the command:

dotnet build -c development

But I get this error:

Error MSB4126: The specified solution configuration "development|Any CPU" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties

This command didn't throw any error a few days ago ...

The project file includes the development configuration:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
  </PropertyGroup>

  <PropertyGroup>
    <Configuration Condition="'$(Configuration)' == 'Debug'">development</Configuration>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)' == 'development'">
    <ConfigurationGroup>Debug</ConfigurationGroup>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)' == 'staging'">
    <ConfigurationGroup>Release</ConfigurationGroup>
  </PropertyGroup> 

  <PropertyGroup Condition="'$(Configuration)' == 'production'">
    <ConfigurationGroup>Release</ConfigurationGroup>
  </PropertyGroup> 

</Project>

What am I missing? Did something change in msbuild?

1

There are 1 answers

0
Jason Pan On

I reproduced your problem and I solved it by recreating the configuration for development, staging, and production in Configuration Manager.

Note: Directly copying the settings in .csproj does not seem to take effect in VS2022, and the error will still occur.

Step 1: Right-click the Solution, and find the Configuration Mansger...

enter image description here

Step 2: Click <New...>, and create the 1,2,3 in my screenshot.

enter image description here

Step 3: Then run the command dotnet build -c development.

enter image description here