Search code examples
c#visual-studioapp-configassembly-name

Debug target doesn't switch when changing configuration


I have a .NET Framework WPF project (Tested on both 4.6.1 and 4.8) with two configurations, that have the AssemblyName property assigned

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
    <AssemblyName>WpfApp2</AssemblyName>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...
    <AssemblyName>WpfApp3</AssemblyName>
  </PropertyGroup>

They compile correctly (Debug has WpfApp2.exe, Release has WpfApp3.exe).

Here's the problem: When debugging one config, debugging the other one gives me an error, saying that the debug target is not found. The bin path is correct, but it looks like the file name didn't change. For example, debugging the Debug project is fine, but after that, if I start debugging the Release config, I get the following error: it's still trying to use WpfApp2.exe
Error message (in French) saying that the debug target cannot be found

Why is it not trying to look for WpfApp3.exe instead, like written in the XML?
Reloading the project doesn't work, but restarting Visual Studio (Tested both the 2019 and 2022 versions) does. I would like a faster way to fix this problem.


Solution

  • After my test, this problem does exist. But you can avoid it by the following methods:

    1: Right-click the project and select Properties.

    2: In the Debug tab, manually set the Start External Program path to the compiled file, for example:

    Set to bin\Debug\WpfAppDebug.exe for Debug configuration

    Set to bin\Release\WpfAppRelease.exe for Release configuration

    If you don't want to use the above method, I suggest you report this issue to DC, there are many VS developers who can help you. If you report the issue in DC, please provide a link where you submit the issue on DC, so that people with the same problem can find a solution more quickly in the future.