HOW TO:編輯發行設定檔 (.pubxml) 檔案中的部署設定以及 Visual Studio Web 專案中的 .wpp.targets 檔案

本主題說明如何設定部署設定透過編輯發行設定檔 (.pubxml) 檔或建立 Visual Studio Web 專案的 .wpp.targets 檔案。 這個主題適用於下列產品:

因為某些部署設定工作在 Visual Studio UI,無法完成編譯發行設定檔或建立 .wpp.targets 檔案可能是必要的。 某些部署選項可以透過編輯控制 Web 發行管線 (WPP) 的其中一個只指定 XML 檔案。

本主題包含下列章節:

  • 編譯發行設定檔 (.pubxml) 檔案。

    當您要設定為特定發行設定檔的設定時,編輯發行設定檔。 發行設定檔會命名為 <profilename>.pubxml 和位於專案資料夾下的屬性\PublishProfiles 資料夾。 每個檔案包含適用於已發行設定檔的設定。 您可以在 [發行 Web] 精靈中輸入的值在這些檔案中。

  • 建立 .wpp.targets 檔案

    當您在專案中要設定會套用至所有設定檔時使用的設定,您可以建立 .wpp.targets 檔案。 .wpp.targets 檔案必須位於專案資料夾,而且必須命名 <projectname>.wpp.targets。

注意事項注意事項

如果您使用 [封裝/發行 SQL] 選項設定資料庫部署,您可能需要編輯資料庫在專案檔中的部署設定。如需如何編輯與 [封裝/發行 SQL] 索引標籤相關之設定的詳細資訊,請參閱本主題的 .NET Framework 4 版。

編譯發行設定檔 (.pubxml) 檔案。

當您建立發行設定檔時,兩個檔案中 PublishProfiles 資料夾建立: <profilename>.pubxml 和 <profilename>.pubxml.user。 .pubxml.user 檔案包含適用於特定使用者的少數設定,例如已加密的密碼。 預設會在原始檔控制不包含。 通常,當您變更設定與設定檔有關時您編輯 .pubxml 檔案而不 .pubxml.user 檔案。

編譯發行設定檔 (.pubxml) 檔案。

  1. 在 [方案總管],按兩下檔案開啟它。

  2. 如果您要變更的項目已經在 PropertyGroup 項目,變更其值,否則請將項目加入至 PropertyGroup 項目。

    例如,假設您想要停用 Visual Studio 部署 setACL 預設行為。 根據預設, Visual Studio 將在目的網站的根資料夾在 App_Data 資料夾使用權限讀取和寫入使用權限。 如果您知道在資料夾的預設使用權限是正確的,而且不需要設定,您可以將下列 XML 停用特定發行設定檔的行為加入至發行設定檔:

    <IncludeSetACLProviderOnDestination>False</IncludeSetACLProviderOnDestination>
    

    當您開啟發行設定檔時,它會類似下列範例:

    <Project ToolsVersion="4.0" xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <WebPublishMethod>Package</WebPublishMethod>
        <LaunchASiteUrlAfterPublish>False</LaunchASiteUrlAfterPublish>
        <SiteUrlToLaunchAfterPublish />
        <MSDeployServiceURL />
        <DeployIisAppPath />
        <RemoteSitePhysicalPath />
        <AllowUntrustedCertificate>False</AllowUntrustedCertificate>
        <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
        <DeployAsIisApp>True</DeployAsIisApp>
        <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
        <UserName />
        <SavePWD>True</SavePWD>
        <PublishDatabaseSettings>
          <!— this section omitted to keep the example short -->
        </PublishDatabaseSettings>
      </PropertyGroup>
    </Project>
    

    如範例所示,若要停用預設 setACL 行為,請將 IncludeSetACLProviderOnDestination 項目,在中,於開頭標記後 PropertyGroup 出現:

    <Project ToolsVersion="4.0" xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <IncludeSetACLProviderOnDestination>False</IncludeSetACLProviderOnDestination>
        <WebPublishMethod>Package</WebPublishMethod>
        <LaunchASiteUrlAfterPublish>False</LaunchASiteUrlAfterPublish>
        <SiteUrlToLaunchAfterPublish />
        <MSDeployServiceURL />
        <DeployIisAppPath />
        <RemoteSitePhysicalPath />
        <AllowUntrustedCertificate>False</AllowUntrustedCertificate>
        <SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
        <DeployAsIisApp>True</DeployAsIisApp>
        <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
        <UserName />
        <SavePWD>True</SavePWD>
        <PublishDatabaseSettings>
          <!— this section omitted to keep the example short -->
        </PublishDatabaseSettings>
      </PropertyGroup>
    </Project>
    
  3. 儲存檔案。

避免編輯 .pubxml 檔案的資料庫相關的設定,,因為 Visual Studio 會自動變更這些設定,則會出現在專案中的變更。 資料庫相關的設定包括:

  • PublishDatabaseSettings 項目。 (這個項目可能會出現在 PropertyGroup 項目)。

  • 在 PropertyGroup 項目之後出現的任何 ItemGroup 項目。

建立 .wpp.targets 檔案

您可以在 .wpp.targets 檔案中設定的設定會套用至所有發行設定檔。 下列程序說明如何建立 .wpp.targets 檔案。

建立 .wpp.targets 檔案

  1. 在專案中建立資料夾 (保留 .csproj 或 .vbproj 檔案) 的相同資料夾中建立新的 XML 檔案並將它命名為 <projectname>.wpp.targets。

  2. 建立 Project 項目做為最上層項目並在其中建立 PropertyGroup 項目。

  3. 將您要用於所有發行設定檔中指定的設定。 例如,在中,如果您想要停用預設 setACL 行為,如下列範例所示,加入項目, IncludeSetACLProviderOnDestination :

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <IncludeSetACLProviderOnDestination>False</IncludeSetACLProviderOnDestination>
      </PropertyGroup>
    </Project>
    
  4. 儲存並關閉檔案。

  5. 關閉 Visual Studio 並重新開啟。

    由於 Visual Studio 快取 .targets 檔案,所做的變更加入至其中一個可能不是有效的,直到,下次開啟 Visual Studio。

您也可以使用 .wpp.targets 檔案擴充 Web 發行管線是更複雜的模式。 例如,除了 App_Data 以外,您可能想要保留預設的 setACL 行為,但自動化寫入權限設定為在另一個資料夾中。 如需說明如何進行,請參閱 若要設定 Web 資料夾使用權限的問題 。Sayed Hashimi 的部落格。

請參閱

概念

Visual Studio 及 ASP.NET 的 Web 部署內容對應