加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

签署F#装配(强名称组件)

发布时间:2020-12-16 01:31:19 所属栏目:安全 来源:网络整理
导读:我在CodeProject上发现了这篇文章: http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus 并且认为尝试一下是很好的,但是在F#中.所以我想出了以下代码: open Systemopen System.IOopen System.Textopen System.Runtime.I
我在CodeProject上发现了这篇文章:
http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus

并且认为尝试一下是很好的,但是在F#中.所以我想出了以下代码:

open System
open System.IO
open System.Text
open System.Runtime.InteropServices
open System.Windows.Forms
open SharpShell
open SharpShell.Attributes
open SharpShell.SharpContextMenu

[<ComVisible(true)>]
[<COMServerAssociation(AssociationType.ClassOfExtension,".txt")>]
type CountLinesExtension() =
    inherit SharpContextMenu.SharpContextMenu()

    let countLines =
        let builder = new StringBuilder()
        do 
            base.SelectedItemPaths |> Seq.iter (fun x -> builder.AppendLine(sprintf "%s - %d Lines" (Path.GetFileName(x)) (File.ReadAllLines(x).Length)) |> ignore  )
            MessageBox.Show(builder.ToString()) |> ignore

    let createMenu =
        let menu = new ContextMenuStrip()
        let itemCountLines = new ToolStripMenuItem(Text = "Count Lines")
        do
            itemCountLines.Click.Add (fun _ -> countLines)
            menu.Items.Add(itemCountLines) |> ignore
        menu

    override this.CanShowMenu() = true
    override this.CreateMenu() = createMenu

但是,我注意到在VS2012中不支持签名F#程序集(文章中的第4步).我了解到,如果我想这样做,我需要手动创建一个键(在命令提示符下键入“sn -k keyName.snk”),然后在“项目属性 – >构建 – >其他标志“(–keyfile:keyName.snk).

我还没有成功运行这个.此外,使用作者的应用程序(在“调试Shell扩展”部分)我收到一个错误,我的程序集不包含COM服务器.

我相信我在签署组件时发生错误.你能帮助我运行这个吗?

通过AssemblyFileKeyAttribute属性来签署F#程序集的一种方式.

创建一个新的模块,并在其中:

module AssemblyProperties

open System
open System.Reflection;
open System.Runtime.InteropServices;

[<assembly:AssemblyKeyFileAttribute("MyKey.snk")>]

do()

其中“MyKey.snk”是相对于项目目录的键的路径.

另一种方法,在Microsoft Connect的这个错误报告中发现,是将–keyfile:MyKey.snk添加到“属性”中的“其他标志”字段中.构建选项卡.

使用任一方法;运行sn -v myfsharpassembly.dll将声明程序集在编译后有效.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读