@Rohan Pande, as this issue is complex, you can open an incident at https://developer.microsoft.com/en-us/windows/support/?tabs=Contact-us so that our engineer can work with you closely and please choose the 'Other' for Windows App SDK for this issue. In-addition, if the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged.
Some doubts regarding after registering for WinUI3 packaged with external location app?
Hi,
I was earlier creating a WinUI3 blank unpackaged app. Followed the steps here to make my solution from packaged to unpackaged application.
In this project I have disabled the XAML code and created my own entry point (WinMain).
Steps that I have done for disabling the XAML code:
Project Properties > (select All Configurations and All Platforms) > Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions, Edit the value, and add the symbol DISABLE_XAML_GENERATED_MAIN.
This is loading the msix file at run time and the WinMain code:
bool
Register()
{
Uri externaluri = nullptr;
Uri packageuri = nullptr;
PackageManager pkgmgr = nullptr;
AddPackageOptions options = nullptr;
bool registration = false;
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation;
try {
externaluri = Uri(L"C:\\Users\\rohan.pande\\source\\repos\\DeleteExternalLocation2\\x64\\Debug\\DeleteExternalLocation2");
packageuri = Uri(L"C:\\Users\\rohan.pande\\source\\repos\\DeleteExternalLocation2\\MyPackage.msix");
pkgmgr = PackageManager();
options = AddPackageOptions();
options.ExternalLocationUri(externaluri);
deploymentOperation = pkgmgr.AddPackageByUriAsync(packageuri, options);
HANDLE opCompletedEvent = CreateEvent(nullptr, true, false, nullptr); // this event will be signaled when the deployment operation has completed.
deploymentOperation.Completed([&](auto const& depProgress, auto const& status) {
SetEvent(opCompletedEvent);
});
std::wcout << L"Installing package " << packageuri << std::endl;
std::wcout << L"Waiting for package registration to complete..." << std::endl;
WaitForSingleObject(opCompletedEvent, INFINITE);
if (deploymentOperation.Status() == AsyncStatus::Error) {
hresult deploymentResult = deploymentOperation.ErrorCode();
int a = 0;
// OutputDebugStringW (L"Installation Error: %d\n", deploymentOperation.ErrorCode ());
// OutputDebugStringW (L"Detailed Error Text: %s\n", deploymentResult->ErrorText.Data());
}
else if (deploymentOperation.Status() == AsyncStatus::Canceled) {
OutputDebugStringW(L"Package Registration Canceled\n");
}
else if (deploymentOperation.Status() == AsyncStatus::Completed) {
registration = true;
OutputDebugStringW(L"Package Registration succeeded!\n");
}
else {
OutputDebugStringW(L"Installation status unknown\n");
}
}
catch (const std::exception& ex) {
std::wcout << L"AddPackageSample failed, error message: " << ex.what() << std::endl;
std::wcout << L"Full Stacktrace: " << ex.what() << std::endl;
}
return registration;
}
int CALLBACK
WinMain([[maybe_unused]] HINSTANCE pInstance, [[maybe_unused]] HINSTANCE pPrevInstance, [[maybe_unused]] LPSTR pCmdLine, [[maybe_unused]] int pShowCmd)
{
Register ();
winrt::init_apartment(winrt::apartment_type::single_threaded);
Application::Start([](auto&&) {
::winrt::make<::winrt::DeleteExternalLocation2::implementation::App>();
});
}
Now I am currently moving my existing solution trying to move to package with external location as this provides 'package identity' which provides additional features to my app.
Reference: https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/grant-identity-to-nonpackaged-apps
It registers the package identity for the first time and application runs (only for first time) but from next time the applications doesn't run. Any idea why this happens like that? I didn't understand why this is happening? Can somebody help here?
Granting the package identity documentation shared above is for unpackaged apps, right? So, it should run that's my understanding.
Note: I don't have any extra code you could also try by creating a new project make it as unpackaged and just follow the steps for disabling the XAML code and follow the steps of granting the package identity.
This is the error that comes on the output screen:
2 answers
Sort by: Most helpful
-
Xiaopo Yang - MSFT 12,726 Reputation points Microsoft Vendor
2024-04-22T08:11:31.49+00:00 -
Darran Rowe 1,041 Reputation points
2024-07-12T01:20:48.5+00:00 As a random and late answer attempt.
You only need to register the package once. It is more or less the same as an APPX/MSIX package that only needs to be installed once. The only difference is that it is lacking content. Once the package is installed, it is the msix element of the application manifest that associates the application with the package.
You are unconditionally calling Register in your code, but you shouldn't. If your application has an installer, you should register the package as part of the install action, and remove the package as part of the uninstall action. If the application is standalone, either provide a register/unregister set of command line options. The register option registers the package and the unregister option unregisters it. If you want to do an automatic regisration, then you should register and then automatically restart the application so that it is associated with the package. In either case, you should check to see if your application has a package identity. You should also provide some means of easily uninstalling the package when the user no longer wants to use your application.