1.编译工具版本VS2015
使用VS 2015,装完VS 2015 是不包含MSBuild 需要下载安装 mu_microsoft_build_tools_2015_x86_x64_6846132.exe(Microsoft Build Tools 2015)
2.项目结构
这里要注意,其他项目里引用Common项目的,是通过dll文件夹里的Common.dll,这是导致并行编译的原因
3.编译脚本
compile.bat
set msbuild_program_dir=C:\Program Files (x86)\MSBuild\14.0\Bin\
set compile_model=Release
set sln_file_dir=.\Test.sln
set message="Compiling WPF"
Echo %message%
"%msbuild_program_dir%\MSbuild.exe" /maxcpucount /p:Configuration=%compile_model% %sln_file_dir%'
set message="completed."
Echo %message%
注意上面的 /maxcpucount,这个并行编译,同时编译多个项目的设置参数
4.导致出现的警告
_CopyAppConfigFile:
[exec] 正在将文件从“app.config”复制到“dll文件夹\Common.dll.config”。
[exec] CopyFilesToOutputDirectory:
[exec] 正在将文件从“obj\Release\Common.dll”复制到“dll文件夹\Common.dll”。
[exec] 2>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(3813,5): warning MSB3026: 未能将“obj\Release\Common.dll”复制到“dll文件夹\Common.dll”。1000 毫秒后将开始第 1 次重试。文件“dll文件夹\Common.dll”正由另一进程使用,因此该进程无法访问此文件。 [D:\Test\Common\Common.csproj]
5./maxcpucount 参数解释
指定生成时要使用的最大并发进程数。 如果不包含此开关,则默认值为 1。 如果包含此开关而没有指定值,MSBuild 将使用计算机中的处理器总数作为其值
如:
MSbuild.exe test.csproj /maxcpucount:3 表示使用三个 MSBuild 进程进行生成,这允许同时生成三个项目,编译时,会在任务管理器里出现在运行的 MSBuild.exe
MSbuild.exe test.csproj /maxcpucount 表示将使用计算机中的处理器总数作为其值
6.解决方案
1>引用Common.dll 的项目改成 引用Common项目,即 dll引用改成对应的 项目引用
2>去掉 /maxcpucount 编译参数或者 设置/maxcpucount:1