Using relative path for "Start external program" in VS.NET 2010

relative path linux
relative path | html
relative path example
relative path windows
relative path c
relative path vs absolute path
relative path python
relative path url

I've seen a few posts related to this topic but none with any conclusive answers...

When debugging my VS.NET 2010 app, I'm trying to start an external program whose location is relative to the project path. I've seen some indications that macros (like $(ProjectDir)) were supported in earlier versions of VS.NET, but they don't seem to work in VS.NET 2010. Using relative path notation just gives me an error that the path is invalid.

Has anyone run into this? If so, how did you address?


I know this is a little late to the party, but here's how we do it. The key to this is to set the 'OutputPath' explicitly to the Build directory. This re-bases it to working directory and not the VS install directory.

  1. Update output path for the project to be: <OutputPath>$(MSBuildProjectDirectory)\bin\</OutputPath>

  2. Update StartProgram for the project to be: <StartProgram>$(OutputPath)Relative.exe</StartProgram>

Here is a sample configuration PropertyGroup:

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '0-Local|AnyCPU'">
   <!-- default values you should already have in your csproj -->

   <!-- actual output path and start action definition -->

Paths explained: Absolute, relative, UNC, and URL—Help, Relative path. A relative path refers to a location that is relative to a current directory. Relative paths make use of two special symbols, a dot (.)  Using relative paths, these adjustments are necessary: When moving a map document or toolbox, you must also move the referenced data. When delivering documents, toolboxes, and data to another user, relative paths should be used. Otherwise, the

Similar to what Yobi21 suggested, editing the project file and adding these lines to the main <PropertyGroup> in the project file worked for me:

<StartArguments>Any Required Arguments</StartArguments>

Watch out for the properties in the .csproj.user file overriding those in your regular project file. Note: Starting with Visual Studio 2017, these properties are contained in the launchsettings.json file.

This one stumped me until I deleted the entries.

Absolute vs. Relative Paths/Links, For that reason, you can only use relative links when linking to pages or files within your site, and you must use absolute links if you're linking to a  Relative path. A relative path is always relative to the root of the document, so if your html is at the same level of the directory, you'd need to start the path directly with your picture's directory name: "pictures/picture.png" But there are other perks with relative paths: dot-slash (./) Dot (.

Found the answer here.

In the event that the above link goes dead, the summarized answer is as follows:

  1. Macros don't work here, so forget about that.
  2. Environment variables don't work either, so forget about that as well.
  3. It turns out that Visual Studio.NET (at least 2008 and 2010) uses one of two paths as the base for any relative path specified in the Start external program setting...

If Visual Studio.NET was launched by clicking on the SLN file in Explorer, the base path will be the folder (including the "\") where the SLN resides. Once I modified my relative path to account this and then launched VS.NET 2010 by double-clicking the SLN file, my external program correctly launched when hitting F5.

If Visual Studio.NET was launched from the shortcut on the Start Menu and then the SLN was opened from within Visual Studio.NET, the base path will be [Visual Studio install path]\Microsoft Visual Studio ["9.0" or "10.0" depending on whether using VS.NET 2008 or 2010]\Common7\IDE\.

I guess it makes sense now, but it still kinda stinks that VS.NET will only find my external program correctly depending on how I launch VS.NET.

File path formats on Windows systems, You can use relative paths only by mapping a UNC path to a drive letter. DOS device paths. The Windows operating system has a unified object  To write an absolute path-name: Start at the root directory ( / ) and work down. Write a slash ( / ) after every directory name (last one is optional) Changing directory with relative path concept : $pwd /home/kt $cd abc $pwd /home/kt/abc. Changing directory with absolute path concept: $pwd /home/kt

$(SolutionDir) will not work if you use it directly in VS2010 in the start external programm, but if you close your solution and open the YourProject.csproj.user with notepad, you can change the path and include the $(SolutionDir).

Reopen VS 2010 and it works like a charm.

here an example of my project "ApplicationService_NSB.csproj.user"

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">

HTML File Paths, It is best practice to use relative file paths (if possible). When using relative file paths, your web pages will not be bound to your current base URL. All links will work  If you don't supply the root, it means that your path is relative. The simplest example of relative path is just a file name, like index.html. So one should be careful with relative paths. If your current directory is /about/then index.htmlwould be one, but if you switch it to /contacts/then it will be another.

You can change the .user in notepad while solution is closed to even include relative paths. It is ,however, horrific. Example:


This is without scroll

<StartProgram>$([System.IO.Path]::GetDirectoryName($([System.IO.Path]::GetDirectoryName( $(SolutionDir))))\MyCustomBindir\MyCustomProgram.exe</StartProgram>

The windows predefined folders can be used too.


Remeber the xml conifg .user file is parsed when loading the solution not when pressing the Start debug button so any changes to the .user file must happen while the solution is closed.

Absolute vs Relative Path - Which Should You Be Using?, Learn more about the differences that exist between an absolute and relative path. This article explains which method you should use and why. Relative path is defined as path related to the present working directory (pwd). Suppose I am located in /var/log and I want to change directory to /var/log/kernel. I can use relative path concept to change directory to kernel changing directory to /var/log/kernel by using relative path concept.

What is a Relative Path?, Computer dictionary definition of what relative path means, including to "https://​" only using ". It is best practice to use relative file paths (if possible). When using relative file paths, your web pages will not be bound to your current base URL. All links will work on your own computer (localhost) as well as on your current public domain and your future public domains.

Relative path in HTML, If you use an absolute path, / would point to the root of the site, not the root of the document: But there are other perks with relative paths:. Use $PSScriptRoot to build absolute file paths from relative ones to make your script and supporting files portable and resilient. As part of this, it is a good practice to create a new folder to become that common root when you start developing a new script that will have supporting files.

How to use relative paths on windows CMD?, Relative paths. Paths, and relative ones, work very similar to what you have in OS X/macOS. Windows uses "\", not "/". Basically ".." is one level higher. Example. Hi All, I am making an analysis tool that uses two Excel file sources via Power Query. The tool work well, but as soon as the file and source files are moved to another location it stops working as the Queries sources from aboslute paths. Can I modify my Sourcing so that as long as the Analysis

  • Macros can still be used, but need to be set manually in the .csproj XML file. After doing this, don't forget to delete the relevant sections from .csproj.user file, if any.
  • I had trouble making your suggestion work. Could you edit your post to include a cut'n'paste of your .csproj file?
  • +1, Awesome. I had fought this for a long time, now we don't need to fight with project settings between dev machines.
  • NOTE: I modified this a little and put these in the main <PropertyGroup> (the one w/o the condition attribute) and changed OutputPath to "$(MSBuildProjectDirectory)\bin\$(Configuration)\" (w/o quotes).
  • To add to @MarkJMiller's comment, i added the <StartAction>, <StartProgram>, and <StartArguments> node to the property group with the following condition, and it works for all debug and release build configs: Condition=" '$(Configuration)' == '' "
  • Sweet! Note the macro can also be an environment variable you have set - in my case I set an Environment variable on all my machines for the root folder for all my code as %CODEZ% which I can use in the .csproj file as $(Codez). As long as the subfolder structure is standardised then it works on all machines.
  • I +1'd the original answer, only to find out that this is a better solution! Adding these properties to the main PropertyGroup works even when you open the solution from within Visual Studio.
  • Awesome. I added those lines twice (once in the debug block, once in the release block) instead of the main properties section. Works great, too.
  • After deleting the .csproj.user file, you can no longer open the Project Properties in VS. Was this not a problem for you guys?
  • Thanks for posting a link to my site. You guys are awesome!
  • I know I'm posting a comment on an answer that's more than 2 years old, but I'd like to clarify this "strange behaviour." It is, actually, not that strange. If I understand correctly, the "Working Directory" concept is one that originates from the OS, not VS itself. As far as the OS is concerned, the working directory is the directory from which VS was invoked (Solution directory when started from the .sln, VS directory when started from link). What may be odd is that VS doesn't explicitly change the working directory whenever a solution is loaded.
  • @MetaFight The strange behavior is that VS allows to use macros like $(TargetDir) anywhere but in the Debug section of the project properties, although in can be set manually in the .csproj file.