共用方式為


HOW TO:建立 Windows Presentation Foundation XAML 瀏覽器應用程式的範例專案檔

更新:2007 年 11 月

這個範例專案檔代表一個 XAML 瀏覽器應用程式 (XBAP),其應用程式定義檔 (App) 已設定為自動開啟由 XAML 和程式碼後置所定義的首頁 (HomePage)。主要的組態詳細資料包括:

  • OutputType。設定為 winexe。

  • HostInBrowser。因為 XAML 瀏覽器應用程式 (XBAP) 必須是瀏覽器裝載的,所以這必須設定為 true。

  • Install。因為未安裝 XAML 瀏覽器應用程式 (XBAP),所以這必須設定為 false。

  • TargetZone。因為 XAML 瀏覽器應用程式 (XBAP) 是在網際網路安全性區域中執行,所以這必須設定為 "Internet"。

  • StartAction。這必須設定為 "Program"。

  • StartProgram。這必須設定為程式,該程式處理在瀏覽器中裝載應用程式的處理程序。

  • StartArguments。這必須設定為應用程式資訊清單 (副檔名為 .xbap) 的路徑。

  • App.xaml。設定做為 ApplicationDefinition 項目的應用程式定義檔案。

  • HomePage.xaml。以 Page 項目宣告的 XAML 檔案。

  • HomePage.xaml.cs。以 Compile 項目宣告的程式碼後置檔案。

  • XBAPApplication_TemporaryKey.pfx。使用 ClickOnce 部署的應用程式 (包括 XBAP) 所需的暫存資訊清單金鑰檔。

只要您參考的檔案都位於所要參考的位置,您便能視需要重複使用或修改這個專案檔。另一種方式是,在 Microsoft Visual Studio 2005 中使用 XAML 瀏覽器應用程式 (WPF) 專案範本自動產生 XBAP 的專案檔。

這個專案檔適用於 C# 專案,因此包含 Microsoft.CSharp.targetsImport 項目。Microsoft Visual Studio 2005 會讓 C# 專案檔具有 .csproj 副檔名。在 Microsoft Visual Studio 2005 中建立的 Microsoft Visual Basic .NET 通常具有 .vbproj 副檔名,並且會包含 Microsoft.VisualBasic.targetsImport 項目。

範例

<Project DefaultTargets="Build" xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <RootNamespace>XBAPApplication</RootNamespace>
    <AssemblyName>XBAPApplication</AssemblyName>
    <WarningLevel>4</WarningLevel>
    <OutputType>winexe</OutputType>
    <EnableSecurityDebugging>false</EnableSecurityDebugging>
    <ApplicationVersion>1.0.0.*</ApplicationVersion>
    <MapFileExtensions>False</MapFileExtensions>
    <HostInBrowser>True</HostInBrowser>
    <Install>False</Install>
    <TargetZone>Internet</TargetZone>
    <StartAction>Program</StartAction>
    <StartProgram>$(WINDIR)\System32\PresentationHost.exe</StartProgram>
    <ApplicationExtension>.xbap</ApplicationExtension>
    <StartArguments>-debug "$(MSBuildProjectDirectory)\bin\$(Configuration)\$(AssemblyName)$(ApplicationExtension)"</StartArguments>
    <SignManifests>True</SignManifests>
    <BootstrapperEnabled>false</BootstrapperEnabled>
    <ManifestKeyFile>XBAPApplication_TemporaryKey.pfx</ManifestKeyFile>
    <ManifestCertificateThumbprint>F2E49D0E8A6FE749DE85D224F5557B875DFD5577</ManifestCertificateThumbprint>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>.\bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugSymbols>false</DebugSymbols>
    <Optimize>true</Optimize>
    <OutputPath>.\bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="WindowsBase" />
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
  </ItemGroup>
  <ItemGroup>
    <ApplicationDefinition Include="App.xaml" />
    <Page Include="HomePage.xaml" />
    <Compile Include="HomePage.xaml.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="XBAPApplication_TemporaryKey.pfx" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />
</Project>