Using batch and MSBuild command compile the project

The first step: create a directory listing as shown in Figure

bin: After compiling all final project DLL output directory

build: storage bat batch file generation project

src: source file storage project

Part II: src directory to create a separate class library project and main project

 

 

 

 

 The purpose of creating multiple solutions is split using subtraction and modular ideas for large projects.

Example: WPF main project MainApp, class library project MainApp.Common. MainApp reference MainApp.Common

After the project is to create a good project respectively Right Properties -> Build Options page output will be compiled dll directory under the unified output to the bin directory, set according to the specific needs of the actual situation of their own project .. \ requires several levels.

 

 

The third step: to create a separate batch file and build a batch file reference

 

 all.proj contents of the file:

<?xml version="1.0" encoding="utf-8"?>
<Project  xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Root>$(MSBuildStartupDirectory)</Root>
  </PropertyGroup>

  <Target Name="Build">

    <!-- Compile -->
    <ItemGroup>
    
      <ProjectToBuild Include="$(Root)\..\src\Foundation\Common\MainApp.Common\MainApp.Common.sln" />
      
      <ProjectToBuild Include="$(Root)\..\src\MainApp\MainApp.sln" />
      
    </ItemGroup>
    <MSBuild Projects="@(ProjectToBuild)" Targets="Build" Properties="Configuration=Debug;">
      <Output TaskParameter="TargetOutputs" ItemName="AssembliesBuiltByChildProjects" />
    </MSBuild>
    
  </Target>
</Project>

红框所示,分别引用了两个解决方案,注意引用顺序

   

 

 all.bat 文件:

@ECHO OFF

SET framework=v4.0.30319

"c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" all.proj /t:Build /p:Configuration=Debug /v:m

ECHO.
ECHO   生成完成!
pause

 

 箭头所指方向是生成器所在目录地址,每个机器环境不一样,确认你本机已经安装了那个版本的MSBuild.exe程序,具体的可以使用dir查看,如:C:\>dir /s /b /d  MSBuild.exe 可以查看本机各个版本。下面箭头所指方向是我本机vs2019环境的

 

 如果你是.net framework 4.0的程序,默认下面这种更合理,不用来回改,系统会动态读取环境变量值。

@ECHO OFF

SET framework=v4.0.30319

"%SystemDrive%\Windows\Microsoft.NET\Framework\%framework%\MSBuild.exe" all.proj /t:Build /p:Configuration=Debug /v:m

ECHO.
ECHO   生成完成!
pause

 执行批处理文件结果如下:

 

 到bin目录下查看是否编译成功:

 

 

 

Guess you like

Origin www.cnblogs.com/wgx0428/p/12297544.html