Debugging in Visual Studio 2019 with different assemblyNames based on configurations

Viewed 34

I inherited the maintenance of a fairly complex solution that changes its functionalities based on #define flags. Then those flags are set as needed in different build configurations. The code is written in C# adapted from an earlier C++ solution, and for the time being a total code rewrite is preferred but not doable.

Before I arrived, my colleagues had to manually assign the assembly name and icon in the property window of the project. Since I am lazy and prefer to do as little dumb work as possible, I just defined the various names based on the active configuiration in the .vcproj file, something like this:

    <AssemblyName Condition="'$(Configuration)' == 'Debug' ">DevelopmentManager</AssemblyName>
    <AssemblyName Condition="'$(Configuration)' == 'Release' ">DevelopmentManager</AssemblyName>
    <AssemblyName Condition="'$(Configuration)' == 'Service Release'">ServiceManager</AssemblyName>
    <AssemblyName Condition="'$(Configuration)' == 'Service Debug'">ServiceManager</AssemblyName>
    <AssemblyName Condition="'$(Configuration)' == 'SERVICE_LIGHT DEBUG'">ServiceLoader</AssemblyName>
    <AssemblyName Condition="'$(Configuration)' == 'Service Light Release'">ServiceLoader</AssemblyName>

(the icons follow the same logic).

Everything works as intended, and each configuration is built with its own specific name, but I have still an issue:

in the vcproj i didn't set a generic assembly name nor an icon, assuming that it would pick the correct one as needed, but then when I try to debug the application sometimes VS2019 try to get the wrong filename. I.e. if I am debugging the Service Debug config that should build into ServiceManager.exe VS instead looks for DevelopmentManager.exe (or another one, that's not the point. I presume it somehow takes the last built or something like that), and if I go to the properties windows I can see that the assembly name is indeed DevelopmentManager.

So, in a few word, how can I tell to visual studio "Please debug my application with the correct assembly name" without having to manually change it in the project file property window?

1 Answers

Currently the solution is the one posted by Hans Passant: select the desired configuration, close and restart VS2019 and everything works.

I don't have a VS2022 installation available, so I don't know if this still applies to the new version.

Related