1

Consider these two software: MyGame.exe and SocketTest.exe.

MyGame.exe doesn't depend on any files to run but SocketTest.exe is an actual software. It can only run if one or more of four other files are in the same folder as itself. These files are: metouia.jar, SocketTest.bat, SocketTest.jar, SocketTest.sh

I want to create a software using Windows Form in Microsoft Visual Studio using C#. It will have two buttons: "Launch MyGame" and "Launch SocketTest."

I go to the Solution Explorer tab and right-click my .csproj file to click Add Existing Item... so I can add MyGame.exe, SocketTest.exe and the other four files into the Solution Explorer.

For the File Properties of the 6 files, under "Copy to Output Directory" I choose "Copy Always."

For Build Action, I'm not sure. I use "None". My buttons can still launch the two .exe files.

However, I'm not sure which settings to use if I want other computers to be able to launch those .exe files with my software, especially for the .exe file that depends on other files. I've read the Build Action descriptions (online too) but still can't decide on the proper one for my situation.

Stoverflow
  • 65
  • 6

2 Answers2

0

The way your're doing it is fine. A few notes:

  • Instead of "Copy Always", you can use "Copy only if newer"
  • For "Add Existing Item...", instead of adding the items directly, you can pull down the "Add" button and select "Add link" - this will keep the files in sync with the source items, in case they are updated
  • Build action "none" is correct. You are not building these items, just copying them to your output folder.

Whatever you do with your project -- publish, deploy, etc -- the added items will stay with your project output.

Good luck!

Pancake
  • 739
  • 1
  • 5
  • 20
  • Thank you, sounds simple enough but wouldn't using "Add As Link" instead of "Add" means my software won't be able to launch the two .exe files on a friend's computer if my friend's computer doesn't have those two .exe files? – Stoverflow Jul 13 '18 at 06:31
  • Your friend's computer WILL have those .exe files. The only difference between "Add" and "Add with link" is that "Add with link" keeps the files in your project synchronized with the original source files during development. So if you update the original files, the updates are reflected in your project. This is preferred over MickyD's approach because the artifacts are actually part of your project and handled as expected in conjunction with the rest of your project structure. For example, they are cleaned when you clean the project. – Pancake Jul 13 '18 at 08:59
  • Hi there, thanks for the clarification but I tried running my built software on a friend's computer and upon trying to launch either of the two .exe files, an Unhandled Exception error occurred, saying the required files are not found. What am I doing wrong? – Stoverflow Jul 18 '18 at 08:05
  • If you have verified that all of the intended files were deployed to your friend's machine, then this means there are additional dependencies on your machine, outside of the MyGame and SocketTest bin folders. Does the exception provide any detail about which files are missing? – Pancake Jul 19 '18 at 17:19
  • My friend's computer isn't meant to have those files. He just needs to run my program which will then launch the two .exe files. As a test, I even added a .pdf file which can be opened if a button in my program is run. Same Unhandled Exception occurred on the friend's computer when he tried opening the file. In fact, strangely, when I tried to launch SocketTest.exe from my built program, I get the same error. The program only works when run in Visual Studio. Anyway, the Unhandled Exception error is: "The system cannot find the file specified." – Stoverflow Jul 24 '18 at 09:31
0

Rather than adding artefacts into your launcher which just produce noise as far as the .csproj is concerned, consider using build events.

Right click your launcher's project, choose Properties then Build Events. In the Post-build event command line enter appropriate copy commands to copy your binaries and artefacts from your other project folders to your launcher's OutDir folder.

Anything more and you should probably look into making an installer.