UWP console app with no icon, just execution alias - windows

I have an Win32 application ported to UWP using desktop bridge.
The application has both GUI and command-line interface (separate executables).
I'd like to have an icon and execution alias for the GUI interface, but only execution alias for the command-line interface. I do not want to pollute the Start menu with an icon no one will ever use.
For that I've understood that the manifest needs to include two Application elements, one for the GUI and one for the command-line interface, as one Application can include only one AppExecutionAlias.
See also Create a Universal Windows Platform console app.
My idea was something like this:
<Applications>
<!-- GUI -->
<Application Id="MyApp" Executable="MyApp.exe" EntryPoint="Windows.FullTrustApplication">
<!-- with icon -->
<uap:VisualElements DisplayName="MyApp" Description="MyApp" ...>
...
</uap:VisualElements>
<!-- and execution alias -->
<Extensions>
<uap5:Extension Category="windows.appExecutionAlias"
Executable="MyApp.exe" EntryPoint="Windows.FullTrustApplication">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="MyApp.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
</Extensions>
</Application>
<!-- Command-line interface -->
<Application Id="MyApp-commandline" Executable="MyApp-commandline.exe"
EntryPoint="Windows.FullTrustApplication">
<!-- with execution alias only -->
<Extensions>
<uap5:Extension Category="windows.appExecutionAlias"
Executable="MyApp-commandline.exe" EntryPoint="Windows.FullTrustApplication">
<uap5:AppExecutionAlias>
<uap5:ExecutionAlias Alias="MyApp-commandline.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
</Extensions>
</Application>
</Applications>
But I cannot find out how (if even possible) to have Application with no icon, as it seems that the VisualElements part is mandatory. So the above manifest is invalid. Of it there's some trick to an additional another execution alias (for a different binary) to the (first and only) Application.

Yes, the VisualElements part is mandatory as the file warned, we should follow the rules that the .Manifest file required. But if you don't want to have some Icons, you can try to provide a URI that doesn't refer a real image resource. Such as,
<uap:VisualElements
DisplayName="ConsoleUWP"
Square150x150Logo="Square150x150Logo.png"
Square44x44Logo="Image.png"
Description="ConsoleUWP"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Image.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
the Square44x44Logo, Square150x150Logo and Wide310x150Logo don't refer to correct URIs for images, but the uap:SplashScreen can not be configure a wrong URI, if you did that, it would get error.
---Update---
We can use the Applications element to specify one or more apps for the package, but every Application need the VisualElements part in the UWP .manefest file. So if you add another , you will need to add the Visual Elements as it required, your idea can not implement. Also note that although each package can contain one or more apps, packages that contain multiple apps won't pass the Store certification process, that is to say you can not publish to store.
On the other hand, you can try to create a package that includes both a Win32 and Universal Windows Platform (UWP) processes, and communicate between them via an AppService APIs. It use the FullTrustProcessLauncher extension but not another . You can try and see the sample:
https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/AppServiceBridgeSample

Related

Is possible to load the images from local folder in Xamarin forms?

Can you give me clarity about how to load the image from the local folder (I mean from D: drive rather than the local cache folder)?
I tried to refer an image from my D: drive, but it's not shown.
image.Source = ImageSource.FromFile("D:/ImageFilters/FilterUWP/Filter_UWP_SkiaSharp/Buldingimage.jpeg");
May I know it is not worked?
Is there amy way to load the image from the D: drive?
image.Source = ImageSource.FromFile("C:/Users/SanthiyaArulsamy/AppData/LocalState/image.jpg");
Worked from my UWP App.
Please explain to me about the FromFile and also the local folder concept?
Assuming that you are only targeting UWP, not iOS/Android (D:\ would make no sense in this case), please read the documentation for UWP apps
Universal Windows Platform (UWP) apps can access certain file system locations by default. Apps can also access additional locations through the file picker, or by declaring capabilities. (source)
According to this section, there is a capability, broadFileSystemAccess, you can declare in your packages XAML file
<Package ...
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp uap5 rescap">
<Capabilities>
<rescap:Capability Name="broadFileSystemAccess" />
</Capabilities>
</Package>
If the user has granted, you may access
All files that the user has access to. For example: documents, pictures, photos, downloads, desktop, OneDrive, etc.
Anyway, the documentation mentions two caveats
Because users can grant or deny the permission any time in Settings, you should ensure that your app is resilient to those changes.
and
If you submit an app to the Store that declares this capability, you will need to supply additional descriptions of why your app needs this capability, and how it intends to use it.

When I run a debug on my program in Visual Studio, the user interface gets cut off. How do I fix this? [duplicate]

I've created a simple Winforms application in C#. When I run the application on a machine with high DPI settings (e.g. 150%), the application gets scaled up. So far so good!
But instead of rendering the fonts with a higher font size, all texts are just scaled up, too. That of course leads to very blurry text (on all controls like buttons etc.).
Shouldn't windows take care of rendering the texts correctly? For example my application's title bar is rendered crisp & clear.
Once you go past 100% (or 125% with the "XP-style DPI scaling" checkbox ticked), Windows by default takes over the scaling of your UI. It does so by having your app render its output to a bitmap and drawing that bitmap to the screen. The rescaling of that bitmap makes the text inevitably look fuzzy. A feature called "DPI virtualization", it keeps old programs usable on high resolution monitors.
You have to explicitly let it know that you can handle higher DPI settings by adding the <dpiAware> element to your manifest. The MSDN page is here but it isn't complete since it is omitting the UAC settings. Project + Add New Item, pick "Application Manifest File". Edit the manifest text or copy/paste this:
<?xml version="1.0" encoding="utf-8"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" >
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<dpiAware>true</dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>
You can also pinvoke SetProcessDPIAware() in your Main() method, necessary for example if you deploy with ClickOnce:
[STAThread]
static void Main() {
if (Environment.OSVersion.Version.Major >= 6) SetProcessDPIAware();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); // Edit as needed
}
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
UPDATE, this common need is finally a bit easier if you use VS2015 Update 1 or higher. The added manifest already has the relevant directive, just remove the comments.
Keyword for search so I can find this post back: dpiAware
Applications can be developed in two different mode.
The first one is to declare our application to be non-DPI-aware (not declaring anything will default to this). In this case the operating system will render our application under the expected 96 DPI and then will do to the bitmap scaling that we discussed before. The result will be a blurry looking application, but with a correct layout.
The second option is to declare the application as DPI-aware. In this case the OS will not do any scaling and will let your application render according to the original DPI of the screen. In case of a per-monitor-DPI environment, your application will be rendered with the highest DPI of all the screens, then this bitmap will be scaled down to the proper size for each monitor. Downscaling results in a better viewing experience than upscaling but you might still notice some fuzziness.
If you want to avoid that, you must declare your application as per-monitor-DPI-aware. Then you must detect when your application is dragged across different monitors and render according to the DPI of the current one.
Declaring the DPI awareness is done in a manifest file.
refer the following link stackoverflow
Using .NET Framework 4.7 and Windows 10 Creators Update (1703) or newer you must do the following things to configure high DPI support for your Windows Form application:
Declare compatibility with Windows 10.
To do this, add the following to your manifest file:
<compatibility xmlns="urn:schemas-microsoft.com:compatibility.v1">
<application>
<!-- Windows 10 compatibility -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
Enable per-monitor DPI awareness in the app.config file.
Windows Forms introduces a new System.Windows.Forms.ApplicationConfigurationSection element to support new features and customizations added starting with the .NET Framework 4.7. To take advantage of the new features that support high DPI, add the following to your application configuration file.
<System.Windows.Forms.ApplicationConfigurationSection>
<add key="DpiAwareness" value="PerMonitorV2" />
</System.Windows.Forms.ApplicationConfigurationSection>
Important
In previous versions of the .NET Framework, you used the manifest to add high DPI support. This approach is no longer recommended, since it overrides settings defined on the app.config file.
Call the static EnableVisualStyles method.
This should be the first method call in your application entry point. For example:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
The advantage of this is the support for dynamic DPI scenarios in which the user changes the DPI or scale factor after a Windows Forms application has been launched.
Source: High DPI support in Windows Forms
None of these suggestions worked for me but, something happened after I removed the Form.Font = new ... from the Form.Design.cs, the form started to re-scale properly, it works if the Font is defined in the constructor or not at all. Why? somebody else may be able to explained, I just can talk about the changed I made and took me a few minutes to figured out it was the root cause for the form I was working on. Hope it helps.
Since at least Visual Studio 2017 you just have to add a manifest file and uncomment this section:
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
</windowsSettings>
</application>
This is not an answer. This is my work around. None of the above answers or comments worked for me. I also searched for and tried other methods.
I have been using Visual Studio.NET with C# and Windows.Forms since it was originally released. Until VS 2022 and Windows 11 this year, setting the scale mode seemed to work fine. For some reason, some of my Form.Height values get reduced at run time. No problems so far with Form.Width being changed. For me, this problem started April 1, 2022 - so I first thought it was an April Fool's prank!
Anyway, I have given up trying solutions for now and decided it is more practical for me to just set the Form.Size in the constructor code.
I observe the Designer UI uses Size which it converts to ClientSize in its generated code as follows:
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(744, 109);
this.ControlBox = false;
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
My workaround in my Form's constructor looks like:
/// <summary>
/// Constructor
/// </summary>
public MyForm()
{
// In the designer, MyForm.Size was entered and displayed as 760, 148
InitializeComponent();
// At runtime, MyForm.Size is changed to 760, 111
// I will Reset this form's Size here so I can get full height again.
this.Size = new Size(760, 148);
}
Platform:
Windows 11 Professional
Microsoft Visual Studio Professional 2022
Version 17.1.6
VisualStudio.17.Release/17.1.6+32421.90
Microsoft .NET Framework version 4.8.04161
C# Tools 4.1.0-5.22165.10+e555772db77ca828b02b4bd547c318387f11d01f
HDMI 1920x1080 video (100% or no scaling)

App icon in UWP

I am new to Xamarin and I am creating UWP application. I wanted to know From where i can set app icon image. I had gone through may articles and question on stack-overflow that looks similar, but it still its not clear..
So my Question is exactly where i should change my image for logo. only 24x24 as shown in below image.then what are the others badge logo and etc.?
should i change all images for logo with all dimensions also?
AppxMainfest.Xaml
<?xml version="1.0" encoding="utf-8"?>
<Package ...>
...
<Properties>
<DisplayName>StockDispatchApp.UWP</DisplayName>
<PublisherDisplayName>pci207</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.10240.0" MaxVersionTested="10.0.10586.0" />
</Dependencies>
<Resources>
<Resource Language="EN-US" />
</Resources>
<Applications>
<Application Id="App" Executable="StockDispatchApp.UWP.exe" EntryPoint="StockDispatchApp.UWP.App">
<uap:VisualElements DisplayName="StockDispatchApp.UWP" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png" Description="StockDispatchApp.UWP" BackgroundColor="transparent">
<uap:LockScreen Notification="" BadgeLogo="Assets\96x96.png" />
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"></uap:DefaultTile>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
...
The MSDN documentation provides clear description of where each of the images is used. In the bottom you can see Asset size tables tables which contain all the dimensions and their usage.
As for the Square 44x44 logo, the first five images in the first row are used for different scales in the app list.
The target images are used for app icons in different places around the system. In their unplated form, they should have transparent background. You can provide just the sizes recommended by the form, but you can also provide more sizes (see the documentation for the complete table).
You don't need to worry about this, you can simply generate all the icons from Visual Studio 2017.
Go to App manifest and click on Visual Assets In all visual assets
There is option called Asset Generator, select at least a 400x400 px
icon file size for the source field
And tap generate And here you get
the all icons.
For reference please have a look at the attached screenshot.

Supported Cultures Box not available in manifest

This msdn link says that to add more language to your windows phone app, you need to make changes in the supported culture box in the properties page, but I can't find such box in the properties page as well as manifest page.
I tried searching all the tabs and I have uploaded the screenshots of properties page as well as manifest, but I'm not able to find the required box.
I have developed an application and updated on the store but only English (US) is the supported language and I'm not able to localize the app.
I'm not able to add screenshots as it requires more that 10 reputation.
Adding resource files
You do not specify what languages you support in the project properties any more. You only specify the default language in the app manifest.
You have to manually add one .resw file for each language you support. The files must all be named Resources.resw and must be placed in a sub-folder, named after the language, under a “Strings” folder in your project.
Accessing resources from xaml
You access the resources by setting the x:Uid property of a control to a unique name. Unfortunately the x:Uid property is not recognized by the properties window, neither in VisualStudio nor in Blend, so you must hand code it directly in the xaml file.
Example:
<TextBlock x:Uid="MyTextBlock" /> <Button x:Uid="MyButton" />
<TextBlock x:Uid="MyTextBlock" />
You must then add a resource with the uid-name with dot-notation, that is, after the dot you write the name of the property of the control in which you want the text.
Reference : http://www.jayway.com/2014/04/22/windows-phone-8-1-for-developers-localizing-apps/

How to set package name of Xamarin.Android APK for Google Play submission

I have finished my app after 8 months work and I am attempting to submit to Google Play.
I sign the and align the APK properly and upload the APK to Google Play. Then I get the following message:
Upload failed Your APK's package name must be in the following format "com.example.myapp". It may contain letters (a-z), numbers, and underscores (_). It must start with a lowercase character.
Here is the AndroidManifest.xml file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" package="com.vrocket.launcher" android:versionName="1.30.637" android:versionCode="1">
<uses-sdk android:targetSdkVersion="14" />
<application android:hardwareAccelerated="true" android:label="launchpad">
<provider android:name="com.vrocket.launcher.LocalFileContentProvider" android:authorities="com.vrocket.launcher" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>
As far as I can tell, the package name I specify here meets the requirements for Google Play submission. I did change my package name in the Android.Manifest since I started the project but I figure this would be pretty normal practice.
Has anyone had similar issues submitting a Xamarin.Android app to Google Play?
EDIT:
I have since figured out that the APK is being compiled with an old package name VRocket.VRocket.
I found this out using the aapt tool in the Android SDK.
Why is it not building with the package name specified in AndroidManifest.xml?
The properties window in Visual Studio (assuming your writing in this) has a couple of settings you can change. These override the manifest when you compile. Perhaps this is where your stray name is coming in from? Same goes for the attributes you place in the class files in your code, Xamarin rewrites all of your manifest on compile. If you display hidden files in the solution tab and go to
obj\Release\android
this directory has the manifest that is generated for your app. Maybe it will shed some light.
I'm using DevStudio and did all of the following things, the last of which FINALLY worked and the Play store accepted my build. I'm pretty sure #2 and #5 are required, maybe all of them, but in any case I think this should go a long way to helping people in a similar situation:
Changed the filename to com.foo.bar.apk (pretty sure this doesn't
matter)
Right-clicked on ProjectName.Droid, Properties-->Android Manifest. Changed the Package Name to com.foo.bar
In that same dialog, set Version Number to 1 and Version Name to "Alpha 1"
Under Properties-->Application, changed Assembly to com.foo.bar
In the Archive Manager, right click on my app and Delete it. Re-create via right-clicking on project again and choosing
Archive...

Resources