Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
How to define custom configurations in new-style .csproj?
Problem
I'm trying to update some projects from old-style .csproj:
<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> etc.
to new-style:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> etc.
One group of projects has a custom configuration, in addition to the standard Debug
and Release
. After I convert a project from this group, VS gives an error message:
Current solution contains incorrect configuration mappings. It may cause projects to not work correctly. Open the Configuration Manager to fix them. [Open Configuration Manager]
(where the square brackets represent a button). If I click the button, or open the configuration manager by other means, it updates the .sln file to use Debug
instead of the custom configuration in the converted project.
What I've tried
I've tried using the configuration manager to create a new configuration for the project, copying from Debug: this does absolutely nothing, not even an error dialog telling me that it can't do it.
I've tried adding a stanza to the converted .csproj to try to "define" the configuration:
<PropertyGroup Condition="'$(Configuration)' == 'Dev Cloud'"> <DefineConstants>TRACE;DEBUG;DEVCLOUD</DefineConstants> <Optimize>false</Optimize> <DebugType>full</DebugType> <ErrorReport>prompt</ErrorReport> <Prefer32Bit>true</Prefer32Bit> <DebugSymbols>true</DebugSymbols> </PropertyGroup>
This also fails to achieve anything.
1 answer
I decided to tackle this again via the route of creating a new solution project-by-project, and this time the configuration manager actually did something useful. Specifically, it added a property to the csproj:
<Configurations>Debug;Release;Dev Cloud</Configurations>
This seems to be the key: the old solution now loads and understands the project configuration.
0 comment threads