简体   繁体   中英

How to request administrator permissons only on release builds?

Description: I want my application to request administrator permissions only when it is compiled using my Release configuration. The main reason for it is that I do not need the administrator permission when debugging/developing the app, but it requires administrator permission when delivered.

Currently I only use the app.manifest file for requesting the administrator permissions with the following code:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Now to my question: Where in my project file ( name.csproj ) do I have to include the app.manifest file in order to only embed it when I'm using my "Release" configuration?

I use the following code to include the app.manifest file inside the project file:

<ApplicationManifest>app.manifest</ApplicationManifest>

After taking another look at my project file I figured out where to put it.

Answer: Inside the following PropertyGroup in the project file ( name.csproj ), which represents the "Release" build,
you have to put the following code to include the app.manifest file:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    ...
    <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

This allows to only request administrator rights on "Release" builds. It can also be added on other build configurations as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM