共用方式為


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# 專案。若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例

[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 命名空間