Silverlight で XNA のコンテンツプロパインを使うためのプロジェクトファイルへの追加書き込み

なんか毎回忘れているのでメモ書き。

csproj ファイルをテキストファイルで開き、Project タグ以下に以下のタグを追加する。

<PropertyGroup>
   <XnaContentProject>..XXXXSampleContentProjectXXXXSampleContentProject.contentproj</XnaContentProject>
</PropertyGroup>
<Target Name="BeforeBuild">
   <MSBuild Projects="$(XnaContentProject)" Properties="XnaContentPipelineTargetPlatform=Windows;XnaContentPipelineTargetProfile=Reach" />
   <CreateItem Include="$(XnaContentProject)">
     <Output TaskParameter="Include" ItemName="XnaContentProjectItem" />
   </CreateItem>
   <CreateProperty Value="%(XnaContentProjectItem.RelativeDir)">
     <Output TaskParameter="Value" PropertyName="XnaContentProjectPath" />
   </CreateProperty>
   <CreateItem Include="$(XnaContentProjectPath)cachefile*targetpath.txt">
     <Output TaskParameter="Include" ItemName="XnaContentCacheFile" />
   </CreateItem>
   <ReadLinesFromFile File="@(XnaContentCacheFile)" Condition="Exists(@(XnaContentCacheFile))">
     <Output TaskParameter="Lines" ItemName="XnaContentOutputs" />
   </ReadLinesFromFile>
   <CreateItem Include="@(XnaContentOutputs->'$(XnaContentProjectPath)binAnyCPU$(Configuration)%(Identity)')" AdditionalMetadata="Link=Content%(RelativeDir)%(Filename)%(Extension)">
     <Output TaskParameter="Include" ItemName="Content" />
   </CreateItem> </Target>

ただし、プロジェクトをビルドしたりなんかしているといつの間にか以下のようなコメントが csproj ファイルの中に追加されていて、前に追加したタグもすべてコメントアウトされていることがある。

To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets.

実はコメントアウトされたタグの下にまったく同じタグが再度追加されているが、なぜかこのコメントアウトされたものが残っていると正しくコンテンツパイプラインが動作しない。なのでコメントをすべて削除して再ビルドする必要がある。

メモ書きなので環境によっては動作が異なる場合があるので注意してください。

]]>