Andreas
Andreas

Reputation: 19

VB.NET 2017 refer to .exe file within my project

Hello been searching for a while but all I get are results that is talking about moon travel and e=mc2.

So in order to be as specific as possible I'll include screenshots :)

  1. I run Microsoft Visual Studio 2017
  2. Form based application
  3. My knowledge is basically zero, i study code-test and get the results eventually.

Story:

I've added an .exe file within my project like so; Screenshot of Solution Explorer What I want to do is to press a button and it will launch the application:

    Private Sub RunVersion11ToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RunVersion11ToolStripMenuItem.Click
    Dim TeamViewer11Path As String = ("C:\Program Files (x86)\TeamViewer\TeamViewer.exe")
    Process.Start(TeamViewer11Path)

End Sub

Private Sub RunVersion12packedToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles RunVersion12packedToolStripMenuItem.Click
    Dim TeamViewer12Path As String = ("?!?!?!?! this file is included in the proj as seen in picture 1, the Private Sub above this is a locally installed one.")
    Process.Start(TeamViewer12Path)
End Sub

As you can see above the first sub executes an application that is already installed on the machine. The 2nd sub I want to run the .exe as shown in the above picture.

However after googling etc, everything is refering to the full path of the file like: C:\Users\XXXX\documents\visual studio 2017\Projects\WindowsApp6\WindowsApp6\ts12.exe

But obviously this wont work if I run the application on another computer.

What I want help with:

What should I put in my Process.Start to point to a file included in the solution explorer? like Process.Start("\root\app\ts3.exe") or similar, that works both in debug and release.

Please note that I'm a newbie, so please provide examples that makes sense for someone way below your own level of expertise. Thanks! :)

Upvotes: 1

Views: 1169

Answers (1)

NoAlias
NoAlias

Reputation: 9193

You'll want to ensure that the Copy to Output Directory property on the .exe file in your solution explorer is set to Copy If Newer or Alway Copy.

Code to get to the output directory:

    Dim strOutputDirectory As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)

    Process.Start(System.IO.Path.Combine(strOutputDirectory, "ts12.exe"))

Upvotes: 1

Related Questions