LoginSignup
2
1

More than 1 year has passed since last update.

MSBuild.exeで実行ファイルを作る

Last updated at Posted at 2021-06-12
  • csc.exe での実行ファイル作成に限界を感じたのでMSBuild.exeを使うこととした。

ファイル

src.PNG

main.csproj
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <ItemGroup>
    <Compile Include="*.cs" />
  </ItemGroup>

  <Target Name="Build">
      <Csc Sources="@(Compile)" References="@(Reference)" />  
  </Target>

</Project>
  • References=でdll読み込みの指定を渡すことができる。
  • ToolsVersion="4.0"を書かないと古いC#の記述方法しか使えなかった。

  • ソースファイル

main.cs
using System;

namespace ConsoleApp1 {
    class Program {
        static void Main(string[] args) {
            Console.Write("hello");
        }
    }
}
  • ビルドスクリプト
compile.bat
del main.exe

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe ^
    main.csproj

main.exe

pause

実行ファイルを作る

2.PNG

DLLの追加

main.csproj
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <ItemGroup>
    <Compile Include="*.cs" />
    <Reference Include="QRCodeEncoderDecoderLibrary.dll"/>
  </ItemGroup>

  <Target Name="Build">
      <Csc Sources="@(Compile)" References="@(Reference)" />  
  </Target>

</Project>
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1