How do I force a WPF .NET Core 3.1 app to run as administrator?
In .NET Framework, it was as simple as adding an app.manifest to your project and then adding the "requireAdministrator" line:
<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>
But in .NET Core, when I add the app.manifest file to my project, and then ensure the .csproj file contains
<ApplicationManifest>app.manifest</ApplicationManifest>
it gives me a compilation error:
c1010001 Values of attribute "level" not equal in different manifest snippets.
This errors occurs because it is trying to issue an "mt.exe" command to merge my app.manifest with one that resides in obj\x64\Debug\netcoreapp3.1\Manifests\app.manifest. When I go to look at that file, it contains a request level set to "asInvoker" so hence the error. However, if I completely delete my obj folder, this file gets regenerated all the time, and I don't know where it is coming from.
All I want to do is to force my WPF app to run as admin. Any help would be greatly appreciated.