且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Visual Studio 2013中为调试版本禁用代码签名?

更新时间:2021-12-07 08:31:21

迄今为止为行为改变找到了解决方案。 Leandro Taset 对原始问题的评论

This post contains the best solution found so far for the change in behavior. The solution was suggested by Leandro Taset in a comment to the original question:

对于需要代码签名的项目,请打开其关联的 .csproj 文件。您应该能够在该文件中列出的 PropertyGroup 节点内找到一个 SignManifests 节点,如下所示:

For the project which requires code signing, open its associated .csproj file. You should be able to find a SignManifests node inside of a PropertyGroup node listed in that file listed as follows:

<PropertyGroup>
  <SignManifests>true</SignManifests>
</PropertyGroup>

此属性同时显示在VS2010和VS2013项目文件中,并在项目范围内列出。您应该能够找到两个与以下内容相似的 Property Group 节点:

This property shows up in both the VS2010 and VS2013 project files and is listed at the project scope. You should be able to find two different Property Group nodes that look similar to the following:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <!-- There may be several properties already in the PropertyGroup node -->
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <!-- There may be several properties already in the PropertyGroup node -->
</PropertyGroup>

这些 PropertyGroup 节点定义了以下项目属性:

These PropertyGroup nodes define project properties which are conditionally applied based on the current configuration and platform being targeted when you build the project.

您将需要删除 SignManifests $ c,并根据当前配置和目标平台有条件地应用此工具。您首先找到的$ c>节点,并将新的 SignManifests 节点放置在每个有条件的 PropertyGroup 节点中:

You'll want to remove the SignManifests node you first found and place a new SignManifests node in each of the conditional PropertyGroup nodes:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <!--  -->
  <SignManifests>false</SignManifests>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <!--  -->
  <SignManifests>true</SignManifests>
</PropertyGroup>

这将使VS2013表现得更好。在发布版本期间(在示例中,发布版本目标为 AnyCPU ),VS2013将尝试对清单进行签名,而在Debug模式下则不会。

This will cause VS2013 to behave a little better. During Release builds (well, in the example Release builds targeting AnyCPU) VS2013 will attempt to sign the manifest and in Debug modes it will not.

此解决方案有几点警告:

A couple caveats to this solution:


  1. 启用ClickOnce签名后,这与VS2010的行为并不完全相同。 VS2010仅在ClickOnce发布期间签名,而在构建期间不签名(无论配置和目标平台如何)。

  2. 如果在VS2013中打开项目属性的签名选项卡,它将将显示未启用ClickOnce签名(无论配置和目标平台如何)。不要让它愚弄您,它在发布版本期间仍会是财产标志。选中此选项卡上的复选框将重新添加 Project 级别的 SignManifests 节点,而无需附加任何条件回到我们开始的地方。在其他选项卡中更改项目设置不会显示在该节点上,因此您可以随意在其他位置进行所需的项目属性更改。

  1. This isn't exactly how VS2010 behaves when ClickOnce signing is enabled. VS2010 will only sign during ClickOnce publishing, it doesn't sign during a build (regardless of the configuration and target platform).
  2. If you open the Signing tab of the project properties in VS2013 it will appear that ClickOnce signing is not enabled (regardless of the configuration and target platform). Don't let this fool you, it will still property sign during Release builds. Checking the checkbox on this tab will re-add the SignManifests node at the Project level without any conditionals on it putting us back where we started. Changing project settings in other tabs doesn't appear re-add the node, so you're free to make needed project property changes elsewhere.