7

For an F# application, I attempted to follow these instructions:

How to force my .NET application to run as administrator?

Alas, Visual Studio does not have the same commands and project configuration pages for F# projects as for C# projects. I have created a throwaway C# project, copied its app.manifest into my F# project, and modified the <requestedExecutionLevel> as per the issue above. Nevertheless, the .exe still runs without administrator privileges.

So then, how do I build an F# application so that it only runs as administrator?

Community
  • 1
  • 1
Brad Collins
  • 846
  • 9
  • 18

1 Answers1

9

C# project files (.csproj) contain the following lines:

<PropertyGroup>
  <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

I just copied and pasted those lines into my .fsproj file just above the following line:

<Import Project="$(FSharpTargetsPath)" />

... and lo, my .exe now has the little shield badge on its icon and prompts me for elevated privileges every time I run it.

Brad Collins
  • 846
  • 9
  • 18
  • 1
    It wasn't clear to me so this may help others: make sure to add `app.manifest` to your project or it won't pick it up. – Andrew Keeton Aug 27 '19 at 17:49