我过去为 Word 做过这个,我怀疑它也适用于 PowerPoint。但这可能有点冒险,但这是 VB.Net 真正大放异彩的一个领域 :)
本质上,您使用调试版本进行开发并使用发布版本进行部署,并且对象使用不同的绑定类型。条件编译控制两种绑定方式的切换。
警告:我没有尝试过这个,但它应该非常接近你所追求的。
' Code for where you declare you your objects...
#If DEBUG Then
' Create the object for the dev environment using early binding
Protected PowerpointApp As PowerPoint.Application = Nothing
Protected PowerpointDoc As PowerPoint.Document = Nothing
#Else
' Create the object for the compiled application using late binding
Protected PowerpointApp As Object = Nothing
Protected PowerpointDoc As Object = Nothing
#End If
' Code for where you create your objects...
#If DEBUG Then
' Declare the object for the dev environment using early binding
PowerpointApp = New PowerPoint.Application
#Else
' Declare the object for the compiled application using late binding
PowerpointApp = CreateObject("POWERPOINT.APPLICATION")
#End If
' Use whichever method you want to open the document
PowerpointDoc = PowerpointApp.Documents.Open(etc, etc, etc, ...)