VS2012 .NET 4.0 Clickonce VSTO CryptographicException: SignatureDescription could not be created for the signature algorithm supplied

前端 未结 4 1178
星月不相逢
星月不相逢 2021-01-12 16:14

I have a VS2010 .NET 4.0 VSTO Outlook Addin project that I wish to migrate to VS2012 (but keep it in .NET 4.0). It compiles fine, and runs from inside the IDE just fine, bu

4条回答
  •  -上瘾入骨i
    2021-01-12 16:42

    Edit: I later found out that the re-sign was the only thing that made this work. Ignore the stuff below about changing the .Net version.


    I ran into this with a VSTO project, while publishing with Visual Studio 2015, targeting .Net 4.5, and running on a client machine with .Net 4.5. Theoretically I should not be seeing the error, but I found that the application manifest (*.dll.manifest) was still specifying .Net 4.0. It would work correctly the first tie it was run after logging in, but would then fail every time after that.

    
      
        
      
    
    

    The version for .Net 4.5 is 4.0.30319.18020 as far as I can tell, so I put that in instead.

    
      
        
      
    
    

    Then I had to re-sign the application and deployment manifests (*.vsto). See Signing and re-signing manifests in ClickOnce. Here is a PowerShell script I used to do that. It runs out of the Application Files\_\ folder.

    # get files only, no directories
    $withDeploy = ls -Recurse | where Mode -eq "------" | where Name -Like "*.deploy"
    
    if ($withDeploy.Length -gt 0)
    {
        # rename .deploy files
        $withDeploy | %{ Rename-Item -Path $_.FullName -NewName $_.FullName.Replace(".deploy", "") }
    
        $certPath = "Z:\path\to\your\cert\file"
        $certFile = "$certPath\cert.p12"
        $certPass = ""
    
        # re-sign the application manifest; should be *.dll.manifest
        $manifestFile = ls | where Name -like "*.dll.manifest" | %{ return $_.Name }
        mage -Update $manifestFile -CertFile $certFile -Password $certPass
    
        # re-sign the deployment manifest; *.vsto
        $vstoFile = ls | where Name -like "*.vsto" | %{ return $_.FullName }
        #mage -Update $vstoFile -AppManifest $manifestFile -CertFile $certFile -Password $certPass
    
        $otherVstoFile = ls "..\..\" | where Name -like "*.vsto" | %{ return $_.FullName }
        mage -Update $otherVstoFile -AppManifest $manifestFile -CertFile $certFile -Password $certPass
        Copy-Item $otherVstoFile $vstoFile
    
        # put .deploy back
        $withDeploy | %{ Rename-Item -Path $_.FullName.Replace(".deploy", "") -NewName $_.FullName }
    }
    

    Ideally it would be preferable to make a change to the Visual Studio project so that I don't have to do this every time I publish, but I don't see a way to do that, and any solution is better than no solution. I might add this as a post-publish MSBuild action or something, but for now this works.

提交回复
热议问题