HOWTO: How to create a remote compiling project in Visual Studio .NET

Introduction

This work was inspired by misterj's attempts at building a remote compiling solution. This approach doesn't involve sticking passwords anywhere and also integrates the functionality into Visual Studio rather than have it all just be run by macros. Finally, build output can be viewed with this approach.

{Ed's note - If anyone wishes to combine Sauce's and misterj's efforts into a single HOWTO, please go ahead and submit it!}

Initial Setup

This stuff needs to be done only once and you'll be good to go with every project.

Install and start the ssh daemon, sshd

Initially, you need to have sshd installed and running. I'll let that be an exercise for the reader. {Ed: or another HOWTO...} Two hints -- make sure the needed ssh* rpms from disc 2 are installed, and then use chkconfig to make sure that sshd is started in run-levels 3, 4 and 5.

Reboot and get it working. You can test this by using ssh (even from your ps2) to connect to your ps2.

Getting your ssh to let you in without a password

First, go to http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html and download plink.exe and puttygen.exe. I'm assuming they're both in c:\, make sure to adjust the path names as appropriate.

Before you go any further, make sure ssh is working from your pc. On your PC, run:
c:\plink < user> @< ps2 hostname/ip address> ls
It should ask you for your password, and then show you the contents of your home directory on your ps2.
< user> is your login name on the ps2
< ps2 hostname/ip address> is either the host or IP address of your ps2. If you have set things up so your pc can talk to your ps2 using its host name (eg by putting an entry in the hosts file or by configuring a name server), then you should be able to use the host name, otherwise you should stick to the IP address.
Note From now on, I will use the username of "sauce" and the hostname of "myps2". The command above would read:
c:\plink sauce@myps2 ls

Next thing you want to do is make things so that it does not ask you for a password each time you connect, and so that you don't have to hard-code your password in your Visual Studio project files.

  1. Run c:\puttygen.exe
  2. Make sure SSH1 (RSA) is selected
  3. Click Generate
  4. Move your mouse as instructed to generate the key
  5. Click on save public key and save it. I'll use the filename c:\ps2key.pub
  6. Click on save private key and save it. I'll use the name c:\ps2key.ppk
    It'll warn you that you're saving the key without a passphrase. It basically means that if anyone gets their hands on ps2key.ppk, they'll be able to sign on to your PS2 as your user name, provided that they can get to your PS2 and know your user name.
What you have now is a pair of matching files that will act as your password. One of these files needs to sit on the ps2, and the other one needs to be accessible by your PC. They are a "public" key that the whole world can know and a "private" key that you keep to yourself, kind of like your password. The two keys are linked together, so if something is "locked" with the public key, it can be unlocked only with the private key. To configure your ps2:
  1. Transfer the file ps2key.pub over to your PS2 using your favorite method, such as samba. For example, on your PC type:
    copy c:\ps2key.pub \\myps2\sauce
  2. On your ps2, make sure there is a .ssh directory in your home directory.
    mkdir ~/.ssh
    chmod 755 ~/.ssh
  3. cat ps2key.pub >> ~/.ssh/authorized_keys
    This step says that anyone who has the private key that matches the public key you just gave it should be able to log on to your system.
  4. chmod 600 ~/.ssh/authorized_keys

Now test it from your PC. Run:
c:\plink sauce@myps2 -1 -i c:\ps2key.ppk ls
You should see your directory listing without being prompted for a password.
If this doesn't work, go back and double check your work.

Creating a VS .NET Project

Now that we've got the initial work out of the way, we're ready to create a VS .NET project that will do all the magic we want it to do. We've created a framework that allows us to execute programs on our PS2 (using plink.exe) from our PC without being prompted for a password each time.

Let's take those tools and make a project that works remotely.

Assumptions

Creating the project

In this HOWTO, we'll create a project from scratch and add source files from scratch. In general, you'll want to create a project and configure it to make and execute properly, but you may already have some existing source files that you'll want to work with as well as new ones. We'll also create a small program to illustrate that standard I/O works as expected over this networked setup.
All these steps are on your PC, in Visual Studio .NET
  1. Go to file, new project, Makefile project
    For location, enter \\myps2\sauce
    For name, enter myproject
  2. Click finish
  3. In the solution explorer, right-click on "myproject" select "Add -> New Item"
    Call it main.cpp
    Enter the following code:
    
    #include < stdio.h> 
    
    int main() {
    	char acName[32];
    	printf("Enter your name: ");
    	fflush(stdout);
    	scanf(acName);
    	printf("Hello, %s\n", acName);
    	return 0;
    }
    
    

    {Ed: Leave the scanf line as it is - It should generate an error which we want to test later}

  4. Go to File->New->File and select text file type Enter the following into your new text file. This will be your make file:
    all: iotest
    
    iotest: main.cpp
    	gcc -o iotest main.cpp
    
    clean:
    	rm -f iotest
    
    Now save this file as \\myps2\sauce\myproject\Makefile. Unfortunately, I know of no way to tell visual studio not to stick a .txt at the end of it, so rename the file from Makefile.txt to Makefile using explorer.
  5. Now add the makefile to your solution. In the solution explorer right click on myproject, select add->existing item->Makefile

    You've now got your Makefile in your skeleton project. This makefile will have all the build commands necessary to build your project (which is very simple for now). Now that we've done all this nonsense, we actually start to do something constructive.

  6. In the solution explorer right click on myproject and select properties.
      In the debugging tab:
    1. Replace whatever value is in Command -- probably $(TargetPath) -- with c:\plink.exe
    2. Set Command Arguments to: sauce@myps2 -1 -i c:\ps2key.ppk "cd ~/myproject;./iotest"

      You've told visual studio that when you select run or debug, you want it to start up plink, to connect to your ps2 using your private key file, and on the ps2 to change to the project directory and run iotest

      In the NMake tab:

    3. Set the Build Command Line to: c:\plink sauce@myps2 -1 -i c:\ps2key.ppk "cd ~/myproject;make"
    4. Set the Rebuild All Command Line to: c:\plink sauce@myps2 -1 -i c:\ps2key.ppk "cd ~/myproject;make clean all"
    5. Set the Clean Command Line to: c:\plink sauce@myps2 -1 -i c:\ps2key.ppk "cd ~/myproject;make clean"
    6. Set the Output to iotest

      You're telling visual studio that when you select one of these build commands, it should connect to your ps2 using plink.exe and your private key file, change to the project directory, and run the appropriate make syntax. Note that "Rebuild All" first deletes everything with the "clean" and then builds everything with the "all" This only works if your makefile has both clean and all targets as the example one above did.

That's it! Now, let's test it out.

You should see your program running and be able to interact with it, even though it is executing on the PS2.

The Rebuild Solution and Clean solution functions in Visual Studio should also work.

Notes

First, running your program does not necessarily build it. You'll have to remember to build it each time you run it or create a macro to do both. Another alternative is to change the plink command when you actually run it to invoke make before running your program, but now you're confusing functions of the system -- not the most elegant approach.

Second, you have two lists of source files. The first resides in the Makefile. This one is the one that is most crucial -- it will drive the build, and do all the magic. On the other hand, if you add the source files to the solution you will also be able to browse the source more quickly using Visual Studio's various features. When it comes to deploying your stuff, you need only your sources and the Makefile. The Visual Studio solution + project is purely ornamental -- a shell to enable the remote compilation.