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

问题描述 投票:0回答:2

我们最近将 Visual Studio 从 2010 年升级到 2013 年,除了一件事之外,一切似乎都与以前一样。 2010 年,代码签名仅在发布项目时执行,但在 2013 年,它希望在我们每次构建项目时对输出程序集进行签名。

我在尝试在线查找有关此问题的任何结果时遇到问题,所有内容都仅指向如何首先设置签名,而不是如何在正常调试构建期间防止其签名。


我创建了一个新项目并开始使用设置来确定在正常构建期间哪个单一设置可能会触发签名要求。在安全选项卡下的项目属性页面中,如果选中“启用 ClickOnce 安全设置”复选框,则 2013 需要签名步骤,但 2010 似乎没有该要求。

我仍然需要确认这是否是此行为的单一决策点。


已确认。

我创建了两个解决方案,每个解决方案都有一个空的 WinForms 应用程序。一个解决方案是在 Visual Studio 2010 中创建的,另一个是在 Visual Studio 2013 中创建的。我进入每个解决方案的项目属性并通过签名选项卡启用签名,然后在安全选项卡中选中“启用 ClickOnce 安全设置”并使用“This是一个完全信任的应用程序”。请注意,这些项目是使用启用 PIN 的智能卡上的证书进行签名的。

VS 2013 在调试模式下正常构建期间会提示输入智能卡 PIN,而 2010 则不会。现在的问题基本上是为什么两个版本之间存在差异以及如何在 2013 年修复此问题以使其表现得像 2010 年一样。


我包含了我在下面创建的测试解决方案的项目文件。比较差异并没有指出任何明显的不同。我还尝试将 VS 2013 项目更改为与 VS 2010 项目相同的框架,以尽量减少项目之间的差异 - 这不会改变行为差异。

Visual Studio 2010 项目文件

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProductVersion>8.0.30703</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{E31DA60C-E444-4E34-AF6D-5B4588CC1F8E}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>SigningTest1</RootNamespace>
    <AssemblyName>SigningTest1</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
    <PlatformTarget>x86</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup>
    <SignManifests>true</SignManifests>
  </PropertyGroup>
  <PropertyGroup>
    <ManifestCertificateThumbprint>22E252B5076264F4F2CD88983A9053D554CCD185</ManifestCertificateThumbprint>
  </PropertyGroup>
  <PropertyGroup>
    <TargetZone>LocalIntranet</TargetZone>
  </PropertyGroup>
  <PropertyGroup>
    <GenerateManifests>true</GenerateManifests>
  </PropertyGroup>
  <PropertyGroup>
    <ApplicationManifest>Properties\app.manifest</ApplicationManifest>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </EmbeddedResource>
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <None Include="Properties\app.manifest" />
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

Visual Studio 2013 项目文件

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{732A657C-452D-4942-8832-89A14314739C}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>SigningTest2013</RootNamespace>
    <AssemblyName>SigningTest2013</AssemblyName>
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
    <TargetFrameworkProfile>Client</TargetFrameworkProfile>
    <FileAlignment>512</FileAlignment>
  </PropertyGroup>
  <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>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup>
    <SignManifests>true</SignManifests>
  </PropertyGroup>
  <PropertyGroup>
    <ManifestCertificateThumbprint>22E252B5076264F4F2CD88983A9053D554CCD185</ManifestCertificateThumbprint>
  </PropertyGroup>
  <PropertyGroup>
    <TargetZone>LocalIntranet</TargetZone>
  </PropertyGroup>
  <PropertyGroup>
    <GenerateManifests>true</GenerateManifests>
  </PropertyGroup>
  <PropertyGroup>
    <ApplicationManifest>Properties\app.manifest</ApplicationManifest>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Deployment" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Windows.Forms" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Form1.cs">
      <SubType>Form</SubType>
    </Compile>
    <Compile Include="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
    </Compile>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <EmbeddedResource Include="Properties\Resources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </EmbeddedResource>
    <Compile Include="Properties\Resources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Resources.resx</DependentUpon>
      <DesignTime>True</DesignTime>
    </Compile>
    <None Include="Properties\app.manifest" />
    <None Include="Properties\Settings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
    <Compile Include="Properties\Settings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

我会尽可能上传每个问题的完整解决方案。由于大多数文件共享网站被阻止,我无法在当前的计算机上执行此操作。

visual-studio-2010 visual-studio-2013 clickonce code-signing
2个回答
19
投票

这篇文章包含迄今为止发现的行为改变的最佳解决方案。该解决方案是由 Leandro Taset 在对原始问题的 评论中提出的:

对于需要代码签名的项目,打开其关联的

.csproj

 文件。您应该能够在该文件中列出的 
SignManifests
 节点内找到 
PropertyGroup
 节点,如下所示:

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

此属性显示在 VS2010 和 VS2013 项目文件中,并在项目范围中列出。您应该能够找到两个不同的

Property Group

 节点,类似于以下内容:

<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

 节点定义项目属性,这些属性是根据构建项目时的当前配置和目标平台有条件地应用的。

您需要删除首先找到的

SignManifests

 节点,并在每个条件 
SignManifests
 节点中放置一个新的 
PropertyGroup
 节点:

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

这将使 VS2013 表现得更好一些。在发布构建期间(好吧,在示例发布构建目标

AnyCPU

中)VS2013将尝试签署清单,而在调试模式下则不会。

此解决方案的一些注意事项:

    这并不完全是启用 ClickOnce 签名时 VS2010 的行为方式。 VS2010 仅在 ClickOnce 发布期间签名,在构建期间不会签名(无论配置和目标平台如何)。
  1. 如果您在 VS2013 中打开项目属性的“签名”选项卡,则会显示 ClickOnce 签名未启用(无论配置和目标平台如何)。不要让这个欺骗你,它仍然会在发布版本期间进行属性签名。选中此选项卡上的复选框将在
  2. SignManifests
     级别重新添加 
    Project
     节点,而无需任何条件,使我们回到开始的位置。在其他选项卡中更改项目设置不会出现重新添加节点的情况,因此您可以在其他地方自由地进行所需的项目属性更改。

0
投票
使用 VS2022,添加条件 SignManifests 确实阻止了调试版本的签名,但它没有签署已发布的版本。知道出了什么问题吗?

注意,我没有 csproj 文件。我将这些添加到vbproj中,我认为是相同的。

© www.soinside.com 2019 - 2024. All rights reserved.