Search code examples
c#windows-10-universalwindows-storesystem.diagnosticsdesktop-bridge

Is calling System.Diagnostics.Process.Start() truly problematic?


In the Validation Result that I get when readying my app for submission to the Microsoft Store (which my app "PASSED WITH WARNINGS"), I got this "Fail" under the "Package Sanity Test" section:

enter image description here

The code which contains such a call is:

private void myMapsHelpToolStripMenuItem_Click(object sender, EventArgs e)
{
    System.Diagnostics.Process.Start("https://ramblingnotesofageezer.substack.com/p/map-o-matic-overview");
}

I am using that code due to the recommendation to do so here. How do I start a process from C#?

Is this truly a problem? If so, what should I use instead of the call to System.Diagnostics.Process.Start()?

I find it odd that it is classified as a failed part of the test, yet the overall results are that my app passed (albeit with warnings).

UPDATE

I checked out the link in the comment from Codexer, where it says, "Starting a utility can often provide a convenient way to obtain information from the operating system, access the registry, or access system capabilities. However, you can use UWP APIs to accomplish these sorts of tasks instead."

If this is the solution, do the UWP APIs have an equivalent to System.Diagnostics.Process.Start()?

UPDATE 2

I followed the steps in the answer, but the solution still doesn't compile, due to an error with this line of code:

await Windows.System.Launcher.LaunchUriAsync(uri);

enter image description here

In fact, even when I comment out the offending line, the project will no longer compile, but doesn't give me any information about how to solve the problem, just this:

enter image description here

I set the Package Management Format to PackageReference, and installed version 10.0.18362.2005 of Microsoft.Windows.SDK.Contracts, but it is complaining about needing a package reference...?!? I tried adding using Windows.System; and using Microsoft.Windows.SDK.Contracts; but neither is recognized.

The package is installed for the project, as you can see here:

enter image description here

UPDATE 3

Regarding the "Must Use Package Reference" err msg, I have three questions revolving around what I see here:

enter image description here

The verbiage below Microsoft.Windows.SDK.Contracts says I can update versions of this package - should I?

I do not see a Reference to Microsoft.Windows.SDK.Contracts in my project's References, although it has been installed. Do I need to add one - if so, from where?

The context menu on my References affords me the ability to "Migrate packages.config to PackageReference..." should I do that?


Solution

  • If you were developing an uwp application, for opening open a web uri, it is recommended to use Launcher.LaunchUriAsync(Uri) method instead, this method starts the default browser to open the specified URI.

    For example:

    private async void button_Click(object sender, RoutedEventArgs e)
            {           
                Uri uri = new Uri("http://www.google.com");
                await Windows.System.Launcher.LaunchUriAsync(uri);
            }
    

    Update:

    As Codexer mentioned, you could refer to this document to use uwp api in winform app.

    I have created a winform project, its target framework is .Net Framework4.8. For earlier versions of .NET(.NET Core 3.x, .NET 5 Preview 7 (or earlier), or .NET Framework), you could refer to my steps.

    1.Click Tools->NuGet Package Manager-> Package Manager Settings-> Change Default package management format to PackageReference. As follows:

    enter image description here

    2.Install the Microsoft.Windows.SDK.Contracts package, note that you need to install the appropriate version. Please check the corresponding version below. (Installation details: Right click Reference-> Manage NuGet Packages->Browse->Search Microsoft.Windows.SDK.Contracts->install)

    • 10.0.19041.xxxx: Choose this for Windows 10, version 2004, version 20H2

    • 10.0.18362.xxxx: Choose this for Windows 10, version 1903.

    • 10.0.17763.xxxx: Choose this for Windows 10, version 1809.

    • 10.0.17134.xxxx: Choose this for Windows 10, version 1803.

    enter image description here

    3.Run the project