Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manifest does not force Visual Studio 2013 to restart under Admin when running application in Debug mode

This worked in VS2010 and VS2012. But in VS2013 application (by pressing "Run" or F5) is just starts with my user's rights and cannot access some resources (I'm using HttpListener).

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
  <security>
    <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
      <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
    </requestedPrivileges>
  </security>
</trustInfo>

I tried to google, tried to generate new manifest, copied it's content from MSDN, but nothing helped. Did something changed in this part of VS2013?

Update1:
That was a part. Here is complete manifest content:

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
  <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
  </requestedPrivileges>
</security>
</trustInfo>

<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
  <application></application>
</compatibility>

</asmv1:assembly>

Update2:
Okey here is simple example: when I run compiled .exe file UAC asks for admin privileges. But when I run it from VS2013 (by pressing "Run" or F5) it doesn't! And if you open the same project with VS2012/VS2010, they do ask to restart under admin.
You can check this quickly:
Create console application in VS2013, add manifest and set level="requireAdministrator". Then run or press F5 (VS2013 runs the application under admin when press Ctrl-F5).
But this is not the behavior of VS2012/VS2010!
How can we get the old behavior?

Update3:
Please vote here or inform me about another ticket.

like image 953
Taras Kozubski Avatar asked Oct 30 '13 19:10

Taras Kozubski


3 Answers

You need to disable the hosting process option to get the VS restart prompt. Project + Properties, Debug tab, untick the "Enable the Visual Studio hosting process" checkbox. It can be easier to just start VS elevated right away. Right-click the shortcut, Run as Administrator.

Not entirely sure if this is a bug or a feature. Keep your eye on this Connect report to learn more.


Update: looks like a bug, the feedback report was closed as "fixed". Unfortunately it gives no hint when that fix is going to make it our machines. Maybe a future VS2013 update, surely the next version.
Update2: the fix made it into VS2013 Update 3.

like image 186
Hans Passant Avatar answered Nov 18 '22 20:11

Hans Passant


What I ended up doing is I run the project without debugging CRTL+F5 . The it gives me the same prompt that Visual Studio 2010 gives you.

like image 20
Tono Nam Avatar answered Nov 18 '22 18:11

Tono Nam


I'm hoping this will get fixed soon™ In the mean time you can use handy shortcuts for restarting VS in admin mode, look up "Visual Studio Restart" in the extension gallery.

Edit:

Only way I see you can achieve the old behavior is to turn off VS hosting process as it is this process that for some reason "eats" the elevation prompt. Actually when I think about it, this behavior might even be by design. You can turn off hosting process in project properties (Debug) or when you generate .csproj set platform configuration UseVSHostingProcess tag to false, like so:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
like image 1
Nemo Avatar answered Nov 18 '22 18:11

Nemo