首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >部署MEF部件

部署MEF部件
EN

Stack Overflow用户
提问于 2011-01-21 13:41:06
回答 1查看 584关注 0票数 0

我已经构建了一个可执行的shell,它使用MEF加载程序集(MEF部件),并相应地显示/执行加载的功能。

现在,我希望将此应用程序部署为ClickOnce安装。有没有人有这样的策略,目前我已经看到了两个策略。

  1. 为部件构建和安装程序,并将其作为再分发组件添加到shell应用程序--这意味着这两个安装基本上是焊接在一起的,这意味着MEF基本上是没有意义的。
  2. 在shell中构建一个下载程序函数,这同样意味着在我们开始之前需要了解每个MEF部件,并且使MEF毫无意义。

还有其他人知道其他方法吗?我是否可以反过来构建依赖关系,以便MEF部件的clickonce安装程序知道它应该使用什么shell?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-24 01:28:37

我所做的就是使用包装API并创建一个映射到shell UI的自定义文件扩展名。它所做的就是将包解压缩到ProgramData\MyApp\Extensions文件夹。然后,当应用程序重新启动时,这个部分就会出现。

有关更多信息,请参见此博客文章。

代码语言:javascript
复制
           ' Open the Package.
        ' ('using' statement insures that 'package' is
        '  closed and disposed when it goes out of scope.)
        Using package As Package = package.Open(fileName, FileMode.Open, FileAccess.Read)
            tFolder = IO.Path.Combine(tFolder,
                MediaToolz.SharedServices.FileSystem.GetSafeFileName(package.PackageProperties.Title))

            Dim directoryInfo As New DirectoryInfo(tFolder)
            If directoryInfo.Exists Then
                directoryInfo.Delete(True)
            End If
            directoryInfo.Create()

            For Each part In package.GetParts()
                If part.ContentType = Packages.MediaToolzAddinMimeType Then
                    ExtractPart(part, tFolder)
                End If
            Next

            package.Close()
        End Using


'  --------------------------- ExtractPart ---------------------------
''' <summary>
'''   Extracts a specified package part to a target folder.</summary>
''' <param name="packagePart">
'''   The package part to extract.</param>
''' <param name="targetDirectory">
'''   The relative path from the 'current' directory
'''   to the targer folder.</param>
Private Shared Sub ExtractPart(ByVal packagePart As PackagePart, ByVal targetDirectory As String)
    ' Create a string with the full path to the target directory.
    Dim pathToTarget As String = targetDirectory
    If pathToTarget.EndsWith(IO.Path.DirectorySeparatorChar) = False Then pathToTarget += IO.Path.DirectorySeparatorChar
    ' Remove leading slash from the Part Uri,
    '   and make a new Uri from the result
    Dim stringPart As String = packagePart.Uri.ToString().TrimStart("/"c)
    ' I added this line to take off the content pat
    stringPart = IO.Path.GetFileName(stringPart)

    Dim partUri As New Uri(stringPart, UriKind.Relative)

    ' Create a full Uri to the Part based on the Package Uri
    Dim uriFullPartPath As New Uri(New Uri(pathToTarget, UriKind.Absolute), partUri)

    ' Create the necessary Directories based on the Full Part Path
    'Directory.CreateDirectory(Path.GetDirectoryName(uriFullPartPath.LocalPath))

    ' Create the file with the Part content
    Using fileStream As New FileStream(uriFullPartPath.LocalPath, FileMode.Create)
        CopyStream(packagePart.GetStream(), fileStream)
    End Using 'Close & dispose fileStream.
End Sub

'  --------------------------- CopyStream ---------------------------
''' <summary>
'''   Copies data from a source stream to a target stream.</summary>
''' <param name="source">
'''   The source stream to copy from.</param>
''' <param name="target">
'''   The destination stream to copy to.</param>
Private Shared Sub CopyStream(ByVal source As Stream, ByVal target As Stream)
    Const bufSize As Integer = &H1000
    Dim buf(bufSize - 1) As Byte
    Dim bytesRead As Integer = 0
    bytesRead = source.Read(buf, 0, bufSize)
    Do While bytesRead > 0
        target.Write(buf, 0, bytesRead)
        bytesRead = source.Read(buf, 0, bufSize)
    Loop
End Sub
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4759443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档