2014年6月13日金曜日

csproj (MsBuild) のデバッグ

csprojファイルをいじるときに、他の人はどうやってデバッグしているのだろうか?

サンプルとして、TargetFrameworkVersionの先頭に"NET_"をつけて、TestPropertyに入れて、DefineConstantsに追加した。
  <None Include="App.config" />
  </ItemGroup>
  
  <PropertyGroup>
    <TestProperty>NET_$(TargetFrameworkVersion.Replace("v","").Replace(".",""))</TestProperty>
    <DefineConstants>$(DefineConstants);$(TestProperty)</DefineConstants>
  </PropertyGroup>
  
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the ta .... 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <Target Name="Build">
    <Message Text="テストプロパティ = $(TestProperty)" />
    <Message Text="ビルド定数       = $(DefineConstants)" />
  </Target>
</Project>

このように、Visual Studioのコマンドプロンプトから、MsBuildを実行すると、Messageタスクが出力される。


このNET_45というシンボルは、ちゃんとVisualStudioで使える。


今度はターゲットフレームワークをNet4.0にすると、シンボル名もNET_40になる。

当然、NET_45シンボルは無いので、#if で括った部分は無効になる。

2014.06.18追記
csprojで使えるメソッドとかの説明
http://msdn.microsoft.com/ja-jp/library/dd633440.aspx

0 件のコメント:

コメントを投稿