Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/1.4-stable] Various fixes for C++ project and item templates (#3745) #3754

Conversation

evelynwu-msft
Copy link
Contributor

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 Win32 Desktop functions not available in WinUI 3 Runtime Component. #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)

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)
@evelynwu-msft evelynwu-msft changed the title Various fixes for C++ project and item templates (#3745) [release/1.4-stable] Various fixes for C++ project and item templates (#3745) Jul 21, 2023
@evelynwu-msft
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines could not run because the pipeline triggers exclude this branch/path.

@evelynwu-msft evelynwu-msft enabled auto-merge (squash) July 21, 2023 16:30
Copy link
Contributor

@codendone codendone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

#pragma once
#include <windows.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

windows

#define WIN32_LEAN_AND_MEAN?

#include <winrt/Microsoft.UI.Xaml.Navigation.h>
#include <winrt/Microsoft.UI.Xaml.Shapes.h>
#include <winrt/Microsoft.UI.Dispatching.h>
#include <wil/cppwinrt_helpers.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cppwinrt_helpers

Does this include <wil/cppwinrt.h> to enable WIL/cppwinrt interop?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. That header file's sole purpose is to support async calls (WIL is where resume_foreground ended up landing). More generally, I recall there was resistance in the past to the project templates automatically opting in developers to using WIL which is why we limit our usage to that one header file. If the functionality hadn't ended up in WIL then we wouldn't even have a Nuget package reference to it in the first place.

#include <winrt/Microsoft.UI.Xaml.Navigation.h>
#include <winrt/Microsoft.UI.Xaml.Shapes.h>
#include <winrt/Microsoft.UI.Dispatching.h>
#include <wil/cppwinrt_helpers.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include

Consider including <wil/result_originate.h> so that error logging automatically calls RoOriginateError.

@evelynwu-msft evelynwu-msft merged commit 220ea99 into release/1.4-stable Jul 21, 2023
@evelynwu-msft evelynwu-msft deleted the user/evelynwu/cherrypick-cppwinrt-template-updates-onto-release-1.4-stable branch July 21, 2023 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants