Relative Paths for Arduino Projects in Visual Studio

The dynamic nature of the Arduino configuration means the locations of tool chains and the arduino source code can not easily be held in system wide environment variables.

This can be a problem in multi-drive scenarios and when syncronising projects in multiple location via source control.

Visual Micro will attempt to use relative paths whenever possible and if the paths match over multiple computers source control will be much happier.

With some thought the locations of the various components can be structured in a way to make that can be easily replicated on different drives. The Arduino IDE, the sketchBook folder, tool chains and project source code need to be located on the same hard drive in a known structure (ie: D:\arduino\)

This can be done as follows assuming the project source will be held on D: this following example locations keep everything close together and in a simple structure that can easily be replicated

tip: The zip download of the arduino ide from arduino.cc is all that most existing users need to use to have a fully working arduino ide. The windows installer installs usb drivers that rearely change and that can also be installed via board manager or from the \drivers folder below the arduino ide

Locations

1. For this example we use a top level folder called Arduino that will never contain any files, only folder.

d:\arduino

2. The arduino ide can be unzipped into "d:\arduino\ide". If you onlt ever work with one version of the arduino ide then do not give a folder name containing the version of arduino. Keep the name generic so that you can easily upgrade the ide at a later date without needing to alter the Ide location in the Visual Micro "Ide Locations" configuration window. Don't foget to update the arduino ide path in the "visual micro ide locations" window when you make this change!

d:\arduino\ide

3. The arduino ide stored settings and downloaded board support packages in "c:\users\[your name]\appdata\local\arduino15". Copy of move this folder to "d:\arduino\ide\portable". You need to create the "portable" folder manually using windows explorer. After you create the portable folder and add at least the preferences.txt from the "arduino15" folder. Both Ide's will now use and store data in the portable folder instead of in "c:\users\[your name]\appdata\local\arduino15"

d:\arduino\ide\portable

4. The arduino sketchbook folder is the default folder for new projects and also where custom libraries and manually installed custom hardware is installed. The default location is "mydocuments\arduino". Move or copy any existing items in "mydocuments\arduino" into a new sketchbook folder called d:\arduino\sketchbook or d:\arduino\projects. After doing this open the arduino ide file>preferences and set the "sketch book location" to the new sketchbook folder or open visual micro ide locations and set the "sketch book folder" to the new sketch book folder. This folder can also be where you store your projects.

d:\arduino\projects

OR

You might choose to have seperate sketchbook and project folder.

d:\arduino\sketchbook

d:\arduino\projects

Don't forget that whatever folder visual micro and arduino thinks is the "sketchbook folder" might have a sub folder called \Libraries and a sub folder called \Hardware. The Libraries folder is the most common because it is where downloaded and unzipped libraries are installed to.

 

Summary

After making these changes all project paths should automatically switch to relative.

After making these changes restart both visual micro and the arduino ide if they are open.