共用方式為


HOW TO:針對僅適用於程式碼的 Windows Presentation Foundation 獨立應用程式建立範例專案檔

更新:2007 年 11 月

這個範例專案檔是適用於整個只以程式碼撰寫的 Windows Presentation Foundation (WPF) 獨立應用程式 (例如沒有可延伸標記語言 (XAML))。主要的組態詳細資料包括:

  • OutputType,設定為 winexe。

  • 所有 C# .cs 程式碼檔案,使用 Include 屬性設定為 *.cs 的 Compile 項目自動進行編譯。

只要您參考的檔案都位於所要參考的位置,您便能視需要重複使用或修改此專案檔。您也可以使用 Microsoft Visual Studio 2005 中的 Windows 應用程式 (WPF) 專案範本,自動產生獨立應用程式的專案檔。此外,還需要移除預設產生的程式碼和 XAML 檔案:App.xaml、App.xaml.cs、Window1.xaml 和 Window1.xaml.cs。

此專案檔適用於 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>WPFStandaloneApplicationCodeOnly</RootNamespace>

<AssemblyName>WPFStandaloneApplicationCodeOnly</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>

<Compile Include="*.cs" />

</ItemGroup>

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

<Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />

</Project>