【发布时间】:2010-12-04 21:15:50
【问题描述】:
我查看了C:\Program Files\Microsoft.NET,但看不到任何SN.exe 文件。
我安装了 .NET 3.5 运行时;这还不够吗?
【问题讨论】:
-
如果您使用 Visual Studio 命令提示符,它应该可以开箱即用
我查看了C:\Program Files\Microsoft.NET,但看不到任何SN.exe 文件。
我安装了 .NET 3.5 运行时;这还不够吗?
【问题讨论】:
您需要安装 Windows SDK 6.0a,而不仅仅是运行时。
如果你已经安装了VS2008,你会发现它已经安装好了,sn.exe会在这里:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\sn.exe
否则,如果你没有安装VS2008,你可以单独下载SDKhere。
SDK 中没有 sn.exe 文件。 SDK的当前版本是6.1,也许他们在这个版本中删除了sn.exe。
【讨论】:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\sn.exe
cd \
dir /s sn.exe 你会得到类似的输出
Volume in drive C has no label.
Volume Serial Number is XXXX-XXXX.
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin的目录
11/07/2007 12:01 PM 95,728 sn.exe
1 File(s) 95,728 bytes
你找到了目录:)
如果没有,您的系统中没有sn.exe。然后安装 SDK。
【讨论】:
我相信你有你的理由——而且在很多情况下SN.exe 是不可避免的和/或适当的(延迟签名)。 (我已经 +1 了 Q 和接受的 A 并且没有以任何方式质疑它们的优点,所以如果它不适用于您的情况,请忽略这一点)
请注意,SN.exe 在实践中很少需要 - 驱动编译器的Microft.<lang>.targets 中的接线[和AL.exe 等] 所有[有效] 都考虑了 .proj 文件中的SignAssembly 标志,并且有条件地将密钥传递给编译器等,因此它可以通过内联程序集的一次触摸完成所有工作(主要是出于性能原因)。
此逻辑还处理 .snk 和 .pfx 密钥之间的区别(它们受密码保护并被秘密存储到密钥容器中)。根据哪种形式,在运行时目录中会出现由Microsoft.Common.targets 解析的KeyContainerName 或KeyOriginatorFile 属性 - 搜索ResolveKeySource。
如果您需要执行SN 的原因是因为您刚刚重写了一个程序集,那么通常应该使用相同的模式,即Mono.Cecil 和类似 PostSharp 的工具(我假设,未确认)通常也需要可以使用相同的参数和/或进行内联签名。
<Target Name="ResolveKeySource"
Condition="$(SignManifests) == 'true' or $(SignAssembly) == 'true'">
<ResolveKeySource ...
KeyFile="$(AssemblyOriginatorKeyFile)"
CertificateFile="$(ManifestKeyFile)"
SuppressAutoClosePasswordPrompt="$(BuildingInsideVisualStudio)">
<Output TaskParameter="ResolvedKeyFile" PropertyName="KeyOriginatorFile" ..."/>
<Output TaskParameter="ResolvedKeyContainer" PropertyName="KeyContainerName" ... "/>
<Csc ...
KeyContainer="$(KeyContainerName)"
KeyFile="$(KeyOriginatorFile)" />
为了完整起见,以下是如何以编程方式推断与您正在编译的目标相关的 SDK 路径(在 4.0 上测试,但同样的方法可以一直追溯到 2.0,即Microsoft.Common.targets 已处理此数据一段时间):
<Target Name="ResolveSNToolPath" Condition=" 'true' == '$(SignAssembly)' ">
<PropertyGroup>
<_SdkToolsBinDir Condition=" '' == '$(_SdkToolsBinDir)' ">$(TargetFrameworkSDKToolsDirectory)</_SdkToolsBinDir>
<SNToolPath Condition=" '' == '$(SNToolPath)' ">$(_SdkToolsBinDir)SN.exe</SNToolPath>
</PropertyGroup>
<Error Condition=" 'true' == '$(SignAssembly)' AND !EXISTS( '$(SNToolPath)' )"
Text="In order to resign the assembly, this package requires access to the SN.EXE tool from the Windows Platform SDK, which was not found.
The location derived was "$(SNToolPath)".
Please either:
1) supply a correct path to your SDK Tools bin directory containing SN.EXE by setting %24(_SdkToolsBinDir) or %24(TargetFrameworkSDKToolsDirectory)
OR
2) supply a correct complete path to your SN.EXE signing tool by setting %24(SNToolPath)" />
</Target>
为了完整起见,以下是您如何利用此过程的输出来运行 SN.exe
<Target Name="ResignMyAssembly" Condition="$(SignAssembly) == 'true'">
<Exec Condition=" '$(KeyContainerName)' != '' "
Command=""$(SNToolPath)" -Rca "@(MyAssembly)" "$(KeyContainerName)" " />
<Exec Condition=" '$(KeyContainerName)' == '' "
Command=""$(SlpsSdkProtectSnTool)" -Ra "@(MyAssembly)" "$(KeyOriginatorFile)" " />
【讨论】:
它是 SDK 的一部分(.NET,或者现在的 Windows SDK)
【讨论】:
对于 VS2017 路径更改为:
C:\Program Files (x86)\Microsoft SDKs\Windows\vX\bin\NETFX X.X.X Tools\.
【讨论】:
很简单:
在windows下(根据.net framework版本\B8.1A..的路径变化),转到=>
C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 工具
编写您的 sn.exe 命令:
sn -i D:\XX\MYProject.UI.api\MYProject.Gateway\my_certificate.pfx VS_KEY_AD6FD8AFB39B6C43
如果它是受密码保护的,那么它会希望 pwd 把它写下来
【讨论】:
不,看来您需要 SDK :(
仅供参考,运行时本身不会在 C:\Program Files\Microsoft.NET 下——它的所有文件都在 [仅] 在 C:\Windows\Microsoft.NET\vXXXXXX\ 下运行
【讨论】:
对于 VS2019,路径是 C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\x64\sn.exe
现在我仍然无法使用 VS 命令提示符。它向我显示消息,例如
** Visual Studio 2017 开发人员命令提示 v15.8.9 ** 版权所有 (c) 2017 Microsoft Corporation
[vcvarsall.bat] 环境初始化为:'x64'
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>其中 sn.exe 信息:找不到给定模式的文件。
【讨论】: