Temporarily change manifest requestedExecutionLevel when debugging

.net, debugging, manifest, permissions, visual-studio-2010

Solution

You can do this with pre-build events `Project -> Options -> Build Events`

Make a pre-build event like :

del "$(ProjectDir)app.manifest"

if "$(ConfigurationName)"=="Debug" (
  copy "$(ProjectDir)app.debug.manifest" "$(ProjectDir)app.manifest"
) else (
  copy "$(ProjectDir)app.release.manifest" "$(ProjectDir)app.manifest"
)

Here we're assuming your manifest is called `app.manifest` and is in the root directory for your project - obviously modify it as needed.

In any case, make two copies of your manifest file and call one `app.debug.manifest` and one `app.release.manifest`, configure them appropriately, and this will replace the active `app.manifest` with the appropriate version before each build.

EDIT:

If you want MSBuild to use the same configuration but a different manifest than Visual Studio, you may also try tweaking the above pre-build event to look like this:

del "$(ProjectDir)app.manifest"

if "$(AdminManifest)"=="true" (
  copy "$(ProjectDir)app.release.manifest" "$(ProjectDir)app.manifest"
) else (
  copy "$(ProjectDir)app.debug.manifest" "$(ProjectDir)app.manifest"
)

Now when you run MSBuild, you can do it like so:

MSBuild.exe MySolution.sln /p:Configuration=WhateverYouWant /p:AdminManifest=true

see also :

https://stackoverflow.com/a/938888/327083

https://stackoverflow.com/a/1732478/327083

Problem

I'm developing an application in Visual Studio which will require administrator permissions after it is installed on a user's system. I've added a proper application manifest file that will make sure this happens: ``` <requestedExecutionLevel level="requireAdministrator" uiAccess="false" /> ``` However now if I want to debug the program in Visual Studio, I am required to run Visual Studio as an administrator. No bueno. And the most annoying part is that the program doesn't really need administrator privileges during debugging. It only requires those privileges after being properly installed on a user's system. Is there a clean, easy way to "throw a switch" that disables the administrator requirement during development, and then re-enables it when I release the application? EDIT: When I release the application to the user, I run a build script which uses MSBuild. What I'm trying to do is make Visual Studio build a solution in the Release configuration without the administrator manifest. Then when I run my build script, I want to get MSBuild to include the administrator manifest while keeping the same Release configuration.

Original source

Related problems