Welcome, Guest. Please Login or Register
Arduino IDE for Visual Studio
 
 

Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

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....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
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
Custom VisualMicro template. (Read 897 times)
Groover
Junior Member
**
Offline



Posts: 25
Custom VisualMicro template.
Sep 1st, 2022 at 6:03pm
 
It would be nice to be able to create an custom not so empty project with sub folder(s)and add it to the Visual Studio Create new Project dialogue,when starting Visual Studio.

I know how to create a template with the Project export template wizard,
but then VisualMicro is not included. Undecided

He is an example of what I like it to look like:

Code (C++):
/*
 Name:		CustomTemplate.ino
 Created:	9/1/2022 5:03:45 PM
 Author:	ajkes
*/

#include <Board_Identify.h>

// the setup function runs once when you press reset or power the board
void setup() {
	Serial.begin(115200);
	delay(200);
	Serial.println("");
	Serial.print(F("Board Model: "));
	Serial.println(BoardIdentify::model);
	Serial.print(F("Board Make: "));
	Serial.println(BoardIdentify::make);
	Serial.print(F("Board MCU: "));
	Serial.println(BoardIdentify::mcu);
	Serial.println("");
	// Provided by compiler at compile time.
	const char compile_dateAndTime[] = __DATE__ " " __TIME__;
	Serial.print("Uploaded on : ");
	Serial.println(compile_dateAndTime);
	Serial.println("");
	Serial.println("Setup done");
	Serial.println("");
}

// the loop function runs over and over again until power down or reset
void loop() {

}
 



Maybe it is possible to copy a template myself from the VisualMicro templates folder and modify it,
but I don't know where that is stored or even exists on my computer.

If this is not possible, then maybe add a persistent folder with collected code-snippets to VisualMicro
or the solution explorer or guide me to accomplish this idea myself to work with VisualMicro.

Regards Groover


Back to top
« Last Edit: Sep 1st, 2022 at 6:15pm by Groover »  

Please Register or Login to the Forum to see File Attachments
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline



Posts: 11537
United Kingdom
Re: Custom VisualMicro template.
Reply #1 - Sep 1st, 2022 at 7:52pm
 
The templates in Visual Studio are standard Visual Studio items. You can create templates for any type of project or code.

There are various Visual Studio locations where you can place zip files, each with a template inside. These can be seen in the VS Tools>Options.

The templates supplied with Visual Micro are stored below the Visual Micro extension. Each VS extension can use this facility.

All of the templates from all the locations are combined together when you use the File>New>project wizard.

The Visual Micro extension folder location can be found in "Tools>Options>Visual Micro". Scroll to the end of the options and you will see the "Assembly Location" property.

You can use the Visual Micro templates as an example if you needed, but make sure you put your own extensions (with different names) in the standard Visual Studio user extensions folder. Otheriwse, when you next update Visual Micro your templates will not be displayed.

Templates can include unlimited code files you can also add scripts to customize the wizard when your templates are used.

Keep these rules in mind...

  • The project name and folder name + an .ino file name, must be the same. Otherwise Visual Micro will not see them as Arduino. nb: The Arduino IDE will only recognise the code if the foler name and an .ino name are the same. This is why the rule exists.
  • The project must be of type .vcxproj (vs c++)



Back to top
« Last Edit: Sep 1st, 2022 at 7:57pm by Tim@Visual Micro »  

Tim Leek
home
WWW  
IP Logged
 
Groover
Junior Member
**
Offline



Posts: 25
Re: Custom VisualMicro template.
Reply #2 - Sep 2nd, 2022 at 9:37am
 
Trying, but no luck.
I created a template named Arduino Board Identify setup and placed it in:
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\2spcwvxc.ufv\ProjectTemplates\
Visual Micro\Arduino Board Identify setup
Folder and Files:

src(Folder) file: arduino folders read me.txt
__PreviewImage.png
__TemplateIcon.png
CustomTemplate.ino:

Code (C++):
/*
 Name:		CustomTemplate.ino
 Created:	9/1/2022 5:03:45 PM
 Author:	ajkes
*/


#include "Board_Identify.h"
// the setup function runs once when you press reset or power the board
void setup() {
	Serial.begin(115200);
	delay(200);
	Serial.println("");
	//Serial.print(F("Board Type: "));
	//Serial.println(BoardIdentify::type);	!This returns a nr. like 106, not very useful.
	Serial.print(F("Board Model: "));
	Serial.println(BoardIdentify::model);
	Serial.print(F("Board Make: "));
	Serial.println(BoardIdentify::make);
	Serial.print(F("Board MCU: "));
	Serial.println(BoardIdentify::mcu);
	Serial.println("");
	// Provided by compiler at compile time.
	const char compile_dateAndTime[] = __DATE__ " " __TIME__;
	Serial.print("Uploaded on : ");
	Serial.println(compile_dateAndTime);
	Serial.println("");
	Serial.println("Setup done");
	Serial.println("");

}

// the loop function runs over and over again until power down or reset
void loop() {

}
 



CustomTemplate.vcxproj(atached as .zip)
CustomTemplate.vcxproj.filters:

Code:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Filter Include="Source Files">
      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
    </Filter>
    <Filter Include="Header Files">
      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
      <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
    </Filter>
    <Filter Include="Resource Files">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
	 <Filter Include="Misc Files">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>xml;json;txt;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
  </ItemGroup>
  <ItemGroup>
    <None Include="CustomTemplate.ino" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="__vm\.CustomTemplate.vsarduino.h">
      <Filter>Header Files</Filter>
	   <Filter Include="Misc Files">
      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
      <Extensions>xml;json;txt;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
    </Filter>
    </ClInclude>
    <ClInclude Include="..\..\..\..\Arduino\libraries\Board_Identify-master\src\Board_Identify.h">
      <Filter>Header Files</Filter>
    </ClInclude>
  </ItemGroup>
</Project> 



MyTemplate.vstemplate:

Code:
<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
  <TemplateData>
    <Name>Arduino Board Identify setup</Name>
    <Description>A new Arduino with Board and other useful info in Setup</Description>
    <ProjectType>VC</ProjectType>
    <ProjectSubType>
    </ProjectSubType>
    <SortOrder>1000</SortOrder>
    <CreateNewFolder>true</CreateNewFolder>
    <DefaultName>Arduino Board Identify setup</DefaultName>
    <ProvideDefaultName>true</ProvideDefaultName>
    <LocationField>Enabled</LocationField>
    <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
    <Icon>__TemplateIcon.png</Icon>
    <PreviewImage>__PreviewImage.png</PreviewImage>
  </TemplateData>
  <TemplateContent>
    <Project TargetFileName="CustomTemplate.vcxproj" File="CustomTemplate.vcxproj" ReplaceParameters="true">
      <ProjectItem ReplaceParameters="false" TargetFileName="$projectname$.vcxproj.filters">CustomTemplate.vcxproj.filters</ProjectItem>
      <ProjectItem ReplaceParameters="false" TargetFileName=".CustomTemplate.vsarduino.h">__VM\.CustomTemplate.vsarduino.h</ProjectItem>
      <ProjectItem ReplaceParameters="false" TargetFileName="CustomTemplate.ino">CustomTemplate.ino</ProjectItem>
    </Project>
  </TemplateContent>
</VSTemplate> 



What am I doing wrong?
Regards Groover



 
Back to top
« Last Edit: Sep 2nd, 2022 at 9:40am by Groover »  

Please Register or Login to the Forum to see File Attachments
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline



Posts: 11537
United Kingdom
Re: Custom VisualMicro template.
Reply #3 - Sep 2nd, 2022 at 10:19am
 
Did you start with a visual micro template? They already work.

You don't need to add any visual micro files such as CustomTemplate.vsarduino.h

Use our template as a starting point.
Back to top
 

Tim Leek
home
WWW  
IP Logged
 
Groover
Junior Member
**
Offline



Posts: 25
Re: Custom VisualMicro template.
Reply #4 - Sep 2nd, 2022 at 1:17pm
 
Tried again. I copied the visualmicro_Arduino template and renamed it to visualmicro_Arduino1.
Saved it to the same location:
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\2spcwvxc.ufv\ProjectTemplates\

My template is not shown when I try to create a new arduino project.

To be able to see the difference I changed the lines in MyTemplate .vstemplate from :
Code:
<Name>Arduino Simple Empty Project</Name>
    <Description>A new empty Arduino compatible project</Description> 



     
to:
Code:
<Name>Arduino Special Empty Project</Name>
    <Description>A new special Arduino compatible project</Description>	 




Still not showing.

I need guidelines, because I'm absolute not familiar  with this.

Regards Groover
Back to top
 
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline



Posts: 11537
United Kingdom
Re: Custom VisualMicro template.
Reply #5 - Sep 2nd, 2022 at 1:18pm
 
I suggest you follow my guide about where to put your own templates.

Then follow the MS docs

https://docs.microsoft.com/en-us/visualstudio/ide/creating-project-and-item-temp...


Back to top
« Last Edit: Sep 2nd, 2022 at 1:19pm by Tim@Visual Micro »  

Tim Leek
home
WWW  
IP Logged
 
Groover
Junior Member
**
Offline



Posts: 25
Re: Custom VisualMicro template.
Reply #6 - Sep 4th, 2022 at 9:35am
 
I  followed  Your guide about where to put your own templates.
Also followed the MS docs.

The project name and folder name + an .ino file name, are the same.
The project is of type .vcxproj (vs c++)
     
     Folder:ArduinoSpecialEmptyProject
     Ino file: ArduinoSpecialEmptyProject.ino
     Project: ArduinoSpecialEmptyProject.vcxproj
     
Templates are created.
when starting Visual Studio I have to find the template with the Search for templates box.
When found and clicked. I can create the project, but it is not a Visual Micro project, no Visual Micro tool bars are present.

Tried many variants and all possible locations, but can't get it working!

I use the latest Visual Micro release (22.08.23.01),
Microsoft Visual Studio Community 2022 Version 17.3.2,
Arduino IDE for Visual Studio by Visual Micro   22.0
Visual C++ 2022   00482-90000-00000-AA219

suggestions:
Maybe an Instruction video in All Visual Micro Videos and Tutorial Media?
Add export as Visual Micro template to the Visual Micro Tool bar?






Back to top
 
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline



Posts: 11537
United Kingdom
Re: Custom VisualMicro template.
Reply #7 - Sep 4th, 2022 at 12:18pm
 
Easiest thing is to zip and attach the resulting project.
Back to top
« Last Edit: Sep 4th, 2022 at 12:18pm by Tim@Visual Micro »  

Tim Leek
home
WWW  
IP Logged
 
Groover
Junior Member
**
Offline



Posts: 25
Re: Custom VisualMicro template.
Reply #8 - Sep 4th, 2022 at 2:13pm
 
OK The zipped project attached.
I placed it in:
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\2spcwvxc.ufv\
ProjectTemplates\Visual Micro
Back to top
 

Please Register or Login to the Forum to see File Attachments
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline



Posts: 11537
United Kingdom
Re: Custom VisualMicro template.
Reply #9 - Sep 4th, 2022 at 2:23pm
 
The project opened as an arduino project and even before it was opened the vcxproj file shows the arduino intellisense has been added. That means vm is working (unless you included the information in your template)

After you create the new project please use the solution explorer to open the .ino code, then attach screen shot.

Thanks

ps: the .ino code shows that some of the template properties have been changed incorrectly. but that does not cause a problem.

Code:
/*
 Name:		$safeitemname$.ino
 Created:	$time$
 Author:	$username$
*/ 



I suggest that you attach your template too
Back to top
« Last Edit: Sep 4th, 2022 at 2:25pm by Tim@Visual Micro »  

Tim Leek
home
WWW  
IP Logged
 
Groover
Junior Member
**
Offline



Posts: 25
Re: Custom VisualMicro template.
Reply #10 - Sep 4th, 2022 at 3:23pm
 
Attached two screen-shots, one as OpenedFromFileExplorer, the other as Create New Project.
Back to top
 

Please Register or Login to the Forum to see File Attachments
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline



Posts: 11537
United Kingdom
Re: Custom VisualMicro template.
Reply #11 - Sep 4th, 2022 at 4:14pm
 
The sketch.ino name needs to be the same as the project name and the containing folder.

You .ino is different from the project name, I assume the folder name is same as the project? Therefore you need to correct the .ino file name in the template.
Back to top
 

Tim Leek
home
WWW  
IP Logged
 
Groover
Junior Member
**
Offline



Posts: 25
Re: Custom VisualMicro template.
Reply #12 - Sep 4th, 2022 at 4:39pm
 
I can not find where it is different, but maybe I'm overlooking it.
When Creating New Project  template the sketch.ino will always be different.
Back to top
« Last Edit: Sep 4th, 2022 at 4:47pm by Tim@Visual Micro »  
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline



Posts: 11537
United Kingdom
Re: Custom VisualMicro template.
Reply #13 - Sep 4th, 2022 at 4:50pm
 
The way templates work are a standard part of Visual Studio. New projects always need to use the name the user has entered. That is why Microsoft provide the $variables that can then be used in your templates.

The Microsoft documentation that I provided a link for will explain what variables to use. The Visual Micro template that you start with already provides the functionality.

You need to start again with your template and look carefully at what you change before changing it. You don;t really need to change the "suggested" name at this point. You only need to add code and a code file.
Back to top
 

Tim Leek
home
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send Topic Print