Is it possible to specify executablePath as a relative path in launchsettings.json?
Asked Answered
M

2

7

I'm looking at a project written by an ex-colleague, in the file launchSettings.json (under Properties) he has the following:

{
  "profiles": {
    "ProjectName": {
      "commandName": "Executable",
      "executablePath": "C:\\code\\project\\\\src\\project.name\\bin\\Debug\\net471\\NServiceBus.Host.exe"
    }
  }
}

Where that executablePath is the path to where his local repository was. But ofcourse, other team members will not have the same local path. Which is fine and not something we should enforce.

Two questions:

  • Why is it there, what's it's purpose?
  • Can this be a relative path? -> Yes it can

-> "..\net471\NServiceBus.Host.exe"

Merchantman answered 22/1, 2019 at 7:4 Comment(2)
What happened when you tried a relative path?Enroot
I guess that just works ... :DMerchantman
E
6

Yes, relative paths just works (e.g. .\NServiceBus.Host.exe, no need to go to the parent folder with ..\ and then back to the same folder, .\ means current folder).

And Properties/launchSettings.json can also process all the MSBuild reserved and well-known properties.

I used $(MSBuildProjectDirectory) to get the path of the source project (outside the bin folder). For instance, this takes me to another project which is a sibling of the one I'm running:

"profiles": {
  "MyApp": {
    "commandName": "Project",
    "commandLineArgs": "$(MSBuildProjectDirectory)/../Tests",
  }
}
Ethe answered 29/12, 2021 at 20:37 Comment(0)
H
0

You may use AppContext.BaseDirectory in your code and concat link from launchsettings.json file.

AppContext.BaseDirectory value corresponds to the AppDomain.BaseDirectory

Highly answered 22/1, 2019 at 7:12 Comment(2)
That docs page is very minimal, an actual example would make your answer easier to understand.Merchantman
The AppContext.BaseDirectory property returns the directory in which the currently main executable resides. Try using and check what you get?Highly

© 2022 - 2024 — McMap. All rights reserved.