VS Arduino
Visual Micro >> Ideas, Suggestions and Related Tools >> Custom VisualMicro template.
https://www.visualmicro.com/forums/YaBB.pl?num=1662051833

Message started by Groover on Sep 1st, 2022 at 5:03pm

Title: Custom VisualMicro template.
Post by Groover on Sep 1st, 2022 at 5: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. :-/

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



Screenshot_2022-09-01_template_001.png ( 65 KB | 1 Download )
Screenshot_2022-09-01_CeateNewProect.png ( 195 KB | 1 Download )

Title: Re: Custom VisualMicro template.
Post by Tim@Visual Micro on Sep 1st, 2022 at 6: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++)




Title: Re: Custom VisualMicro template.
Post by Groover on Sep 2nd, 2022 at 8: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>[/code):



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



 
https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=CustomTemplate_-_Copy.zip ( 17 KB | 1 Download )

Title: Re: Custom VisualMicro template.
Post by Tim@Visual Micro on Sep 2nd, 2022 at 9: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.

Title: Re: Custom VisualMicro template.
Post by Groover on Sep 2nd, 2022 at 12: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>[/code):



     
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

Title: Re: Custom VisualMicro template.
Post by Tim@Visual Micro on Sep 2nd, 2022 at 12: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-templates?view=vs-2022



Title: Re: Custom VisualMicro template.
Post by Groover on Sep 4th, 2022 at 8: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?







Title: Re: Custom VisualMicro template.
Post by Tim@Visual Micro on Sep 4th, 2022 at 11:18am
Easiest thing is to zip and attach the resulting project.

Title: Re: Custom VisualMicro template.
Post by Groover on Sep 4th, 2022 at 1: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
https://www.visualmicro.com/forums/YaBB.pl?action=downloadfile;file=ArduinoSpecialEmptyProject.zip ( 87 KB | 1 Download )

Title: Re: Custom VisualMicro template.
Post by Tim@Visual Micro on Sep 4th, 2022 at 1: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$
*/[/code]

I suggest that you attach your template too

Title: Re: Custom VisualMicro template.
Post by Groover on Sep 4th, 2022 at 2:23pm
Attached two screen-shots, one as OpenedFromFileExplorer, the other as Create New Project.

OpenedFromFileExplorer.png ( 503 KB | 1 Download )
OpenedAsCreateNewProject.png ( 517 KB | 2 Downloads )

Title: Re: Custom VisualMicro template.
Post by Tim@Visual Micro on Sep 4th, 2022 at 3: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.

Title: Re: Custom VisualMicro template.
Post by Groover on Sep 4th, 2022 at 3: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.

Title: Re: Custom VisualMicro template.
Post by Tim@Visual Micro on Sep 4th, 2022 at 3: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.

VS Arduino » Powered by YaBB 2.6.12!
YaBB Forum Software © 2000-2024. All Rights Reserved.