Msbuild Postsharp抛出System.Runtime.InteropServices.COMException(0x8013141C):未找到强名称密钥容器。(来自HRESULT的异常:0x8013141C)

Msbuild Postsharp抛出System.Runtime.InteropServices.COMException(0x8013141C):未找到强名称密钥容器。(来自HRESULT的异常:0x8013141C),msbuild,code-signing,postsharp,Msbuild,Code Signing,Postsharp,为将来需要解决相同问题的任何人添加问题 环境:Visual Studio 2017或2019 对程序集进行Postsharp签名时出现生成错误 MSBuild postsharptest.csproj /T:Rebuild /P:PostSharpTrace=StrongName /V:D /P:PostSharpHost=Native > postsharp.log C:\ProgramData\PostSharp\4.0.41\bin.Release\postsharp.4.0-x8

为将来需要解决相同问题的任何人添加问题

环境:Visual Studio 2017或2019
对程序集进行Postsharp签名时出现生成错误

MSBuild postsharptest.csproj /T:Rebuild /P:PostSharpTrace=StrongName /V:D /P:PostSharpHost=Native > postsharp.log

C:\ProgramData\PostSharp\4.0.41\bin.Release\postsharp.4.0-x86.exe obj\Debug\Before-PostSharp\PostsharpTest.exe /X:default /NoLogo /P:Output=C:\PostsharpTest\obj\Debug\PostsharpTest.exe /P:ReferenceDirectory=C:\PostsharpTest /P:Configuration=Debug /P:Platform=AnyCPU "/P:SearchPath=bin\Debug\|obj\Debug\|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Facades\ " /P:IntermediateDirectory=obj\Debug\PostSharp /P:CleanIntermediate=False /P:MSBuildProjectFullPath=C:\PostsharpTest\postsharptest.csproj /P:SignAssembly=true /P:PrivateKeyLocation=Thycotic.snk /P:PrivateKeyContainer= /P:DelaySign= "/P:ResolvedReferences=C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.CSharp.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll|C:\PostsharpTest\packages\PostSharp.4.0.41\lib\net35-client\PostSharp.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.DataSetExtensions.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Net.Http.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.dll|C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.Linq.dll" /P:SymbolFile=bin\Debug\PostsharpTest.pssym /P:WriteWeavingSymbols=True /P:ConstraintVerificationEnabled=True /P:RuntimeVerificationEnabled=True /P:TargetFrameworkVersion=v4.5 /P:TargetFrameworkIdentifier=.NETFramework /P:TargetFrameworkProfile= "/P:TargetFrameworkMoniker=.NETFramework,v4.5" "/P:NativeFrameworkMoniker=.NETFramework,v4.5.1" /P:BindingMapsDirectory=C:\ProgramData\PostSharp\4.0.41\BindingMaps /P:PostSharpLibraryProfile= /P:AspectProviders= "/P:Language=C#" /T:StrongName /config C:\ProgramData\PostSharp\4.0.41\bin.Release\postsharp.4.0-x86.exe.config 
C:\PostsharpTest\postsharptest.csproj : warning PS0131: The project 'ModuleDeclaration PostsharpTest.exe' does not contain any aspect or other transformation. You can disable PostSharp for this project by editing the project properties in Visual Studio. Remember to enable PostSharp back if you add an aspect to this project.
C:\PostsharpTest\postsharptest.csproj : error PS0099: Unhandled exception (4.0.41.0, 32 bit, CLR 4.5, Release): System.Runtime.InteropServices.COMException (0x8013141C): Strong name key container not found. (Exception from HRESULT: 0x8013141C)
C:\PostsharpTest\postsharptest.csproj : error PS0099: at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
C:\PostsharpTest\postsharptest.csproj : error PS0099: at ^nIsIyZ7TTJqY.GetKeyInfo(^8gP93Xsl\+Imn _0)
C:\PostsharpTest\postsharptest.csproj : error PS0099: at ^Up6wxUIUnN6a.^3w8852HL()
C:\PostsharpTest\postsharptest.csproj : error PS0099: at ^Up6wxUIUnN6a.^VfvrABjR()
C:\PostsharpTest\postsharptest.csproj : error PS0099: at ^Up6wxUIUnN6a.^SkiT()
C:\PostsharpTest\postsharptest.csproj : error PS0099: at ^Up6wxUIUnN6a.^8KD6D2SV(String _0)
C:\PostsharpTest\postsharptest.csproj : error PS0099: at ^cyC/TYSlPGB/.^wvPm(^RtksFin57NJ8 _0, ^8gP93Xsl\+Imn _1)
C:\PostsharpTest\postsharptest.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Tasks.CompileTask.Execute()
C:\PostsharpTest\postsharptest.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Project.ExecutePhase(String phase)
C:\PostsharpTest\postsharptest.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Project.Execute()
C:\PostsharpTest\postsharptest.csproj : error PS0099: at PostSharp.Hosting.PostSharpObject.ExecuteProjects()
C:\PostsharpTest\postsharptest.csproj : error PS0099: at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation).

我在尝试使用(SN.exe)创建新签名密钥时,遇到访问被拒绝的错误,因此我能够解决此问题

sn -k jeff.snk
Failed to generate a strong name key pair -- Access is denied.

使用显示问题是对
C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys
中特定文件的访问被拒绝。在授予自己对目录中所有文件的访问权限后,我能够创建签名密钥并运行msbuild,没有任何错误。

我发现McAfee防病毒有时会阻止此访问。Postsharp的技术支持论坛网站规避AV是其失败的唯一原因