Compile application twice with different manifest files - wpf

Is there a way to compile a WPF application twice in Visual Studio (version 2015/2017) with different manifest files?
On the one hand I need the application to require administrator permissions, on the other hand the same application without administrator permissions (means: without or another manifest file).
With compile constants I'm able to do something like this:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="Update.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
#if ADMIN
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
#endif
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
but this doesn't seem to work like expected.
A solution where I only need to click the build button once and receive two applications would be perfect.
Another possible solution is to use post-build commands, but I'm not sure if this will work.

There is an option in Visual Studio 2017 (and maybe earlier versions, I cannot confirm) that allows you to build multiple configurations in a single run.
Look at the toolbar menu: "Build" > "Batch Build"

Related

Windows 10 Kiosk Mode (MultiAppAssignedAccess Provisioning package) won't install

For my Project at work i want to install a provisioning Package, that contains a xml configuration for Kiosk Mode (Assigned Access).
I used the exact code from the xml reference page and inserted my Apps, as an account i used a local account that i created for testing.
<?xml version="1.0" encoding="utf-8" ?>
<AssignedAccessConfiguration
xmlns="http://schemas.microsoft.com/AssignedAccess/2017/config"
xmlns:rs5="http://schemas.microsoft.com/AssignedAccess/201810/config"
>
<Profiles>
<Profile Id="{786df454-09d0-492f-9ef0-c07731d1606f}">
<AllAppsList>
<AllowedApps>
<App DesktopAppPath="C:\Program Files\Google\Chrome\Application\chrome.exe"/>
</AllowedApps>
</AllAppsList>
<StartLayout>
<![CDATA[<LayoutModificationTemplate xmlns:defaultlayout="http://schemas.microsoft.com/Start/2014/FullDefaultLayout" xmlns:start="http://schemas.microsoft.com/Start/2014/StartLayout" Version="1" xmlns="http://schemas.microsoft.com/Start/2014/LayoutModification">
<LayoutOptions StartTileGroupCellWidth="6" />
<DefaultLayoutOverride>
<StartLayoutCollection>
<defaultlayout:StartLayout GroupCellWidth="6">
<start:Group Name="Group1">
<start:Tile Size="4x4" Column="0" Row="0" DesktopAppPath="C:\Program Files\Google\Chrome\Application\chrome.exe" />
</start:Group>
</defaultlayout:StartLayout>
</StartLayoutCollection>
</DefaultLayoutOverride>
</LayoutModificationTemplate>
]]>
</StartLayout>
<Taskbar ShowTaskbar="true"/>
<Taskbar/>
</Profile>
</Profiles>
<Configs>
<Config>
<Account>.\Kiosk-test</Account>
<DefaultProfile Id="{786df454-09d0-492f-9ef0-c07731d1606f}"/>
</Config>
</Configs>
</AssignedAccessConfiguration>
When i try to install it, it either wont install at all with Error code 0x8007000b on one computer or on my private computer the installation will fail.
The Settings say that i has to Lock the user interface and make changes to the device.
then the EventLogs say that it failed due to follwing error: "Error during verification because the document does not contain exactly one root node. (0xC00CE223)" (translated with deepl, so might be a bit different in reality)
I could not find a matching solution on the internet.
I also tried using the configuration Wizard for single app Kiosk, and there the same error occured.
Does anyone of you know a solution to that or can tell me what the problem is at all?
I tried to change every part of the code, so that every aspect (App, User, e.g.) is tested seperately.
I moved my computer out the group policies, so that there are no GPOs that vreate an error.
The error messages didn't change at all
Thanks and best Regards!

Publish WPF Core using MSIX...multiple problems

Edit #1 Start
To Replicate this:
Create a new "vanilla" WPF application addressing .Net Core 3.1
Add an Windows Application Packaging Project to the solution (follow the steps mentioned in Set up your desktop application for MSIX packaging in Visual Studio)
Try to "deploy" to a UNC path...
Edit #1 End
I am in the process of converting a WPF .net framework application to .net core 3.1. This application is an "internal" tool that we've always deployed by using ClickOnce to place create the setup on a shared UNC path. So simple....
I've now re-written it in .Net Core and need to deploy it. Finding that "ClickOnce" is no longer available, I understand that I have to go down the "MSIX" route. The documentation looks like it should be simple, but I guess I'm missing a few things....
1 - I've had to change my Developer Settings from "Side Bar" to "Developer Mode"
2 - It builds fine on my machine, but on Azure DevOps fails
3 - and how do I actually deploy it...?
Let's look at each in turn.
1 - Side Bar => Developer Mode issue
I add a new Windows Application Packaging Project to my solution, pick Windows version 1909 for both target and minimum versions, and set my WPF application to be the Entry Point. I try to run this and it forces me to change from "Side Bar" to "Developer Mode".
Is this only affecting me as the developer....if so, that's fine. I doubt the final end users will want to do this.
2 - Azure DevOps build pipeline fails
Locally, it compiles just fine, even under Release Mode where I have all warnings set to Error, and have FxCop running. Push it to Azure and it says:
[error]C:\Program Files\dotnet\sdk\3.1.201\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(234,5):
Error NETSDK1047: Assets file
'd:\a\1\s\MyApp\MyApp\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.1/win-x86'.
Ensure that restore has run
and that you have included 'netcoreapp3.1' in the TargetFrameworks for
your project.
You may also need to include 'win-x86' in your
project's RuntimeIdentifiers.
Okay
my YAML file has a "Restore NuGet Packages" step preceding the build
that succeeded.
I look in my SKD project file for my application and
I see <TargetFramework>netcoreapp3.1</TargetFramework>
Regarding "RuntimeIdentifiers", I found the link Additions to the csproj format for .NET Core so added <RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers> immediately under <TargetFramework>netcoreapp3.1</TargetFramework> (should I be more specific an use win10-x64;win10-x86?)
Either way, this failed with a slightly different message:
There was a mismatch between the processor architecture of the project
being built "MSIL" and the processor architecture of the reference
"path to my dll", "x86". This mismatch may cause runtime failures.
Please consider changing the targeted processor architecture of your
project through the Configuration Manager so as to align the processor
architectures between your project and references, or take a
dependency on references with a processor architecture that matches
the targeted processor architecture of your project.
3 - how do I actually deploy it?
From MSIX: The Modern Way to Deploy Desktop Apps on Windows it states:
To generate the actual MSIX package, there’s a wizard available under
Project | Store | Create App Packages in Visual Studio.
There isn't on my machine....I even went as far as installing the Visual Studio workload "Universal Windows Platform Development". I can see a "Deploy" under the Build menu...but is this it....where do I put the UNC path?
I think I'm missing something fairly fundamental....
The relevant part of my CSPROJ is
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifiers>win-x64;win-x86</RuntimeIdentifiers>
<UseWPF>true</UseWPF>
</PropertyGroup>
The package project is:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' < '15.0'">
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM">
<Configuration>Debug</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM">
<Configuration>Release</Configuration>
<Platform>ARM</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|ARM64">
<Configuration>Debug</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|ARM64">
<Configuration>Release</Configuration>
<Platform>ARM64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|AnyCPU">
<Configuration>Debug</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|AnyCPU">
<Configuration>Release</Configuration>
<Platform>AnyCPU</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup>
<WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
</PropertyGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
<PropertyGroup>
<ProjectGuid>08b169a2-6461-440b-afa1-ca35c7d98aa7</ProjectGuid>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<EntryPointProjectUniqueName>..\MyApp\MyApp.csproj</EntryPointProjectUniqueName>
<PackageCertificateThumbprint>01C08F1E21D5624A484DB362BE4F056504B825CC</PackageCertificateThumbprint>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Images\SplashScreen.scale-200.png" />
<Content Include="Images\LockScreenLogo.scale-200.png" />
<Content Include="Images\Square150x150Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Images\StoreLogo.png" />
<Content Include="Images\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyApp\MyApp.csproj">
<SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
</ProjectReference>
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>
(can/should I remove references to the "DEBUG" and to "ARM" which I don't think will be relevant??)
And the manifest is
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">
<Identity
Name="46aebba6-d403-4412-89c0-05279b36e54e"
Publisher="CN=MyCompany"
Version="2020.5.0.0" />
<Properties>
<DisplayName>MyApp</DisplayName>
<PublisherDisplayName>MyCompany</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.14393.0" MaxVersionTested="10.0.14393.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate"/>
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="MyApp.Package"
Description="MyApp.Package"
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
<uap:SplashScreen Image="Images\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
Thanks!
In .wapproj project file please add,
<PropertyGroup>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
None
</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
</PropertyGroup>

VB2015 Designer text / display scaling

I have a Win Forms application that I work on in either on my laptop or desktop. (Nothing special about the software, what i working on seems irrelevent)
Both displays on the desktop and laptop have different text scaling options.
On one computer the project layout (position of text boxes, labels etc) is fine, BUT! If you open the project on the other, everything moves and the layout ( / my GUI) ends up completely ruined. If you build / save this project, then all is lost and it all has to be reset/relocated to suit the computer your are building it on. Once the project is actually built, the application runs / looks fine. (on any screen/ res/ dpi scale) (EDIT: The built version is fine if it was built with the layout correct)
It seems that VS's designer cant handle the DPI scale change when working on the forms.
Does anyone know of a solution to this? I have changed the DPI scaling mode on several controls/forms and nothing seems to work. Its this just a Visual Studio Bug???
Thanks interwebs.
EDIT: OK Here is a twist: If you open the project with your screen text scaling set the same as the computer you last saved the project on, THEN (with VS open) change the text scaling, the controls move correctly and everything looks fine. (Stuff is where it should be) ......
You may have solved this problem by now, but ... Have you tried creating an external manifest file for Visual Studio?
Process is described here: http://www.danantonielli.com/adobe-app-scaling-on-high-dpi-displays-fix/ I copied Antonielli's photoshop manifest file exactly and it seems to work fine, which does not mean I understand it. I will show it below in case someone with knowledge can correct any errors.
Just tried this now, but it seems to be working for me. I am moving windows form app dev from a 1920x1080 laptop to a 2560x1440 laptop and my app scales fine when it runs, but VS2015 screens are unreadable. So, what you see in design is a mess and NOT what you get when you run the app.
My app simply sets AUTOSCALEMODE to INHERIT on all forms and then sets AUTOSCALEMODE to FONT on main form. Various posts here discuss better methods I am sure (e.g, Creating a DPI-Aware Application and How to control the font DPI in .NET WinForms app).
Here is Antonielli's photoshop manifest file (must change registry first per his blog link above) which is saved on my computer as "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe.manifest":
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0" processorArchitecture="*"
publicKeyToken="6595b64144ccf1df"
language="*">
</assemblyIdentity>
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.VC90.CRT"
version="9.0.21022.8"
processorArchitecture="amd64"
publicKeyToken="1fc8b3b9a1e18e3b">
</assemblyIdentity>
</dependentAssembly>
</dependency>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel
level="asInvoker"
uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<asmv3:application>
<asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
<ms_windowsSettings:dpiAware xmlns:ms_windowsSettings="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</ms_windowsSettings:dpiAware>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

Unable to uninstall with custom WiX installer

I've created a custom WiX Burn installer using ManagedBootstrapperApplicationHost with a WPF frontend (using WiX 3.9).
The installation of my MSI works correctly. I use mBootstrapperApplication.Engine.Detect(); to determine if the MSI package is present or not. If it is, I follow a flow similar to that of the installation, in order to uninstall:
mBootstrapperApplication.Engine.Plan(LaunchAction.Uninstall);
Once it's in the PlanComplete event and the Status == 0, I call mBootstrapperApplication.Engine.Apply(System.IntPtr.Zero); and will eventually get back to the ApplyComplete event with Status == 0.
Unfortunately though, nothing seems to have happened at that point.
I'm hooked up to the ExecuteMsiMessage and it has no messages coming through. When ExecuteBeginis fired, PackageCount is 0, where I believe it should be 1.
I can post code if necessary. My wxs file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension" xmlns:bal="http://schemas.microsoft.com/wix/BalExtension" xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">
<Bundle Name="CustomInstallBootstrapper" Version="1.0.0.0" Manufacturer="Square Enix Ltd." UpgradeCode="33CA185D-083B-4D45-A0AE-693C2E09C5F0">
<BootstrapperApplicationRef Id="ManagedBootstrapperApplicationHost">
<Payload SourceFile="D:\Project\CustomInstallBootstrapper\BootstrapperCore.config"/>
<Payload SourceFile="D:\Project\CustomInstallBootstrapper\CustomInstallBootstrapper.dll"/>
</BootstrapperApplicationRef>
<WixVariable Id="WixMbaPrereqPackageId" Value="ignore" />
<WixVariable Id="WixMbaPrereqLicenseUrl" Value="ignore" />
<Chain>
<PackageGroupRef Id="NetFx451Redist"/>
<MsiPackage Id="LauncherMSI" SourceFile="D:\Project\Launcher.msi" Cache="yes" Visible="no">
</MsiPackage>
</Chain>
</Bundle>
</Wix>
If I run the MSI on its own, I can install and uninstall it without any issues.

WPF Application not getting file access rights

I have a WPF app that creates some text files in its own install directory. However, even after the UAC prompt, windows vista and windows 7 users often times still get "file access failed" type errors. The solution is to find the executable in windows explorer and open up the compatibility tab under the file properties and check "run as administrator". This is obviously a terrible user experience but I'm not sure how to ensure the app can secure itself these permissions without that step being taken. I am not trying to bypass the UAC prompts.
In general, .Net wants you to put application generated files either into the user's home directory or the shared user folder. Have a look at this answer: When using a Settings.settings file in .NET, where is the config actually stored?
It talks about .Net config files but you can put other files there.
You can force your app to start with admin rights (UAC will show it's dialog box anyway) by embedding custom manifest (project properties -> build -> Manifest).
Manifest example (requestedExecutionLevel part is importaint):
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0"
xmlns="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv1="urn:schemas-microsoft-com:asm.v1"
xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="yourappname.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of all Windows versions that this application is designed to work with. Windows will automatically select the most compatible environment.-->
<!-- If your application is designed to work with Windows 7, uncomment the following supportedOS node-->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
</application>
</compatibility>
</asmv1:assembly>

Resources