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.

Advertisements

One thought on “Vista, UAC elevation and MSBuild

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s