I am building a UWP application. When I open the app settings for my App, I want to display the Version number of my application in the Specifications section.
For example- In the following image, you can see the version number as 1.2.4.0 under the Specifications section in the App settings. How can I do a similar thing for my UWP application.
Image
How can I achieve this?
See: Retrieve the Current App version from Package
That's how you can display it anyway.
public string GetAppVersion()
{
Package package = Package.Current;
PackageId packageId = package.Id;
PackageVersion version = packageId.Version;
return "Version " + string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
}
The UWP Community Toolkit has a SystemInformation class which has many relevant properties and methods.
You could use it to get the information that you want.
For example,
// To get application's name:
public string ApplicationName => SystemInformation.ApplicationName;
// To get application's version:
public string ApplicationVersion => $"{SystemInformation.ApplicationVersion.Major}.{SystemInformation.ApplicationVersion.Minor}.{SystemInformation.ApplicationVersion.Build}.{SystemInformation.ApplicationVersion.Revision}";
You get this for free, nothing special needs to be done. The App settings page will display the version number retrieved from your appxmanifest file.
Related
I was using the following code to show a Windows 10 Toast notifications from a .NetCore 3.1 console application, where I was using objects from the following namespaces: Windows.UI.Notifications & Windows.Data.Xml.Dom, in .Net5.0 these namespaces seem to be moved to somewhere else.
public void GenerateToast(string appid, string imageFullPath, string h1, string h2, string p1)
{
try
{
var template = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
var textNodes = template.GetElementsByTagName("text");
textNodes[0].AppendChild(template.CreateTextNode(h1));
textNodes[1].AppendChild(template.CreateTextNode(h2));
textNodes[2].AppendChild(template.CreateTextNode(p1));
if (File.Exists(imageFullPath))
{
XmlNodeList toastImageElements = template.GetElementsByTagName("image");
((XmlElement)toastImageElements[0]).SetAttribute("src", imageFullPath);
}
IXmlNode toastNode = template.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("duration", "long");
var notifier = ToastNotificationManager.CreateToastNotifier(appid);
var notification = new ToastNotification(template);
notifier.Show(notification);
}
catch (Exception)
{
// Ignore
}
}
How to get back these namespaces?
Solution found Here:
This option is only supported in projects that use .NET 5 (or a later release) and target Windows 10, version 1809 or a later OS release. For more background info about this scenario, see this blog post.
With your project open in Visual Studio, right-click your project in
Solution Explorer and choose Edit Project File. Your project file
should look similar to this.
WinExe
net5.0
true
Replace the value of the TargetFramework element with one of the
following strings:
net5.0-windows10.0.17763.0: Use this value if your app targets
Windows 10, version 1809. net5.0-windows10.0.18362.0: Use this value
if your app targets Windows 10, version 1903.
net5.0-windows10.0.19041.0: Use this value if your app targets
Windows 10, version 2004.
For example, the following element is for a project that targets
Windows 10, version 2004.
net5.0-windows10.0.19041.0
Save your changes and close the project file.
I am parsing AppxManifest.xml and getting the display name. That contains something like
ms-resource:ApplicationTitleWithBranding, ms-resource:AppTitleWithBranding,
ms-resource:AppStoreName.
When I use SHLoadIndirectString function with this display name (in the format of #{PRIFilepath?resource} ), I don't get the localized display name. It returns nothing.
But I get proper response for some apps which contain display name something like ms-resource:///Resources/AppStoreName.
Is there any workaround to get the localized display names ?
I need this to work on both windows8.1 and windows10. It is a desktop app.
I just passed 'ms-resource:AppTitleWithBranding' to the function along with the pri file location. That's why I did not get the localized names.
We should not send resource in this format : ms-resource:AppTitleWithBranding. Modify this thing in the below format.
Resource should be in the format:
ms-resource://Package.Id.Name/resources/AppTitleWithBranding
If AppxManifest.xml already contains in the above format, then just pass as it is.
And the final format should be #{PRIFilepath?resource}
I know a little bit more ms-resource: URI transformations for #{PRIFilepath?resource}:
ms-resource:///xxx => ms-resource://<PRI-file package name>/xxx
ms-resource://xxx
ms-resource:/xxx => ms-resource://<PRI-file package name>/xxx
ms-resource:xxx => ms-resource://<PRI-file package name>/Resources/xxx
ms-resource:xxx/yyy => ms-resource://<PRI-file package name>/xxx/yyy
ms-resource:xxx/yyy => ms-resource://<PRI-file package name>/Resources/xxx/yyy
Note: Be careful, the package name from WinRT database and AppxManifest.xml can be different then the package name from resources.pri.
I'm developing a program in C# (Visual Studio 2015) and I want to show a toast message to the user at a certain situation. I downloaded this code from the MSDN and it runs fine:
// Get a toast XML template
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
// Fill in the text elements
XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
for (int i = 0; i < stringElements.Length; i++)
{
stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
}
// Specify the absolute path to an image
String imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;
// Create the toast and attach event listeners
ToastNotification toast = new ToastNotification(toastXml);
toast.Activated += ToastActivated;
toast.Dismissed += ToastDismissed;
toast.Failed += ToastFailed;
// Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
After testing this code I wanted to implement it into my application. So I changed it up a little bit and tried to run it. The error messages:
The type "IReadOnlyList<>" is defined in a not referenced assembly. Add a reference to System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
(translated)
Same goes for IEnumerable<> and IReadOnlyList<>
The error come from these two lines:
for (int i = 0; i < stringElements.Length; i++)
{
stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
I also tried adding the reference to System.Runtime. I downloaded it with NuGet (https://www.nuget.org/packages/System.Runtime/4.0.0/).
After that the errors were gone, but now literaly every word in my code is cringled red with error like "System.Object is not defined" and so on (but it still runs when I start it!).
The only possible solution I can think of is that System.Runtime is already installed somewhere on my computer, and that 4.0.0 is the wrong version for my program. But I can't find it anywhere.
PS: It's a desktop-application, not a Windows-Store application.
I think it is the same problem as in this question
You must add a reference to
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Runtime.dll
PS : If you have a Windows 10 only desktop app, you might want to use the new toast system, the code sample on MSDN uses the Windows 8 one. it works on W10 but does not have all the new features (Microsoft released an official NuGet package).
Edit : Since I can't comment, I will post the answer here :
The exception is because you need to provide an applicationId in CreateToastNotifier()
ToastNotificationManager.CreateToastNotifier("MyApplicationId").Show(toast);
It is the name that will be used in the action center to group your toasts (so in general, you put the name of your app). In Windows 8.1 it was needed to register your application Id (I think this was in the sample from the MSDN) but now you can just put the name of your app.
And the GetXml() is only for WinRT. In desktop you need to do like you did with the GetContent().
We are about to submit a game for Windows 8 with two versions:
An ad-supported free version with 3 levels
The full game
So on the ad-supported version, we need a button to link to the store for the full version.
In both versions, we also would like to place a button to link to the store to review each app.
How are these two scenarios handled in Windows 8?
Thanks to the lovely folks who created Physamajig not only working this out, but also sharing the information on their blog! Here's how you can link directly to your Review page:
Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:REVIEW?PFN=MY_PACKAGE_FAMILY_NAME"));
Replacing MY_PACKAGE_FAMILY_NAME with the one from your package manifest.
See full details: http://andybeaulieu.com/Home/tabid/67/EntryID/227/Default.aspx
var storeURI = new Uri("ms-windows-store:PDP?PFN=<Your package family name from the manifest>");
await Windows.System.Launcher.LaunchUriAsync(storeURI);
should do the trick.
We asked about linking directly to the review page at an AEL today. The link to Rate and Review in the settings charm is added automatically once your app is in the store. No coding required.
You can directly use below code in click event:
MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
marketplaceReviewTask.Show();
You will need to add
using Microsoft.Phone.Tasks;
also.
Use this:-
private async void Rate_Click(object sender, RoutedEventArgs e)
{
String pfn = Package.Current.Id.FamilyName;
await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:REVIEW?PFN=" + pfn + ""));
}
You can find detailed solution here.
I want to get the path and version number of a ClickOnce application, provided the name of the ClickOnce application.
When I manually searched for it, I found it at the path as follows:
'C:\Users\krishnaim\AppData\Local\Apps\2.0\1HCG3KL0.K41\VO5BM4JR.RPO\head..tion_7446cb71d1187222_0005.0037_37dfcf0728461a82\HeadCount.exe'
But this keeps on changing, and it will become a hard-coded path. Is there another way to get a ClickOnce application (for example, HeadCount.exe which is already installed) path and version number using C#/.NET code?
It seems a little bizarre, but getting the current directory of the executing assembly is a bit tricky so my code below may be doing more than you think it should, but I assure you it is mitigating some issues where others may attempt to use Assembly.GetExecutingAssembly.Location property.
static public string AssemblyDirectory
{
get
{
//Don't use Assembly.GetExecutingAssembly().Location, instead use the CodeBase property
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return System.IO.Path.GetDirectoryName(path);
}
}
static public string AssemblyVersion
{
get
{
var asm = Assembly.GetExecutingAssembly();
//If you want the full four-part version number:
return asm.GetName().Version.ToString(4);
//You can reference asm.GetName().Version to get Major, Minor, MajorRevision, MinorRevision
//components individually and do with them as you please.
}
}
In order to do a ClickOnce application update you do not have to do so manually as long as you are using the standard deployment manifests (which I don't know how to ClickOnce unless you do use them).
The MSDN article Choosing a ClickOnce Update Strategy describes the different options for application updates.