@@ -71,10 +71,23 @@ wstring Project::GetSaveDirectory()
7171wstring Project::GetProjectSaveLocation ()
7272{
7373 auto file = GetSaveDirectory ();
74- file += L" \\ " + name + L" .vcxproj " ;
74+ file += L" \\ " + name + GetProjectExtension () ;
7575 return file;
7676}
7777
78+ std::wstring Project::GetProjectExtension ()
79+ {
80+ switch (projectType)
81+ {
82+ case projecttype_Console:
83+ default :
84+ return L" .vcxproj" ;
85+ case projecttype_CppSharedItemsProject:
86+ return L" .vcxitems" ;
87+ }
88+ }
89+
90+
7891
7992void Project::SetVsVersion (int _vsVersion)
8093{
@@ -553,18 +566,33 @@ void Project::VisitConfigurations(std::function<void (VCConfiguration&)> visitCo
553566//
554567// Clears existing project
555568//
556- void Project::New ()
569+ void Project::New (EProjectType _projectType )
557570{
558571 // Reset parsing variables.
559572 markForPropertyGroup = projectGlobals = xml_node ();
560573
561574 xmldoc.reset ();
562575 guid = GUID_NULL;
563- SetVsVersion (2017 ); // May change without further notice
576+ projectType = _projectType;
577+
578+ switch (projectType)
579+ {
580+ case projecttype_Console:
581+ {
582+ SetVsVersion (2017 ); // May change without further notice
583+
584+ ReflectConnectChildren (nullptr );
585+
586+ Globals.Keyword = keyword_Win32Proj;
587+ Globals.WindowsTargetPlatformVersion = " 10.0.17134.0" ;
588+ }
589+ break ;
590+
591+ case projecttype_CppSharedItemsProject:
592+ ReflectConnectChildren (nullptr );
593+ break ;
594+ }
564595
565- ReflectConnectChildren (nullptr );
566- Globals.Keyword = projecttype_Win32Proj;
567- Globals.WindowsTargetPlatformVersion = " 10.0.17134.0" ;
568596}
569597
570598
@@ -618,13 +646,17 @@ pugi::xml_node Project::project()
618646 if (proj.empty ())
619647 {
620648 proj = xmldoc.append_child (L" Project" );
621- proj.append_attribute (L" DefaultTargets" ).set_value (L" Build" );
649+ if (projectType == projecttype_Console)
650+ proj.append_attribute (L" DefaultTargets" ).set_value (L" Build" );
622651 proj.append_attribute (L" xmlns" ).set_value (L" http://schemas.microsoft.com/developer/msbuild/2003" );
623652 }
624653
625654 // Project configurations
655+
626656 xml_node itemGroup = proj.first_child ();
627- if (itemGroup.empty ())
657+ bool needsSpecialTags = projectType == projecttype_Console;
658+
659+ if (needsSpecialTags && itemGroup.empty ())
628660 {
629661 itemGroup = proj.append_child (L" ItemGroup" );
630662 itemGroup.append_attribute (L" Label" ).set_value (L" ProjectConfigurations" );
@@ -637,13 +669,16 @@ pugi::xml_node Project::project()
637669 if (projectGlobals.empty ())
638670 {
639671 // Project globals (Guid, etc...)
640- projectGlobals = proj.insert_child_after (PropertyGroup, itemGroup);
672+ if (itemGroup.empty ())
673+ projectGlobals = proj.append_child (PropertyGroup);
674+ else
675+ projectGlobals = proj.insert_child_after (PropertyGroup, itemGroup);
641676 projectGlobals.append_attribute (L" Label" ).set_value (L" Globals" );
642677 }
643678 }
644679
645680 // Magical xml imports.
646- if (markForPropertyGroup.empty ())
681+ if (needsSpecialTags && markForPropertyGroup.empty ())
647682 {
648683 proj.append_child (L" Import" ).append_attribute (L" Project" ).set_value (Microsoft_Cpp_Default_props);
649684 proj.append_child (L" Import" ).append_attribute (L" Project" ).set_value (Microsoft_Cpp_props);
@@ -680,10 +715,14 @@ bool Project::Save(const wchar_t* file)
680715 guid = GUID_NULL;
681716 }
682717 else
683- fpath = name + L" .vcxproj " ;
718+ fpath = name + GetProjectExtension () ;
684719
685720 project ();
686- Globals.ProjectGuid = GetGuid ().c_str ();
721+
722+ if ( projectType == projecttype_CppSharedItemsProject)
723+ Globals.ItemsProjectGuid = GetGuid ().c_str ();
724+ else
725+ Globals.ProjectGuid = GetGuid ().c_str ();
687726
688727 fpath = GetSaveDirectory () + L" \\ " + fpath;
689728
0 commit comments