如何:为 Windows Presentation Foundation 自定义控件库创建示例项目文件

更新:2007 年 11 月

本示例项目文件适用于具有一个用户控件 WPFUserControl 的 Windows Presentation Foundation (WPF) 自定义控件库。主要配置详细信息包括:

  • OutputType. 设置为 library。

  • WPFUserControl.xaml。声明为 Page 元素的 XAML 文件。

  • WPFUserControl.xaml.cs。声明为 Compile 元素的代码隐藏文件。

您可以根据自己的需要重用或修改此项目文件,但前提是所引用的文件位于您正在从中引用文件的位置。也可以通过使用 Microsoft Visual Studio 2005 中的 自定义控件库 (WPF) 项目模板为自定义控件自动生成项目文件。

此项目文件适用于 C# 项目,因此包括 Microsoft.CSharp.targets Import 元素。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>WPFCustomControlLibrary</RootNamespace>

<AssemblyName>WPFCustomControlLibrary</AssemblyName>

<WarningLevel>4</WarningLevel>

<OutputType>library</OutputType>

<ApplicationVersion>1.0.0.*</ApplicationVersion>

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

<Page Include="WPFUserControl.xaml" />

<Compile Include="WPFUserControl.xaml.cs" />

</ItemGroup>

<ItemGroup>

<Compile Include="Properties\AssemblyInfo.cs" />

<AppDesigner Include="Properties\" />

</ItemGroup>

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

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

</Project>