HOW TO:建立 Windows Presentation Foundation 獨立應用程式的範例專案檔
更新:2007 年 11 月
這個範例專案檔代表一個 Windows Presentation Foundation (WPF) 獨立應用程式,其應用程式定義 (App) 已設定為自動開啟由可延伸標記語言 (XAML) 和程式碼後置 (Code-Behind) 所定義的視窗 (MainWindow)。主要的組態詳細資料包括:
OutputType。設定為 winexe。
App.xaml。設定為 ApplicationDefinition 項目的應用程式定義檔案。
MainWindow.xaml。宣告為 Page 項目的 XAML 檔案。
MainWindow.xaml.cs。宣告為 Compile 項目的程式碼後置檔案。
只要您參考的檔案都位於所要參考的位置,您便能視需要重複使用或修改此專案檔。您也可以使用 Microsoft Visual Studio 2005 中的 Windows 應用程式 (WPF) 專案範本,自動產生獨立應用程式的專案檔。
此專案檔適用於 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>WPFStandaloneApplication</RootNamespace>
<AssemblyName>WPFStandaloneApplication</AssemblyName>
<WarningLevel>4</WarningLevel>
<OutputType>winexe</OutputType>
<ApplicationVersion>1.0.0.*</ApplicationVersion>
<BootstrapperEnabled>false</BootstrapperEnabled>
</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="MainWindow.xaml" />
<Compile Include="MainWindow.xaml.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />
</Project>