visual-studio 如何在编译时在 Visual Studio 2010 中嵌入清单文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4084585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:40:37  来源:igfitidea点击:

How to embed a manifest file at compile time in Visual Studio 2010

visual-studiovisual-studio-2010uacmanifest

提问by andy

I have a project with a manifest file with the following node:

我有一个带有以下节点的清单文件的项目:

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

...meaning I want it to only run "as administrator" by default.

...意味着我希望它默认只以“管理员身份”运行。

from searching around, to make this work I have two options:

通过四处寻找,为了完成这项工作,我有两个选择:

  1. "Embed" it.
  2. deploy the manifest file with the exe, and name it YourProject.exe.manifest.
  1. “嵌入”它。
  2. 使用 exe 部署清单文件,并将其命名为 YourProject.exe.manifest。

I've tried option 2, and when I run my app it doesn't ask for admin rights?

我试过选项 2,当我运行我的应用程序时,它不要求管理员权限?

So, how do I do option 1 in VS2010? I've heard of mt.exe, but this is no good to me as it's done post build. I need the option to part of the solution and the project file itself.

那么,如何在 VS2010 中执行选项 1?我听说过 mt.exe,但这对我没有好处,因为它是在构建后完成的。我需要部分解决方案和项目文件本身的选项。

So, how do I make this work? I'll be happy to do 2, but it doesn't seem to work?

那么,我该如何进行这项工作?我很乐意做 2,但它似乎不起作用?

回答by JaredPar

In Visual Studio 2010 the default setting for a new project is to embed the manifest in the application (option #1). By default though a default manifest is included. What you need to do is add a custom manifest.

在 Visual Studio 2010 中,新项目的默认设置是在应用程序中嵌入清单(选项 #1)。默认情况下,虽然包含默认清单。您需要做的是添加自定义清单。

  • Right click on the project and select "Add New Item"
  • Select "Application Manifest File"
  • 右键单击项目并选择“添加新项目”
  • 选择“应用程序清单文件”

This will add a file named app.manifest to the project. Open that file and modify the line to be the following

这会将名为 app.manifest 的文件添加到项目中。打开该文件并将该行修改为以下内容

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

This should also work in Visual Studio 2008.

这也应该适用于 Visual Studio 2008。

回答by Paul Pavlinvovich

Under VS2010 it is a little different. Right click the Project and select Properties. Select the "Application" tab and then click "View Windows Settings". This opens the manifest. Then make the changes you need.

在 VS2010 下有点不同。右键单击项目并选择属性。选择“应用程序”选项卡,然后单击“查看 Windows 设置”。这将打开清单。然后进行所需的更改。

回答by Jay

I just ran into the same problem caused by copying an existing app.manifest into another project (C#).

我刚刚遇到了由于将现有 app.manifest 复制到另一个项目 (C#) 而导致的相同问题。

I fixed it by unloading the project, editing its csproj file and inserting the following section:

我通过卸载项目、编辑其 csproj 文件并插入以下部分来修复它:

<PropertyGroup>
  <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

This allowed my application to pick up the app.manifest correctly.

这使我的应用程序能够正确获取 app.manifest。