VSProject2.WorkOffline 属性

指示 Web 项目是联机工作还是脱机工作。 当脱机工作时,开发继续在项目文件的一个脱机存储区上进行,以便服务器中的项目文件不被更改。

命名空间:  VSLangProj80
程序集:  VSLangProj80(在 VSLangProj80.dll 中)

语法

声明
Property WorkOffline As Boolean
bool WorkOffline { get; set; }
property bool WorkOffline {
    bool get ();
    void set (bool value);
}
abstract WorkOffline : bool with get, set
function get WorkOffline () : boolean
function set WorkOffline (value : boolean)

属性值

类型:System.Boolean
一个布尔值。对于 Web 应用程序,在脱机工作时该属性返回 true,在联机工作时返回 false。对于本地项目,此属性返回 false。

备注

当项目处于脱机状态时,将不尝试对服务器中的项目文件进行写入或访问操作。

若要更改脱机项目文件的 URL,请使用 Project.Properties 集合的 OfflineURL 属性。

只能为 Web 项目更改该属性。 虽然这是一个读写属性,但如果您尝试为某个本地项目设置该属性,就会生成错误。

示例

此示例假定解决方案中的第一个项目为 Visual Basic 或 Visual C# 项目。 若要将此示例作为外接程序运行,请参见如何:编译和运行自动化对象模型代码示例

[Visual Basic]

' Add-in code.
Imports VSLangProj
Imports VSLangProj80
Public Sub OnConnection(ByVal application As Object,_
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    applicationObject = CType(application, DTE2)
    addInInstance = CType(addInInst, AddIn)
    WorkOfflineExample(applicationObject)
End Sub

Sub WorkOfflineExample(ByVal dte As DTE2)
    ' This example assumes that the first project in the solution is 
    ' a Visual Basic or C# project.
    Dim aVSProject As VSProject2 = _
    CType(applicationObject.Solution.Projects.Item(1).Object,_
    VSProject2)
    MsgBox("Work offline is: " & aVSProject.WorkOffline.ToString())
    Try
        MsgBox("Setting WorkOffline to false.")
        aVSProject.WorkOffline = False
    Catch e As System.Exception
        ' Setting the property fails for local projects.
        MsgBox(e.Message)
    End Try
    Try
        MsgBox("Setting WorkOffline to true.")
        aVSProject.WorkOffline = True
    Catch e As System.Exception
        ' Setting the property fails for local projects.
        MsgBox(e.Message)
    End Try
End Sub

[C#]

using System.Windows.Forms;
using VSLangProj;
using VSLangProj2;
using VSLangProj80;
public void OnConnection(object application, ext_ConnectMode
 connectMode, object addInInst, ref Array custom)
{ 
    applicationObject = (DTE2)application;
    addInInstance = (AddIn)addInInst;
    WorkOfflineExample((DTE2)applicationObject);
}

public void WorkOfflineExample( DTE2 dte ) 
{ 
// This example assumes that the first project in the solution is 
// a Visual Basic or C# project.
    VSProject2 aVSProject = ( ( VSProject2 )
(applicationObject.Solution.Projects.Item( 1 ).Object ) ); 
    MessageBox.Show( "Work offline is: " + 
aVSProject.WorkOffline.ToString()); 
    try 
    { 
        MessageBox.Show( "Setting WorkOffline to false."); 
        aVSProject.WorkOffline = false; 
    } 
    catch ( System.Exception e ) 
    { 
        // Setting the property fails for local projects.
        MessageBox.Show( e.Message); 
    } 
    try 
    { 
        MessageBox.Show( "Setting WorkOffline to true."); 
        aVSProject.WorkOffline = true; 
    } 
    catch ( System.Exception e ) 
    { 
        // Setting the property fails for local projects.
        MessageBox.Show( e.Message); 
    } 
}

.NET Framework 安全性

请参见

参考

VSProject2 接口

WorkOffline 重载

VSLangProj80 命名空间