Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 
When Logging a Support Issue in the Forum, please ensure you have also:-
  • Enabled vMicro > Compiler > Show Build Properties and Verbose
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
Support requests without the output above may be impossible to answer, so please help us to help you
 
  HomeSearch Tutorials & Wiki visualmicro.com LoginHelpRegister  
 
Page Index Toggle Pages: 1
Send Topic Print
AdditionalIncludeDirectories in project files causes GIT merge conflicts (Read 1444 times)
Fergazoid
Newbies
*
Offline



Posts: 6
AdditionalIncludeDirectories in project files causes GIT merge conflicts
Sep 19th, 2018 at 9:45pm
 
The <AdditionalIncludeDirectories> tag in a Visual Micro project file (.vcxproj) is apparently updated as part of the build process. The data in this tag is machine-dependent, as library locations will likely change from machine to machine. Merely syncing a GIT repo to changes from another machine will virtually guarantee a merge conflict every time. Then a simple build will cause a local change to the project file which will then get needlessly pushed with other local changes. The cycle continues causing needless confusion and effort to revert, undo or resolve conflict merges.

This <AdditionalIncludeDirectories> data would best be kept in a separate file that can be excluded from GIT via .gitignore, etc.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #1 - Sep 20th, 2018 at 12:18am
 
Hi,

It's not used in the build process. The only way to allow VS intellisense to know where files are is to populate this property. This is the only reason why it is populated and it should sync to each machine. It's possible if you install arduino and your project with the same file structure across all machines the property will not have to alter so often.

Arduino packages can be located in locations other than app-data\user_name so that might help however I expect you are going to see some git change suggestions that are false due to having to manipulate the project properties for intellisense.

Back to top
 
WWW  
IP Logged
 
Fergazoid
Newbies
*
Offline



Posts: 6
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #2 - Sep 20th, 2018 at 7:26am
 
Visual Micro wrote on Sep 20th, 2018 at 12:18am:
It's possible if you install arduino and your project with the same file structure across all machines the property will not have to alter so often.

(1) I can control the Arduino program location during install. I can control sketch location with preferences. But I cannot find any way to control where include files and libraries are installed. Nothing in 'preferences' or 'preferences.txt'.

(2) The include files actually ARE installed in the same location, but since it's in a Users\<name>\ subdirectory it's not generally possible to make these paths identical across all users/machines. I suspect VisualMicro could probably use the $(USERPROFILE) macro in this context to make these settings identical across machines and users.

(3) Even with the same username, VisualMicro goes too far in trying to make relative paths for these settings.
On a machine with the includes and projects on the different drives I get:
   C:\Users\<name>\AppData\Local\arduino15\...
while on a machine with the includes and projects on the same drive I get:
   $(ProjectDir)..\..\..\Users\<name>\AppData\Local\arduino15\...
This is going all the way to the root and back up just to make a relative link! The settings have been made different with NO added value! The same problem occurs for ALL paths on the C: drive, such as:
   $(ProjectDir)..\..\..\Program Files (x86)\Arduino\libraries

Recognizing these cases and using the proper macros, where available, to provide more generic settings could solve these problems. Even not going so far as the root to create a relative link would help in most cases since these directories are almost always on the C: drive.

Thanks for listening!
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #3 - Sep 20th, 2018 at 11:04am
 
You can create a folder called \Portable under arduino ide folder.

Move/copy \arduino15 into \portable then restart all ide's

You can also use the .zip install for arduino and locate the ide in a better location. You do not need to run the windows installer to install arduino, it's only required for usb driver install which is already done for you.
Back to top
« Last Edit: Sep 20th, 2018 at 11:05am by Visual Micro »  
WWW  
IP Logged
 
Fergazoid
Newbies
*
Offline



Posts: 6
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #4 - Sep 20th, 2018 at 6:25pm
 
I appreciate the effort to provide workarounds for this problem. Trust me when I say the pain of making every machine look identical for Visual Micro rivals or exceeds the pain of the problem being circumvented.

I just wanted to get my idea and suggestion to the right people. It's a quite simple solution, whether it makes the cut or not. I'll condense the suggestion here for clarity:

The proper use of macros by Visual Micro in the C++ project (.vcxproj) files for <AdditionalIncludeDirectories> entries would eliminate the needless merge conflicts that occur between multiple machines under source code control. Specifically, the use of the macros $(USERPROFILE) and $(ProgramFiles) would make the paths for include files, libraries and packages identical across all default Arduino installations.

Thanks!
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #5 - Oct 20th, 2018 at 6:28pm
 
Thanks, I agree.

If you can provide an example of how to set a vs macro for global use but to allow it to be altered without restarting the ide or re-opening the project that would be a big help.
Back to top
 
WWW  
IP Logged
 
Fergazoid
Newbies
*
Offline



Posts: 6
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #6 - Oct 20th, 2018 at 10:05pm
 
Visual Micro wrote on Oct 20th, 2018 at 6:28pm:
Thanks, I agree.

If you can provide an example of how to set a vs macro for global use but to allow it to be altered without restarting the ide or re-opening the project that would be a big help.

There is no need to actually SET any macro to solve this problem. Just use the macros already available in Visual Studio. The $(USERPROFILE) and $(ProgramFiles) macros are already system-defined and reliable. It would be overkill (and ill-advised) to process all the macros provided by VS. But those two macros should cover virtually all the needs in this case. (With better knowledge of additional locations where Arduino include files typically reside, you might be able to identify a couple more macros worth using.)
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #7 - Oct 23rd, 2018 at 9:08pm
 
How do the macros you mention relate to arduino?
Back to top
 
WWW  
IP Logged
 
Fergazoid
Newbies
*
Offline



Posts: 6
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #8 - Oct 24th, 2018 at 5:04am
 
Visual Micro wrote on Oct 23rd, 2018 at 9:08pm:
How do the macros you mention relate to arduino?

I thought this was clear enough, but perhaps you'll have to pass this on to your developers for a more thorough understanding of the topics discussed.

Here is an excerpt from the AdditionalIncludeDirectories settings from my Visual Micro project file, AS CREATED BY VISUAL MICRO.
(In this specific case, this file is located at "D:\Projects\mSlider\mSlider\mSlider.vcxproj" on my desktop computer.)

     <AdditionalIncludeDirectories>
     $(ProjectDir)..\mSlider;
     C:\Program Files (x86)\Arduino\libraries;
     C:\Users\Scott Ferguson\OneDrive\Documents\Arduino\libraries;
     </AdditionalIncludeDirectories>

Here are the relevant macros and their definitions:

     $(ProjectDir) ==> D:\Projects\mSlider\mSlider\
     $(ProgramFiles) ==> C:\Program Files (x86)
     $(USERPROFILE) ==> C:\Users\Scott Ferguson

You're already using the $(ProjectDir) macro in the first case. This is GOOD.
In the second and third cases you are referencing machine-specific and user-specific drives and directories. This is BAD.
This causes problems for source code control systems, such as Git, because each project team member or machine
will almost certainly have to have a DIFFERENT version of the file, causing constant merge conflicts.
When better, more transportable options are readily available, this should be considered a BUG!

Here is what those project settings paths SHOULD look like using the proper macros:

     <AdditionalIncludeDirectories>
     $(ProjectDir)..\mSlider;
     $(ProgramFiles)\Arduino\libraries;
     $(USERPROFILE)\OneDrive\Documents\Arduino\libraries;
     </AdditionalIncludeDirectories>

These settings are machine-independent and user-independent and are therefore transportable. This is GOOD.

To highlight an additional problem (BUG) in Visual Micro, here is the same project file excerpt after
loading and use on my laptop computer where it is located at "C:\Projects\mSlider\mSlider\mSlider.vcxproj".

     <AdditionalIncludeDirectories>
     $(ProjectDir)..\mSlider;
     $(ProjectDir)..\..\..\Users\Scott\OneDrive\Documents\Arduino\libraries;
     $(ProjectDir)..\..\..\Program Files (x86)\Arduino\libraries;
     </AdditionalIncludeDirectories>

Because the second two cases have paths on the same drive as the Project file, Visual Micro attempts
to use the $(ProjectDir) macro where it does NOT apply, creating a relative path that goes all the
way to the root of the C: drive and back up to find libraries in the "Users" directory and the "Program Files (x86)" files
directory. This is BAD. These problems would all be resolved through proper use of the above macros.
The project file would not need to change and create merge conflicts in source code control for every user and every
system it appears on.
This is the way Visual Studio itself saves settings in a machine-independent and user-independent way.

These macros are present on ALL systems and therefore can be used without having to create, modify or set any macros.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #9 - Oct 24th, 2018 at 12:51pm
 
The USERPROFILE might help in a few cases but it's not as easy as you think.

$(ProgramFiles)\Arduino\libraries;
   You have assumed that users have installed arduino into program files. That's a big mistake Smiley


$(USERPROFILE)\OneDrive\Documents\Arduino\libraries;
   You have assumed that people have not altered the location of their SketchBookFolder in the arduino ide or in visual micro

There are many other paths to consider, not just your examples. It also is important to consider what board you are using because that also changes the paths.

Summary

From your replies I can see you have not given thought to how you might better install and configure your locations. Some tips below that will help.

1) Grab the zip of the arduino ide and unpack it to some standard easy to manage folder or share. Then reconfigure visual micro to look at that path. If it is on the same drive as the project then visual micro should fallback to using relative paths so you can keep directory structures the same across drives.

2) Change your sketchbook location to something of similar ilk to 1) but not a child of the ide and make sure the ide is not a child of the sketch book.

3) If you are using board manager to install hardware then create a folder below the arduino ide called Portable. Move/copy the contents of c:\users\name\appdata\local\arduino15 into ide\roaming.

Now you will have all paths at better locations.



Back to top
 
WWW  
IP Logged
 
Fergazoid
Newbies
*
Offline



Posts: 6
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #10 - Oct 24th, 2018 at 8:44pm
 
Visual Micro wrote on Oct 24th, 2018 at 12:51pm:
...it's not as easy as you think... You have assumed... That's a big mistake... you have not given thought...

I have made no mistake and have assumed nothing except that you understood how to use the system's predefined macros in Visual Studio to implement an extension. It is as easy as I think! To clarify...

At some point when the Visual Micro project file (.vcxproj) is being written, you are providing a list of paths to be a part of the <AdditionalIncludeDirectories> XML tag within that file. You've gone through some process to identify where all the required include files for the project are located and have made a list of paths. Before committing that list of paths to that XML tag, you process each individual path. You look up the definitions for the macros you want to use. Somewhere in the API for Visual Studio Extensions there's a way to do this. It's been a while since I looked at that API so I can't tell you exactly what it is and how it's used. But you give it the name of a macro, e.g. "ProgramFiles" or "USERPROFILE", and it returns to you their definitions which are paths to folders on the user's system. Worst case you can use regular system APIs to look up the environment variables these macros derive from. For each path in the list you look to see if the string starts with the definition of a macro. If it does, you replace that substring with the macro. For example, in my case:

     $(USERPROFILE)
is defined as
     C:\Users\Scott Ferguson"

so the path
     "C:\Users\Scott Ferguson\OneDrive\Documents\Arduino\libraries"
becomes
     "$(USERPROFILE)\OneDrive\Documents\Arduino\libraries"

It's a simple search-and-replace string operation. If that macro doesn't match, you try the next. If none match, you leave the path alone and no harm is done. No mistake is made. You've not assumed anything about the location of the libraries. You KNOW where they are and you don't use the macro unless it applies to the path in question. But because the macro definition is specific to that system and user, you've eliminated the difference and made the path machine-independent and user-independent! When the project file is reloaded on the same system, or any other, you reverse the process to restore the actual path to get the best chance at finding the proper files. If the users are relying on the default installation location for the IDE and libraries, you've gained portability. If not, then the macros will not have been applied and what you're doing right now (making everything relative to the Project directory) will stand as good a chance to work as it ever did. (It could, and does, fail regularly!)

This process is already being done somehow for the $(ProjectDir) macro.
NOTE: It should be obvious that you must do this macro replacement BEFORE you mangle the path by trying to make it relative
to the $(ProjectDir) location.

I HAVE given thought to what I could do to manually intervene with the default placement of Arduino files as a workaround for this problem. I could reinstall ALL my Arduino IDE files and libraires to non-default locations and move ALL my projects to the same drive as the libraries to overcome this issue. As I said before, such an effort, for me, exceeds the problem being solved. (and in the latter case, may not even be feasible!) I'm suggesting that you could more easily FIX the problem rather than requiring your impacted clients to work around it with the effort you suggest. By default the Arduino IDE places these files in the "Users" and "Program Files (x86)" paths. So BY DEFAULT, using just those two macros can solve this problem for the vast majority of your clients. A small amount of work to save a larger amount of work multiplied by the number of affected users. Granted, I may be the only client you have using source code control and wanting a fix for this. I have no clue as to the size of your user base nor how many might use source code control. So I respect that your cost-benefit analysis applied to bug resolution may not get to this soon. But it should be a simple effort with negligible risk, so the cost should be relatively small.
Back to top
 
 
IP Logged
 
Visual Micro
Administrator
*****
Offline



Posts: 10395
United Kingdom
Re: AdditionalIncludeDirectories in project files causes GIT merge conflicts
Reply #11 - Oct 26th, 2018 at 1:00pm
 
The arduino ide can be unloaded from the zip on their web site and the libraries will only exist in your sketchbook\libraries folder so it's easy to move them. An arduino project does not remember paths so your ide and libs should continue to work if their location is changed.

It's a much simpler job that my having to mess about with include paths especially because different versions of arduino can use different locations and atmel studio has different macros defined. This means a lot of testing when includes change.

However, as I said it's an idea to pick a couple of known macros and try to add support for them. I will do that when I get some spare time.
Back to top
 
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print