Skip to content

Commit 220ea99

Browse files
Various fixes for C++ project and item templates (#3745) (#3754)
This is a partial adoption of #3619 by @JaiganeshKumaran in order to expedite the merging of the changes from that PR which do not need additional time for discussion. The individual changes that were extracted from the aforementioned PR are as follows: - Removed usage of InitializeComponent as it's no longer recommended by C++/WinRT (see https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent for more details). - Removed Microsoft copyright notice. - Removed #include XAML headers in a template control header. This was in the C++/WinRT templates because a runtime component will not include XAML headers in pch.h, which is no longer the case with a WinUI 3 runtime component. - Made the WinUI 3 runtime component "desktop-only" as WinUI 3 cannot be used by UWP apps. This is a fix for #1780. (Note that unlike the original PR the source directory structure is not being changed in order to minimize potential merge conflicts.) - Removed App.idl because it's empty and not needed. - Indented App.xaml.cpp's content inside the implementation namespace, rather than `using namespace` for consistency with the rest of the code. Also removed `using namespace` for namespaces that aren't actually used (Controls and Navigation namespaces were needed for Frame navigation, which isn't performed in the WinUI 3 template. IInspectable is available as an alias in every WinRT implementation type, thus doesn't require prefixing it with Windows::Foundation). Additionally, this PR replaces `<ProjectTypeTag>uwp</ProjectTypeTag>` with `<ProjectTypeTag>WinUI</ProjectTypeTag>` (or just adds the latter if the former was not present at all) in the item templates. I don't believe this tag is surfaced anywhere in the Visual Studio UI but the consistency makes me happier. --------- Co-authored-by: Jaiganésh Kumaran <[email protected]> (cherry picked from commit 18ada2f)
1 parent cf90544 commit 220ea99

File tree

61 files changed

+119
-237
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+119
-237
lines changed

Diff for: dev/VSIX/ItemTemplates/Desktop/CSharp/BlankWindow/WinUI.Desktop.Cs.BlankWindow.vstemplate

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<LanguageTag>csharp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
1717
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1819
</TemplateData>
1920
<TemplateContent>
2021
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" CustomTool="MSBuild:Compile" TargetFileName="$fileinputname$.xaml">BlankWindow.xaml</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Desktop/CppWinRT/BlankWindow/BlankWindow.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
#include "pch.h"
52
#include "$safeitemname$.xaml.h"
63
#if __has_include("$safeitemname$.g.cpp")
@@ -15,11 +12,6 @@ using namespace Microsoft::UI::Xaml;
1512

1613
namespace winrt::$rootnamespace$::implementation
1714
{
18-
$safeitemname$::$safeitemname$()
19-
{
20-
InitializeComponent();
21-
}
22-
2315
int32_t $safeitemname$::MyProperty()
2416
{
2517
throw hresult_not_implemented();

Diff for: dev/VSIX/ItemTemplates/Desktop/CppWinRT/BlankWindow/BlankWindow.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
#pragma once
52

63
#include "$safeitemname$.g.h"
@@ -9,12 +6,16 @@ namespace winrt::$rootnamespace$::implementation
96
{
107
struct $safeitemname$ : $safeitemname$T<$safeitemname$>
118
{
12-
$safeitemname$();
9+
$safeitemname$()
10+
{
11+
// Xaml objects should not call InitializeComponent during construction.
12+
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
13+
}
1314

1415
int32_t MyProperty();
1516
void MyProperty(int32_t value);
1617

17-
void myButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
18+
void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
1819
};
1920
}
2021

Diff for: dev/VSIX/ItemTemplates/Desktop/CppWinRT/BlankWindow/BlankWindow.idl

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
namespace $rootnamespace$
52
{
63
[default_interface]

Diff for: dev/VSIX/ItemTemplates/Desktop/CppWinRT/BlankWindow/WinUI.Desktop.CppWinRT.BlankWindow.vstemplate

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<LanguageTag>cpp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
1717
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1819
</TemplateData>
1920
<TemplateContent>
2021
<ProjectItem SubType="Designer" TargetFileName="$fileinputname$.xaml" ReplaceParameters="true">BlankWindow.xaml</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CSharp/BlankPage/WinUI.Neutral.Cs.BlankPage.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>csharp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" CustomTool="MSBuild:Compile" TargetFileName="$fileinputname$.xaml">BlankPage.xaml</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CSharp/ResourceDictionary/WinUI.Neutral.Cs.ResourceDictionary.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>csharp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" CustomTool="MSBuild:Compile" TargetFileName="$fileinputname$.xaml">ResourceDictionary.xaml</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CSharp/Resw/WinUI.Neutral.Cs.Resw.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>csharp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem ItemType="PRIResource">Resources.resw</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CSharp/TemplatedControl/WinUI.Neutral.Cs.TemplatedControl.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>csharp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem ReplaceParameters="true" TargetFileName="$fileinputname$.cs">CustomControl.cs</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CSharp/UserControl/WinUI.Neutral.Cs.UserControl.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>csharp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" CustomTool="MSBuild:Compile" TargetFileName="$fileinputname$.xaml">UserControl.xaml</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/BlankPage/BlankPage.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
#include "pch.h"
52
#include "$safeitemname$.xaml.h"
63
#if __has_include("$safeitemname$.g.cpp")
@@ -15,11 +12,6 @@ using namespace Microsoft::UI::Xaml;
1512

1613
namespace winrt::$rootnamespace$::implementation
1714
{
18-
$safeitemname$::$safeitemname$()
19-
{
20-
InitializeComponent();
21-
}
22-
2315
int32_t $safeitemname$::MyProperty()
2416
{
2517
throw hresult_not_implemented();

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/BlankPage/BlankPage.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
#pragma once
52

63
#include "$safeitemname$.g.h"
@@ -9,12 +6,16 @@ namespace winrt::$rootnamespace$::implementation
96
{
107
struct $safeitemname$ : $safeitemname$T<$safeitemname$>
118
{
12-
$safeitemname$();
9+
$safeitemname$()
10+
{
11+
// Xaml objects should not call InitializeComponent during construction.
12+
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
13+
}
1314

1415
int32_t MyProperty();
1516
void MyProperty(int32_t value);
1617

17-
void myButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
18+
void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
1819
};
1920
}
2021

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/BlankPage/BlankPage.idl

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
namespace $rootnamespace$
52
{
63
[default_interface]

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/BlankPage/WinUI.Neutral.CppWinRT.BlankPage.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>cpp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem SubType="Designer" TargetFileName="$fileinputname$.xaml" ReplaceParameters="true">BlankPage.xaml</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/ResourceDictionary/WinUI.Neutral.CppWinRT.ResourceDictionary.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>cpp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem OpenInEditor="true" ReplaceParameters="true" ItemType="Page" TargetFileName="$fileinputname$.xaml">ResourceDictionary.xaml</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/Resw/WinUI.Neutral.CppWinRT.Resw.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>cpp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem ItemType="PRIResource">Resources.resw</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/TemplatedControl/TemplatedControl.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
#include "pch.h"
52
#include "$safeitemname$.h"
63
#if __has_include("$safeitemname$.g.cpp")

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/TemplatedControl/TemplatedControl.h

-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
#pragma once
52

6-
#include "winrt/Microsoft.UI.Xaml.h"
7-
#include "winrt/Microsoft.UI.Xaml.Markup.h"
8-
#include "winrt/Microsoft.UI.Xaml.Controls.Primitives.h"
93
#include "$safeitemname$.g.h"
104

115
namespace winrt::$rootnamespace$::implementation

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/TemplatedControl/TemplatedControl.idl

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
namespace $rootnamespace$
52
{
63
[default_interface]

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/TemplatedControl/WinUI.Neutral.CppWinRT.TemplatedControl.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>cpp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem SubType="Code" TargetFileName="$fileinputname$.cpp" ReplaceParameters="true">TemplatedControl.cpp</ProjectItem>

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/UserControl/UserControl.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
#include "pch.h"
52
#include "$safeitemname$.xaml.h"
63
#if __has_include("$safeitemname$.g.cpp")
@@ -15,11 +12,6 @@ using namespace Microsoft::UI::Xaml;
1512

1613
namespace winrt::$rootnamespace$::implementation
1714
{
18-
$safeitemname$::$safeitemname$()
19-
{
20-
InitializeComponent();
21-
}
22-
2315
int32_t $safeitemname$::MyProperty()
2416
{
2517
throw hresult_not_implemented();

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/UserControl/UserControl.h

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
#pragma once
52

6-
#include "winrt/Microsoft.UI.Xaml.h"
7-
#include "winrt/Microsoft.UI.Xaml.Markup.h"
8-
#include "winrt/Microsoft.UI.Xaml.Controls.Primitives.h"
93
#include "$safeitemname$.g.h"
104

115
namespace winrt::$rootnamespace$::implementation
126
{
137
struct $safeitemname$ : $safeitemname$T<$safeitemname$>
148
{
15-
$safeitemname$();
9+
$safeitemname$()
10+
{
11+
// Xaml objects should not call InitializeComponent during construction.
12+
// See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent
13+
}
1614

1715
int32_t MyProperty();
1816
void MyProperty(int32_t value);
1917

20-
void myButton_Click(Windows::Foundation::IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
18+
void myButton_Click(IInspectable const& sender, Microsoft::UI::Xaml::RoutedEventArgs const& args);
2119
};
2220
}
2321

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/UserControl/UserControl.idl

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) Microsoft Corporation and Contributors.
2-
// Licensed under the MIT License.
3-
41
namespace $rootnamespace$
52
{
63
[default_interface]

Diff for: dev/VSIX/ItemTemplates/Neutral/CppWinRT/UserControl/WinUI.Neutral.CppWinRT.UserControl.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<TargetPlatformName>Windows</TargetPlatformName>
1515
<LanguageTag>cpp</LanguageTag>
1616
<PlatformTag>windows</PlatformTag>
17-
<ProjectTypeTag>uwp</ProjectTypeTag>
1817
<ProjectTypeTag>desktop</ProjectTypeTag>
18+
<ProjectTypeTag>winui</ProjectTypeTag>
1919
</TemplateData>
2020
<TemplateContent>
2121
<ProjectItem SubType="Designer" TargetFileName="$fileinputname$.xaml" ReplaceParameters="true">UserControl.xaml</ProjectItem>

Diff for: dev/VSIX/ProjectTemplates/Desktop/CSharp/ClassLibrary/WinUI.Desktop.Cs.ClassLibrary.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<LanguageTag>XAML</LanguageTag>
2222
<PlatformTag>windows</PlatformTag>
2323
<ProjectTypeTag>desktop</ProjectTypeTag>
24-
<ProjectTypeTag>WinUI</ProjectTypeTag>
24+
<ProjectTypeTag>winui</ProjectTypeTag>
2525
</TemplateData>
2626
<TemplateContent PreferedSolutionConfiguration="Debug|AnyCPU">
2727
<CustomParameters>

Diff for: dev/VSIX/ProjectTemplates/Desktop/CSharp/PackagedApp/BlankApp/WinUI.Desktop.Cs.BlankApp.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<LanguageTag>XAML</LanguageTag>
2323
<PlatformTag>windows</PlatformTag>
2424
<ProjectTypeTag>desktop</ProjectTypeTag>
25-
<ProjectTypeTag>WinUI</ProjectTypeTag>
25+
<ProjectTypeTag>winui</ProjectTypeTag>
2626
</TemplateData>
2727
<TemplateContent PreferedSolutionConfiguration="Debug|x86">
2828
<Project File="ProjectTemplate.csproj" ReplaceParameters="true">

Diff for: dev/VSIX/ProjectTemplates/Desktop/CSharp/PackagedApp/WapProj/WinUI.Desktop.Cs.WapProj.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<LanguageTag>XAML</LanguageTag>
2222
<PlatformTag>windows</PlatformTag>
2323
<ProjectTypeTag>desktop</ProjectTypeTag>
24-
<ProjectTypeTag>WinUI</ProjectTypeTag>
24+
<ProjectTypeTag>winui</ProjectTypeTag>
2525
</TemplateData>
2626
<TemplateContent>
2727
<CustomParameters>

Diff for: dev/VSIX/ProjectTemplates/Desktop/CSharp/PackagedApp/WinUI.Desktop.Cs.PackagedApp.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<LanguageTag>XAML</LanguageTag>
2222
<PlatformTag>windows</PlatformTag>
2323
<ProjectTypeTag>desktop</ProjectTypeTag>
24-
<ProjectTypeTag>WinUI</ProjectTypeTag>
24+
<ProjectTypeTag>winui</ProjectTypeTag>
2525
</TemplateData>
2626
<TemplateContent PreferedSolutionConfiguration="Debug|x86">
2727
<CustomParameters>

Diff for: dev/VSIX/ProjectTemplates/Desktop/CSharp/SingleProjectPackagedApp/WinUI.Desktop.Cs.SingleProjectPackagedApp.vstemplate

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<LanguageTag>XAML</LanguageTag>
2222
<PlatformTag>windows</PlatformTag>
2323
<ProjectTypeTag>desktop</ProjectTypeTag>
24-
<ProjectTypeTag>WinUI</ProjectTypeTag>
24+
<ProjectTypeTag>winui</ProjectTypeTag>
2525
</TemplateData>
2626
<TemplateContent PreferedSolutionConfiguration="Debug|x86">
2727
<CustomParameters>

0 commit comments

Comments
 (0)