Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

Thanks.

like image 629
goombaloon Avatar asked Jan 23 '11 16:01

goombaloon


2 Answers

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 -->
   <PlatformTarget>AnyCPU</PlatformTarget>
   <DebugSymbols>true</DebugSymbols>
   <DebugType>full</DebugType>
   <DefineConstants>DEBUG;TRACE</DefineConstants>
   <ErrorReport>prompt</ErrorReport>

   <!-- actual output path and start action definition -->
   <OutputPath>$(MSBuildProjectDirectory)\bin\</OutputPath>
   <StartAction>Program</StartAction>
   <StartProgram>$(OutputPath)NServiceBus.Host.exe</StartProgram>
   <StartArguments>NServiceBus.Integration</StartArguments>
</PropertyGroup>
like image 138
cfbarbero Avatar answered Oct 11 '22 14:10

cfbarbero


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

<StartAction>Program</StartAction>
<StartProgram>$(MSBuildProjectDirectory)\Path\Relative\To\CSProj\Folder</StartProgram>
<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.

like image 34
Patrick Earl Avatar answered Oct 11 '22 14:10

Patrick Earl