方法 : Windows Presentation Foundation カスタム コントロール ライブラリのサンプル プロジェクト ファイルを作成する

更新 : 2007 年 11 月

この例のプロジェクト ファイルは Windows Presentation Foundation (WPF) カスタム コントロール ライブラリ用で、ユーザー コントロールは WPFUserControl の 1 つだけです。主な構成の詳細は次のとおりです。

  • OutputType: library に設定します。

  • WPFUserControl.xaml: Page 要素として宣言される XAML ファイル。

  • WPFUserControl.xaml.cs: Compile 要素として宣言される分離コード ファイル。

このプロジェクト ファイルは、必要に応じて再利用したり変更したりできます。ただし、参照するファイルは参照元の場所になければなりません。別の方法として、Microsoft Visual Studio 2005 で カスタム コントロール ライブラリ (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>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>