Vista, UAC elevation and MSBuild

While making an application that requires UAC elevation in Vista I used this neat article to create my manifest and add it to Visual Studio. The one problem with that is that the MSBuild build then failed to add that manifest. The problem is that $DevEnvDir variable is not defined when run by MSBuild. This makes sense when you think about it because MSBuild is installed on all machines with the .net framework but not all those machines might have Visual Studio. To fix the problem just add the following parameter, “/property:DevEnvDir=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\”
.

In my batch file the complete line looks like this,

c:\Windows\Microsoft.NET\Framework\v2.0.50727\msbuild.exe Basher.sln "/property:DevEnvDir=C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\"

You might also need to change the build event to have a slash straight after the variable. This makes it,

"$(DevEnvDir)\..\..\SDK\v2.0\bin\mt.exe" -manifest "$(ProjectDir)$(TargetName).exe.manifest" –outputresource:"$(TargetDir)$(TargetFileName)";#1

Another thing to watch out for if you launch your program to do the task with elevated access is what happens if the user cancels the access.   In the case of .Net you might get a “System.ComponentModel.Win32Exception: The operation was canceled by the user”.  This probably translates to a normal error return from ShellExecute if you are doing it from win32.

1 Comment »

  1. [...] even if you want to run ‘asInvoker’ which is typically just as the user. My previous post on the subject mentions how to setup the manifest but Aaron’s UI Design Blog has more on the [...]

RSS feed for comments on this post · TrackBack URI

Leave a Comment