How to specify the start application for your assembly
With the introduction of .NET Core Microsoft changed the format of the .csproj file. It is much smaller than the original format and I quite like it. Unfortunately, there are some regressions and this will be the subject of today’s post.
Imagine an application that has hundreds of assemblies. Now imagine that you want to recompile one of them, put a breakpoint somewhere, and start the main application. It is very simple in the .NET Framework class library. All you need is to go to project properties, go to the “Debug” tab, select “Start external program” and select the main application. Very easy and simple.
Now, let's compare it with the .NET Core class library. After you open the “Debug” tab in the project properties, you need to click on “Open debug launch profiles UI”. In the new window, you will not see any way to specify the path for the application to start. The correct way to do so is to delete this profile and then create a new one by pressing the left top button and selecting “Executable” profile.
This approach has many disadvantages:
- More clicks are needed to access this information
- It should be done for each project
- An extra file will appear in the repository and an extra folder in the Solution Explorer.
- It is not possible to name the profile to be the same as the name of the project. You will have to name it manually and keep it in sync. I spent quite a bit of time on this and it looks impossible or just well hidden.
We have a desktop application and we typically use an environment variable for its location, so all our projects have the same application to start. When we were porting the application to .NET 6 I was thinking of adding a file launchSettings.json to all our projects but it will be hundreds of files.
And then I accidentally found a better solution. All you need to add this to the first PropertyGroup of your project:
<StartAction>Program</StartAction>
<StartProgram>C:\MyPropgram.exe</StartProgram>
After that, you don’t need to mess with launchSettings.json. Unfortunately, there is no UI to edit that path in Visual Studio but you can just double-click on the project file in the Solution Explorer and edit it directly.
I hope it helps someone.