MSBuild



.SUFFIXES: .cpp .vcproj .obj .exe
.PHONY: all test mmm clean
TARGET=TaskSchedulerExplorer

all: $(TARGET).exe

$(TARGET).exe: $(TARGET).vcproj
    msbuild.exe $<

test:
    ./$(TARGET).exe

clean:
    msbuild.exe /t:Clean
~




myproj

<?xml version="1.0" encoding="utf-8" ?>
<Project
      xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
      <Target Name="Build">
    ……タスクの記述……
  </Target>   <ItemGroup>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>

  <PropertyGroup>
    <AssemblyName>ConsoleApplication1</AssemblyName>
    <RootNamespace>ConsoleApplication1</RootNamespace>
    <OutputType>Exe</OutputType>
    <Configuration>Debug</Configuration>
    <Platform>AnyCPU</Platform>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <OutputPath>bin\Debug\</OutputPath>
  </PropertyGroup>
<PropertyGroup>

    <Configuration

      Condition
=" '$(Configuration)' == '' ">Debug</Configuration>

    <AssemblyName>ConsoleApplication1</AssemblyName>
    <RootNamespace>ConsoleApplication1</RootNamespace>
    <OutputType>Exe</OutputType>
    <Platform>AnyCPU</Platform>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
  </PropertyGroup>
  <PropertyGroup
    Condition=" '$(Configuration)' == 'Debug' ">
    <OutputPath>bin\Debug\</OutputPath>
  </PropertyGroup>
  <PropertyGroup
    Condition=" '$(Configuration)' == 'Release' ">
    <OutputPath>bin\Release\</OutputPath>
  </PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>


reference





  1. おまじない
    <Project  
        xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    </Project>
    
  2. Target を定義する
    
    <Project  
        xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <Target Name="brabra">
            :
        </Target>
    </Project>
    
  3. 規定のC#ターゲットのインポートで済ませる場合
    
    <Project  
        xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
    </Project>
    
  4. デフォルト・ターゲットの指定
    
    <Project
      DefaultTargets="Build"
        xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
    </Project>
    
  5. モジュールを使うターゲットの例
    
    <Project DefaultTargets="ModuleCompilation" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    
      <PropertyGroup>
        <Configuration>Debug</Configuration>
        <Platform>AnyCPU</Platform>
        <OutputPath>bin\</OutputPath>
      </PropertyGroup>
    
      <Target Name="ModuleCompilation">
        <MakeDir Directories= "$(OutputPath)"/>
        <Csc Sources="MyModule.cs" TargetType="Module"
             OutputAssembly="$(OutputPath)\MyModule.netmodule" />
        <Csc Sources="ConsoleApplication1.cs" TargetType="Exe"
             AddModules="$(OutputPath)\MyModule.netmodule" 
             OutputAssembly="$(OutputPath)\ConsoleApplication1.exe" />
      </Target>
    
  6. ソースの指定
    
    <Project
      DefaultTargets="Build"
      xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    
      <ItemGroup>
        <Compile Include="Program.cs" />
        <Compile Include="Properties\AssemblyInfo.cs" />
      </ItemGroup>
    
      <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
    </Project> 
    
  7. リファレンスの指定
    
    <Project
      DefaultTargets="Build"
      xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ItemGroup>
        <Reference Include="System" />
        <Reference Include="System.Data" />
        <Reference Include="System.Xml" />
      </ItemGroup>
      
    </Project> 
    
  8. プロパティの設定
    
    <Project
      DefaultTargets="Build"
      xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    
      <PropertyGroup>
        <!-- アセンブリ名 -->
        <AssemblyName>ConsoleApplication1</AssemblyName>
        <!-- 既定の名前空間 -->
        <RootNamespace>ConsoleApplication1</RootNamespace>
        <!-- 出力の種類 -->
        <OutputType>Exe</OutputType>
        <!-- 構成 -->
        <Configuration>Debug</Configuration>
        <!-- プラットフォーム -->
        <Platform>AnyCPU</Platform>
        <!-- 条件付きコンパイル・シンボル -->
        <DefineConstants>DEBUG;TRACE</DefineConstants>
        <!-- 出力パス -->
        <OutputPath>bin\Debug\</OutputPath>
      </PropertyGroup>
    
    </Project> 
    

 

MSBuildのプロパティ
MSBuildフォルダ内Microsoft.Build.Commontypes.xsdファイルのコメントPROPERTIESを見る

予約済みプロパティ 説明
MSBuildProjectDirectory プロジェクトファイルの絶対パス C:\MyFolder
MSBuildProjectFile プロジェクトファイル名 My.proj
MSBuildProjectExtension プロジェクトファイルの拡張子 .proj
MSBuildProjectFullPath プロジェクトファイルの絶対パスとファイル名 C:\MyFolder\My.proj
MSBuildProjectName プロジェクトファイル名(拡張子なし) My
MSBuildBinPath 「MSBuild.exe」の絶対パス C:\WINDOWS\Microsoft.NET\ Framework\v2.0.50727
MSBuildProjectDefaultTargets DefaultTargets属性で指定されたターゲット <ProjectDefaultTargets="A;B">の場合、「A;B」
MSBuildExtensionsPath 「Program Files」下の「MSBuild」フォルダ <ImportProject= "$(MSBuildExtensionsPath) \MyFiles\OtherCustom.targets"/>



<Target Name="build" >
    <CSC
        Sources="@(CSFile)"
        References="@(Reference)"
        OutputAssembly="$(ProjectName).exe"
        TargetType="winexe" />

</Target>
<Target Name="run" DependsOnTargets="build">
    <Exec Command="$(ProjectName).exe"/>
    <Message Text="アプリケーションを実行しました。" />
</Target>





Include File パス追加

    <Tool
                                Name="VCCLCompilerTool"
                                Optimization="0"
                                AdditionalIncludeDirectories=";"
                                PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
                                MinimalRebuild="TRUE"
                                BasicRuntimeChecks="0"
                                RuntimeLibrary="1"
                                RuntimeTypeInfo="FALSE"
                                WarningLevel="3"
                                DebugInformationFormat="4"/>